Add audio

This commit is contained in:
asraelite 2018-03-06 20:07:13 +00:00
parent 0101ef8d55
commit 62b8c74f57
26 changed files with 225 additions and 18 deletions

View file

@ -41,7 +41,7 @@ export default class Body {
return result;
}
getWorldPoint(lx, ly) {
getWorldPoint(lx, ly, test) {
let [cx, cy] = this.localCom;
let [nx, ny] = this.rotateVector(lx - cx, ly - cy, this.r);
return [nx + this.x + cx, ny + this.y + cy];
@ -55,8 +55,8 @@ export default class Body {
}
rotateVector(x, y, r = this.r) {
return [(x * Math.cos(r) - y * Math.sin(r)),
(y * Math.cos(r) - x * Math.sin(r))];
return [(x * Math.cos(-r) + y * Math.sin(-r)),
-(-y * Math.cos(-r) + x * Math.sin(-r))];
}
// TODO: Remove and replace uses with `rotateVector`.

View file

@ -1,5 +1,6 @@
import * as sector from './sector.mjs';
import * as spawn from './spawn.mjs';
import * as graphics from '../graphics/index.mjs';
export {getSectorFromWorld, getContainedSectors} from './sector.mjs';
@ -31,5 +32,5 @@ export function tick() {
celestials.forEach(c => c.tick());
entities.forEach(e => e.tick());
ships.forEach(s => s.tick());
tracers.forEach(t => t.tick());
if (graphics.trace) tracers.forEach(t => t.tick());
}

View file

@ -41,6 +41,7 @@ export default class Ship extends Body {
}
tick() {
window.q = [];
if (!state.editing) this.tickMotion();
if (!this.landed) this.tickGravity(world.celestials);
if (!state.editing) this.resolveCollisions();
@ -109,19 +110,29 @@ export default class Ship extends Body {
});
}
})
window.q.push([...this.com, 'green']);
}
resolveCelestialCollision(pos, cel) {
let celToCom = this.angleTo(...this.com, ...cel.com);
let celToPoc = this.angleTo(...pos, ...cel.com);
let pocToCom = this.angleTo(...this.com, ...pos);
let shipAngle = this.r + Math.PI / 2;
window.q.push([...pos, 'blue']);
let turnAngle = this.angleDifference(celToPoc, pocToCom);
let checkAngle = this.angleDifference(celToPoc, this.r + Math.PI / 2);
let checkAngle = this.angleDifference(celToPoc, shipAngle);
let correctionAngle = this.angleDifference(shipAngle, pocToCom);
let [force] = this.rotateVector(0, 1, turnAngle);
if (Math.abs(checkAngle) < consts.TIP_ANGLE) force *= -1;
if (Math.abs(checkAngle) < consts.TIP_ANGLE) {
[force] = this.rotateVector(0, 1, correctionAngle);
force *= 0.2;
}
let canLand = Math.abs(checkAngle) < 0.03
&& Math.abs(this.rvel) < 0.001;
@ -131,7 +142,7 @@ export default class Ship extends Body {
this.rvel = 0;
this.r = celToCom - Math.PI / 2;
}
this.rvel += force * consts.TIP_SPEED;
}

View file

@ -11,9 +11,11 @@ export function player() {
ship.addModule(0, 0, modules.capsule.small);
ship.addModule(0, 1, modules.fuel.small);
ship.addModule(0, 2, modules.thruster.light);
//ship.addModule(1, 2, modules.thruster.light);
//ship.addModule(-1, 2, modules.thruster.light);
world.ships.add(ship);
world.setPlayerShip(ship);
let tracer = new Tracer(ship);
world.tracers.add(tracer);