Add collectable fuel cans

This commit is contained in:
asraelite 2018-03-07 02:19:06 +00:00
parent 4f8fd6e1af
commit b27bd7bba2
9 changed files with 141 additions and 27 deletions

82
dist/img/modules/fuelcan.svg vendored Normal file
View file

@ -0,0 +1,82 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="22.166674mm"
height="22.16667mm"
viewBox="0 0 22.166674 22.16667"
version="1.1"
id="svg8"
inkscape:version="0.92.2 5c3e80d, 2017-08-06"
sodipodi:docname="fuel.svg">
<defs
id="defs2" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="5.6"
inkscape:cx="70.825635"
inkscape:cy="47.633986"
inkscape:document-units="mm"
inkscape:current-layer="layer1"
showgrid="true"
inkscape:window-width="1366"
inkscape:window-height="714"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="1">
<inkscape:grid
type="xygrid"
id="grid815"
originx="-85.489575"
originy="-141.05208" />
</sodipodi:namedview>
<metadata
id="metadata5">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(-85.489576,-133.78125)">
<path
style="opacity:1;fill:#be220f;fill-opacity:1;stroke:#000000;stroke-width:3.77952766;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;paint-order:fill markers stroke"
d="m 41.890625,1.890625 -30.000829,14.999138 8.29e-4,55.000862 10,10 h 40 l 10,-10 v -60 l -10,-10 z m 4.999171,4.9991383 h 10 l 5,9.9999997 h -25 z"
transform="matrix(0.26458333,0,0,0.26458333,85.489576,133.78125)"
id="rect821"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cccccccccccccc" />
<path
style="opacity:1;vector-effect:none;fill:#791c11;fill-opacity:1;stroke:#000000;stroke-width:1;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;paint-order:fill markers stroke"
d="m 93.927084,144.86458 h 5.291667 v 5.29166 h -5.291667 z"
id="rect908-7"
inkscape:connector-curvature="0"
sodipodi:nodetypes="ccccc" />
<path
style="opacity:1;vector-effect:none;fill:#1f1f1f;fill-opacity:1;stroke:#000000;stroke-width:1;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;paint-order:fill markers stroke"
d="m 89.958334,135.60417 2.645834,-1.32292 1.322916,1.32292 -3.96875,1.32291 z"
id="rect908-7-6"
inkscape:connector-curvature="0"
sodipodi:nodetypes="ccccc" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 3.2 KiB

View file

