diff --git a/dist/audio/blip1.mp3 b/dist/audio/blip1.mp3 new file mode 100644 index 0000000..5a46eae Binary files /dev/null and b/dist/audio/blip1.mp3 differ diff --git a/dist/audio/blip2.mp3 b/dist/audio/blip2.mp3 new file mode 100644 index 0000000..9fa513b Binary files /dev/null and b/dist/audio/blip2.mp3 differ diff --git a/dist/audio/crash1.mp3 b/dist/audio/crash1.mp3 new file mode 100644 index 0000000..1213b30 Binary files /dev/null and b/dist/audio/crash1.mp3 differ diff --git a/dist/audio/release1.mp3 b/dist/audio/release1.mp3 new file mode 100644 index 0000000..6a0f1cc Binary files /dev/null and b/dist/audio/release1.mp3 differ diff --git a/dist/audio/rocket1.mp3 b/dist/audio/rocket1.mp3 new file mode 100644 index 0000000..c5dc9f3 Binary files /dev/null and b/dist/audio/rocket1.mp3 differ diff --git a/dist/audio/swoosh1.mp3 b/dist/audio/swoosh1.mp3 new file mode 100644 index 0000000..7b9ad0e Binary files /dev/null and b/dist/audio/swoosh1.mp3 differ diff --git a/dist/audio/thunk1.mp3 b/dist/audio/thunk1.mp3 new file mode 100644 index 0000000..035183a Binary files /dev/null and b/dist/audio/thunk1.mp3 differ diff --git a/dist/audio/thunk2.mp3 b/dist/audio/thunk2.mp3 new file mode 100644 index 0000000..9c4919c Binary files /dev/null and b/dist/audio/thunk2.mp3 differ diff --git a/dist/audio/twinkle1.mp3 b/dist/audio/twinkle1.mp3 new file mode 100644 index 0000000..1c38ed8 Binary files /dev/null and b/dist/audio/twinkle1.mp3 differ diff --git a/dist/audio/up1.mp3 b/dist/audio/up1.mp3 new file mode 100644 index 0000000..a091497 Binary files /dev/null and b/dist/audio/up1.mp3 differ diff --git a/dist/audio/up2.mp3 b/dist/audio/up2.mp3 new file mode 100644 index 0000000..cdd24ab Binary files /dev/null and b/dist/audio/up2.mp3 differ diff --git a/dist/audio/up3.mp3 b/dist/audio/up3.mp3 new file mode 100644 index 0000000..b49b621 Binary files /dev/null and b/dist/audio/up3.mp3 differ diff --git a/dist/audio/wrong1.mp3 b/dist/audio/wrong1.mp3 new file mode 100644 index 0000000..7ecbece Binary files /dev/null and b/dist/audio/wrong1.mp3 differ diff --git a/dist/img/modules/xheavy_connector.svg b/dist/img/modules/xheavy_connector.svg new file mode 100644 index 0000000..ea64e8d --- /dev/null +++ b/dist/img/modules/xheavy_connector.svg @@ -0,0 +1,146 @@ + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/js/assets.mjs b/js/assets.mjs index 60c0b70..d6bf871 100644 --- a/js/assets.mjs +++ b/js/assets.mjs @@ -20,6 +20,9 @@ export const images = { off: 'modules/light_thruster.svg', on: 'modules/light_thruster_on.svg', } + }, + connector: { + xheavy: 'modules/xheavy_connector.svg' } }, celestials: { @@ -29,7 +32,10 @@ export const images = { } }; -export const audio = {}; +export const audio = { + itemPickup: 'up1.mp3', + endEdit: 'release1.mp3' +}; export async function init() { let parse = (obj, convert) => Object.entries(obj).forEach(([k, v]) => { @@ -46,7 +52,11 @@ export async function init() { return img; }); parse(audio, str => { - // TODO: Load audio. + let audio = new Audio('audio/' + str); + promises.push(new Promise((res, rej) => { + audio.addEventListener('canplaythrough', res); + })); + return audio; }); await Promise.all(promises); diff --git a/js/data.mjs b/js/data.mjs index 1c36467..52d98a5 100644 --- a/js/data.mjs +++ b/js/data.mjs @@ -5,12 +5,13 @@ export const modules = { small: { name: 'Small Capsule', tooltip: 'A small, simple capsule. Provides just enough ' + - 'rotational power for a small rocket.', + 'rotational power for a small rocket and has a small ' + + 'amount of storage space.', type: 'capsule', id: 'small', mass: 2, connectivity: [false, false, true, false], - capacity: 3, + capacity: 2, rotation: 0.1 } }, @@ -37,5 +38,16 @@ export const modules = { thrust: 10, isp: 200 } + }, + connector: { + xheavy: { + name: 'Heavy 4-way Connector', + tooltip: 'Can connect ship parts in any direction, but is quite ' + + 'heavy', + type: 'connector', + id: 'xheavy', + mass: 5, + connectivity: [true, true, true, true] + } } } diff --git a/js/game/audio.mjs b/js/game/audio.mjs new file mode 100644 index 0000000..3e00707 --- /dev/null +++ b/js/game/audio.mjs @@ -0,0 +1,5 @@ +import {audio} from '../assets.mjs'; + +export function play(name) { + audio[name].cloneNode(true).play(); +} diff --git a/js/game/edit.mjs b/js/game/edit.mjs index 67eb4da..f70d8fc 100644 --- a/js/game/edit.mjs +++ b/js/game/edit.mjs @@ -87,7 +87,9 @@ function validate() { if (tile.type == 'thruster') thrustersFound++; if (tile.type == 'fuel') fuelFound++; tile.neighbours.forEach(n => { - if (unvisited.has(n)) visit(n); + if (unvisited.has(n) && n.neighbours.indexOf(tile) > -1) { + visit(n); + } }); }; @@ -111,7 +113,7 @@ function validate() { } else { message = reason; } - + return reason; } diff --git a/js/game/events.mjs b/js/game/events.mjs index 4bc95c3..957d488 100644 --- a/js/game/events.mjs +++ b/js/game/events.mjs @@ -5,6 +5,7 @@ import * as player from './player.mjs'; 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'; export let shipLanded = false; @@ -71,6 +72,7 @@ export function endEditing() { let {valid, reason} = edit.end(); if (valid) { + audio.play('endEdit'); graphics.changePerspective('universe'); game.state.editing = false; game.state.inventory = false; @@ -91,5 +93,6 @@ export function tossItem() { export function collectItem(type, id) { inventory.addItem(type, id); + audio.play('itemPickup'); return true; } diff --git a/js/game/inventory.mjs b/js/game/inventory.mjs index 4565f50..d1f7f25 100644 --- a/js/game/inventory.mjs +++ b/js/game/inventory.mjs @@ -10,6 +10,7 @@ let onupdate = () => {}; export function init() { items.clear(); + addItem('connector', 'xheavy'); } export function getTiles() { diff --git a/js/graphics/world.mjs b/js/graphics/world.mjs index 059851f..6d59b26 100644 --- a/js/graphics/world.mjs +++ b/js/graphics/world.mjs @@ -10,6 +10,14 @@ export function render() { if (graphics.trace) world.tracers.forEach(renderTracer); world.ships.forEach(renderShip); world.entities.forEach(renderEntity); + + /* + if (typeof window.q === 'undefined') window.q = []; + q.forEach(p => { + context.fillStyle = p[2]; + context.fillRect(p[0] - 0.05, p[1] - 0.05, 0.1, 0.1); + }); + */ } function renderParticle(particle) { diff --git a/js/gui/modules.mjs b/js/gui/modules.mjs index 4a02d5e..78914a1 100644 --- a/js/gui/modules.mjs +++ b/js/gui/modules.mjs @@ -88,11 +88,17 @@ export function game() { }; + let invShadow = root(); + shadow.append(invShadow); + invShadow.posRelative({x: 0, w: 0.4, h: 0.6}); + invShadow.x += 10; + invShadow.y += 10; + invShadow.h += 60; + let inventory = new GuiInventory(0, 0, 0, 0); - shadow.append(inventory); - inventory.posRelative({x: 0, y: 0, w: 0.4, h: 0.6}); - inventory.x += 10; - inventory.y += 10; + invShadow.append(inventory); + inventory.posRelative({w: 1, h: 1}); + inventory.h -= 60; edit.guiInventory = inventory; diff --git a/js/world/body.mjs b/js/world/body.mjs index 0cbf4f9..c9b93ab 100644 --- a/js/world/body.mjs +++ b/js/world/body.mjs @@ -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`. diff --git a/js/world/index.mjs b/js/world/index.mjs index 8441d4c..2f3e829 100644 --- a/js/world/index.mjs +++ b/js/world/index.mjs @@ -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()); } diff --git a/js/world/ship.mjs b/js/world/ship.mjs index 97c456f..d64559d 100644 --- a/js/world/ship.mjs +++ b/js/world/ship.mjs @@ -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; } diff --git a/js/world/spawn.mjs b/js/world/spawn.mjs index 919bc32..bb2a9dd 100644 --- a/js/world/spawn.mjs +++ b/js/world/spawn.mjs @@ -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);