Skip to content

Commit

Permalink
Add rocket launch capability
Browse files Browse the repository at this point in the history
  • Loading branch information
Bowserinator committed Aug 23, 2018
1 parent 0420197 commit c62a129
Show file tree
Hide file tree
Showing 15 changed files with 225 additions and 39 deletions.
55 changes: 55 additions & 0 deletions TODO.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ Create a simulation (calculations only)
https://stackoverflow.com/questions/29429219/how-put-a-texture-on-pixi-js-polygon


//TODO ERROR
decomp.Polygon is not a constructor ERROR!!

Fix weird sliding bug on the ice - rocket slides left


Speed up sector rendering by computing once for both graphics and planet

Expand Down Expand Up @@ -91,3 +96,53 @@ science instruments
orbital decay
fake lagrange points
re-entry heat

Future update ideas
Magnetics update
Mag sail
magnetospheres
magnetic field detector
aurouras
solar sails
railguns
antimatter
container
collector (antimatter contained in magnetic fields of planets)
engine (antimatter triggered fission reactor)

Nuclear update
Nuclear engines / reactors
Radiation shielding (since craft come with it built in only really applicable for reactors)
Solar radiation/radiation belts
Fusion/fission thrusters
Fusion thruster
Nuclear lightbulb
Nuclear bomb solar sail
Nuclear bombs :D
Radiation beam lasers
Traveling wave reactor
Cosmic ray sensor

Science update
Soil scoop (robotic)
Weather stations
Lots of more telescoeps on different wavelengths
cameras
sesmic reader
labatories

Interstellar exploration update (big update)
resources
Water drill
Atmospheric scoop
habitats: greenhouses, waste recycling, co2 scrubbers
supercapciator - large battery

engines
methane engines (mine methane is easier)
water engines
ion engines, fusion engines, antimatter engines
ship
bigger radiators
planets
lots of new star systems to explore
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<link rel="stylesheet" href="css/index.css">

<!-- Libaries -->
<script src="js/pixi.js"></script>
<script src="js/decomp.js"></script>
<script src="js/pixi.js"></script>
<script src="js/matter.js.min"></script>

<!-- Init script -->
Expand Down
1 change: 1 addition & 0 deletions src/controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ window.addEventListener('wheel', function(e) {
stage.onScroll(e);
});