@ -23,7 +23,8 @@ export const images = {
},
connector: {
xheavy: 'modules/xheavy_connector.svg'
}
},
fuelcan: 'modules/fuelcan.svg'
},
celestials: {
green: {
@ -35,6 +36,7 @@ export const images = {
export const audio = {
itemPickup: 'up1.mp3',
fuelPickup: 'blip2.mp3',
endEdit: 'release1.mp3'
};

View file

@ -23,7 +23,7 @@ export const ZOOM_SPEED = 0.01;
export const TIP_ANGLE = 0.25;
export const TIP_SPEED = 0.03;
// Ship flight mechanics. Speed measured in units per tick.
export const FUEL_BURN_RATE = 0.01;
export const FUEL_BURN_RATE = 0.3;
export const THRUST_POWER = 0.004;
export const TURN_POWER = 0.07;
// Distance at which an orbited planet will not be considered a parent body.
@ -33,6 +33,7 @@ export const EDIT_MARGIN = 2;
// Floating items.
export const ENTITY_ROTATION_RATE = 0.01;
// World generation.
export const PLANET_SPAWN_RATE = 0.00002;
export const ENTITY_SPAWN_RATE = 0.3;
export const PLANET_SPAWN_RATE = 3;
export const ENTITY_SPAWN_RATE = 8;
export const MIN_CELESTIAL_SPACING = 15;
export const FUEL_CAN_AMOUNT = 4;

View file

@ -5,6 +5,7 @@ import * as inventory from './inventory.mjs';
import * as particle from '../world/particle.mjs';
import * as edit from './edit.mjs';
import * as audio from './audio.mjs';
import * as consts from '../consts.mjs';
export let shipLanded = false;
export let score = 0;
@ -105,9 +106,17 @@ export function tossItem() {
}
export function collectItem(type, id) {
inventory.addItem(type, id);
audio.play('itemPickup');
score += 20;
notify('Collected module: +20');
return true;
if (type === 'fuelcan') {
world.playerShip.addFuel(consts.FUEL_CAN_AMOUNT);
audio.play('fuelPickup');
score += 10;
notify('Collected fuel: +10');
return true;
} else {
inventory.addItem(type, id);
audio.play('itemPickup');
score += 20;
notify('Collected module: +20');
return true;
}
}

View file

@ -110,13 +110,13 @@ export default class Body {
this.rvel += r / this.mass;
}
orbit(cel, altitude) {
orbit(cel, altitude, angle = 0) {
this.gravity = true;
let speed = Math.sqrt(G * cel.mass / (altitude + cel.radius));
let [cx, cy] = cel.com;
this.x = cx;
this.y = cy - (altitude + cel.radius);
this.yvel = 0;
this.xvel = speed;
let [dx, dy] = this.rotateVector(0, -(altitude + cel.radius), angle);
[this.xvel, this.yvel] = this.rotateVector(speed, 0, angle);
this.x = cx + dx;
this.y = cy + dy;
}
}

View file

@ -14,7 +14,6 @@ export default class Entity extends Body {
gravity = false
} = {}) {
super(x, y, 0.1);
this.xvel = xvel;
this.yvel = yvel;
this.width = 1;
@ -22,7 +21,13 @@ export default class Entity extends Body {
this.radius = (this.width + this.height) / 2;
this.type = type;
this.id = id;
this.image = assets.modules[type][id];
if (this.type === 'fuelcan') {
this.image = assets.modules.fuelcan;
} else {
this.image = assets.modules[type][id];
if (this.type === 'thruster')
this.image = this.image.off;
}
this.gravity = gravity;
this.touched = false;
}
@ -36,6 +41,8 @@ export default class Entity extends Body {
}
tick() {
if (Math.abs(playerShip.x - this.x) > 500 ||
Math.abs(playerShip.y - this.y) > 500) return;
this.r += consts.ENTITY_ROTATION_RATE;
this.tickMotion();
if (this.gravity) this.tickGravity(celestials);
@ -47,6 +54,7 @@ export default class Entity extends Body {
if (playerShip.colliding(this.com, this.radius)) {
if (this.touched) return;
this.touched = true;
let success = events.collectItem(this.type, this.id);
if (!success) return;
particle.createPickupBurst(playerShip, this.com);

View file

@ -7,8 +7,6 @@ export default class Module {
type = 'block',
id = 'unknown',
mass = 1,
// Fuel
filled = false,
fuelCapacity = 0,
...properties
}) {
@ -21,10 +19,8 @@ export default class Module {
this.id = id;
this.images = assets.modules[this.type][this.id];
this.data = modules[this.type][this.id];
// Fuel
if (this.type == 'fuel') {
this.fuel = filled ? fuelCapacity : 0;
} else if (this.type == 'thruster') {
if (this.type == 'thruster') {
this.power = 0;
}
}

View file

@ -74,6 +74,10 @@ export default class Ship extends Body {
this.modules.clear();
}
addFuel(amount) {
this.fuel = Math.min(this.fuel + amount, this.maxFuel);
}
addModule(x, y, properties, options) {
let module = new Module(x, y, this, {...properties, ...options});
this.modules.add(module);
@ -188,6 +192,7 @@ export default class Ship extends Body {
let thrustForce = -forward * consts.THRUST_POWER * this.thrust;
let turnForce = (turnRight - turnLeft) * consts.TURN_POWER;
turnForce *= this.rotationPower;
this.fuel -= Math.abs(thrustForce) * consts.FUEL_BURN_RATE;
this.applyDirectionalForce(0, thrustForce, turnForce);

View file

@ -41,11 +41,11 @@ function nearest(x, y, set) {
function spawnSector(x, y) {
let area = SS ** 2;
for (let i = 0; i < area / 10000; i++) {
for (let i = 0; i < area / 1000; i++) {
let [px, py] = [(x + Math.random()) * SS, (y + Math.random()) * SS];
if (Math.random() > consts.PLANET_SPAWN_RATE) {
if (Math.random() < consts.PLANET_SPAWN_RATE / 1000) {
randomPlanet(px, py);
} else if (Math.random() > 0.01 ){
} else if (Math.random() < consts.ENTITY_SPAWN_RATE / 1000){
randomEntity(px, py);
}
}
@ -68,13 +68,23 @@ function randomPlanet(x, y) {
for (let i = 1.5; i < 8; i += 1) {
if (Math.random() > consts.ENTITY_SPAWN_RATE) {
let e = randomEntity();
e.orbit(planet, i * rad);
e.orbit(planet, i * rad, Math.random() * Math.PI * 2);
}
}
}
function randomEntity(x, y) {
let entity = new Entity(x, y);
let entity, type, id;
if (Math.random() > 0.3) {
entity = new Entity(x, y, 'fuelcan');
} else {
let arr = Object.entries(modules);
[type, arr] = arr[Math.random() * arr.length | 0];
arr = Object.keys(arr);
entity = new Entity(x, y, type, arr[Math.random() * arr.length | 0]);
}
world.entities.add(entity);
return entity;
}
@ -88,6 +98,7 @@ export function player() {
//ship.addModule(-1, 2, modules.thruster.light);
world.ships.add(ship);
world.setPlayerShip(ship);
ship.addFuel(ship.maxFuel);
let tracer = new Tracer(ship);
world.tracers.add(tracer);