/* Click events */
window.addEventListener('click', function(e) {
let stage = stage_handler.stages[stage_handler.current_stage];
stage.onClick(e);
Expand Down
13 changes: 12 additions & 1 deletion src/editor/editor-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ global.editorFunctions.changeEditorBuild = function(id) {
scenes.editor.current_select_build = id;
}

global.editorFunctions.spawnCurrentRocketAtLaunchPad = function() {
let rocket = stage_handler.getCurrentStage().constructRocket();

rocket.control = true;
scenes.sim.addRocket(rocket);

console.log(rocket)

stage_handler.switchStage('sim');
}

/* Load the actual html */
module.exports = `
<div style="
Expand Down Expand Up @@ -45,6 +56,6 @@ module.exports = `
right: 0;
text-align: right;
">
<button>LAUNCH</button>
<button onclick="editorFunctions.spawnCurrentRocketAtLaunchPad()">LAUNCH</button>
</div>
`;
14 changes: 14 additions & 0 deletions src/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,20 @@ class Editor extends RenderableScene {

this.current_build.push({ x: x, y: y, name: this.current_select_build, data: part_data });
}

/**
* constructRocket - Construct a new Rocket object
* that can be added to the sim
*
* @return {Rocket} Rocket built in the editor
*/
constructRocket() {
let parts = this.current_build.map(part => new allParts.index[part.name](part.x, part.y));
let rocket = new Rocket(parts, Matter);

rocket.reposition(90, -100); // TODO update to launch pad coords
return rocket;
}
}

module.exports = Editor;
39 changes: 22 additions & 17 deletions src/game-components/physical-scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ class PhysicalScene {
}

/**
* load - Loads a PhysicalScene into existence.
* Also renders the PhysicalScene, and enables physics.
*
* load - Loads a PhysicalScene into existence.
* Also renders the PhysicalScene, and enables physics.
*
* @param {PIXI.Container} stage Stage to draw everything on
* @param {Matter.World} world World to add physical objects to
* @param {Matter.Engine.Create()} engine Matter.js engine
Expand All @@ -33,28 +33,33 @@ class PhysicalScene {
load(stage, world, engine) {
//init.resetAll(); // Clear the game renderer and physics engine

let bodies = []; // Physical bodies to add to engine

// Add physical sprites
for(let physical_sprite of this.physical_sprites) {
stage.addChild(physical_sprite.sprite);
if (!physical_sprite.skip_add_body) {
bodies.push(physical_sprite.body);
}
}
this.addPhysicalSprites(stage, this.physical_sprites);

// Add non-physical sprites
for(let sprite of this.sprites) {
stage.addChild(sprite.sprite);
}

// Add matterjs bodies
for(let body of this.bodies) {
bodies.push(body);
}

// Add all physical objects
world.add(engine.world, bodies);
world.add(engine.world, this.bodies);
}

/**
* addPhysicalSprites - Adds more physical sprites
* to the current scene.
*
* @param {PIXI.Container} stage Stage to draw everything on
* @param {array} physical_sprites Array of physical sprites
*/
addPhysicalSprites(stage, sprites) {
for (let physical_sprite of sprites) {
stage.addChild(physical_sprite.sprite);
if (!physical_sprite.skip_add_body) {
this.bodies.push(physical_sprite.body);
}
}
this.physical_sprites = this.physical_sprites.concat(sprites);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/game-components/planet-sector.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ class PlanetSector {
Matter.Body.setStatic(this.body, true);

// Debugging
/* let graphics = new PIXI.Graphics();
/*let graphics = new PIXI.Graphics();
for (let i=1;i<vert.length;i++) {
graphics.lineStyle(20, 0xffffff)
.moveTo(vert[i-1].x, vert[i-1].y)
.lineTo(vert[i].x, vert[i].y);
}
sim.stage.addChild(graphics); */
stage_handler.getStageByName('sim').stage.addChild(graphics);*/
}
}

Expand Down
1 change: 1 addition & 0 deletions src/game-components/rocket-part.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class RocketPart extends PhysicalSprite {
let body = Matter.Bodies.rectangle(x, y, width, height);
super(image_path, width, height, body);

this.sprite.anchor.set(0, 0);
this.image_path = image_path;
this.skip_add_body = true;

Expand Down
23 changes: 19 additions & 4 deletions src/game/rocket-parts/base-classes/thruster.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const RocketPart = require('../../../game-components/rocket-part.js');

/**
* A FuelTank
* A Thruster
*/
class Thruster extends RocketPart {
/**
Expand All @@ -23,7 +23,7 @@ class Thruster extends RocketPart {
/* Blocks are the same size as the image they're from
* and are static. Non-static blocks should be an entitySprite */
super(image_path, width, height, x, y, data, id);
this.thurst = thrust;
this.thrust = thrust;
this.burn_rate = burn_rate;

// This class should not be constructed directly
Expand All @@ -37,9 +37,24 @@ class Thruster extends RocketPart {
* Update method. this.rocket is set
* in the Rocket class
*/
update() {
update(multiplier=1) {
super.update();
this.rocket.applyForceToAll({x: 0, y: -0.005});

/**
* Angle of 0 = rocket is facing upwards. Thrust components
* is determiend by the following forumla:
*
* x = -sin(angle) * thrust
* y = -cos(angle) * thrust
*/
let angle = this.rocket.body.angle;
Matter.Body.applyForce(
this.rocket.body,
this.body.position,
{
x: this.thrust * multiplier * Math.sin(angle),
y: -this.thrust * multiplier * Math.cos(angle)
});
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/game/rocket-parts/thruster/thruster-normal.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ThrusterNormal extends Thruster {
config.build_grid_size,
config.build_grid_size,
x, y, DATA, 'Liquid Fuel Engine',
4000);
0.01, 0.1);
}
}

Expand Down
Loading

0 comments on commit c62a129

Please sign in to comment.