From 504f5fcc0c06e94b1f578fad76ed9c6f8fd4c346 Mon Sep 17 00:00:00 2001 From: asraelite Date: Wed, 7 Mar 2018 19:00:03 +0000 Subject: [PATCH] Add more modules --- dist/img/modules/advanced_capsule.svg | 87 ++++++++++ dist/img/modules/advanced_connector.svg | 130 ++++++++++++++ dist/img/modules/advanced_fuel_tank.svg | 105 ++++++++++++ dist/img/modules/advanced_thruster.svg | 97 +++++++++++ dist/img/modules/advanced_thruster_on.svg | 97 +++++++++++ dist/img/modules/cargo_bay.svg | 87 ++++++++++ dist/img/modules/heavy_thruster.svg | 121 +++++++++++++ dist/img/modules/large_capsule.svg | 99 +++++++++++ dist/img/modules/large_fuel_tank.svg | 117 +++++++++++++ dist/img/modules/large_gyroscope.svg | 198 ++++++++++++++++++++++ dist/img/modules/small_gyroscope.svg | 147 ++++++++++++++++ js/assets.mjs | 28 ++- js/consts.mjs | 2 +- js/data.mjs | 113 +++++++++++- js/game/edit.mjs | 2 + js/game/events.mjs | 5 +- js/world/ship.mjs | 10 ++ js/world/spawn.mjs | 14 +- 18 files changed, 1448 insertions(+), 11 deletions(-) create mode 100644 dist/img/modules/advanced_capsule.svg create mode 100644 dist/img/modules/advanced_connector.svg create mode 100644 dist/img/modules/advanced_fuel_tank.svg create mode 100644 dist/img/modules/advanced_thruster.svg create mode 100644 dist/img/modules/advanced_thruster_on.svg create mode 100644 dist/img/modules/cargo_bay.svg create mode 100644 dist/img/modules/heavy_thruster.svg create mode 100644 dist/img/modules/large_capsule.svg create mode 100644 dist/img/modules/large_fuel_tank.svg create mode 100644 dist/img/modules/large_gyroscope.svg create mode 100644 dist/img/modules/small_gyroscope.svg diff --git a/dist/img/modules/advanced_capsule.svg b/dist/img/modules/advanced_capsule.svg new file mode 100644 index 0000000..bd6b80f --- /dev/null +++ b/dist/img/modules/advanced_capsule.svg @@ -0,0 +1,87 @@ + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + diff --git a/dist/img/modules/advanced_connector.svg b/dist/img/modules/advanced_connector.svg new file mode 100644 index 0000000..23cb83e --- /dev/null +++ b/dist/img/modules/advanced_connector.svg @@ -0,0 +1,130 @@ + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + diff --git a/dist/img/modules/advanced_fuel_tank.svg b/dist/img/modules/advanced_fuel_tank.svg new file mode 100644 index 0000000..ff2a75c --- /dev/null +++ b/dist/img/modules/advanced_fuel_tank.svg @@ -0,0 +1,105 @@ + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + diff --git a/dist/img/modules/advanced_thruster.svg b/dist/img/modules/advanced_thruster.svg new file mode 100644 index 0000000..c6c6d34 --- /dev/null +++ b/dist/img/modules/advanced_thruster.svg @@ -0,0 +1,97 @@ + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + diff --git a/dist/img/modules/advanced_thruster_on.svg b/dist/img/modules/advanced_thruster_on.svg new file mode 100644 index 0000000..75439d1 --- /dev/null +++ b/dist/img/modules/advanced_thruster_on.svg @@ -0,0 +1,97 @@ + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + diff --git a/dist/img/modules/cargo_bay.svg b/dist/img/modules/cargo_bay.svg new file mode 100644 index 0000000..711fa1c --- /dev/null +++ b/dist/img/modules/cargo_bay.svg @@ -0,0 +1,87 @@ + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + diff --git a/dist/img/modules/heavy_thruster.svg b/dist/img/modules/heavy_thruster.svg new file mode 100644 index 0000000..2c3a1e0 --- /dev/null +++ b/dist/img/modules/heavy_thruster.svg @@ -0,0 +1,121 @@ + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + diff --git a/dist/img/modules/large_capsule.svg b/dist/img/modules/large_capsule.svg new file mode 100644 index 0000000..ed016a0 --- /dev/null +++ b/dist/img/modules/large_capsule.svg @@ -0,0 +1,99 @@ + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + diff --git a/dist/img/modules/large_fuel_tank.svg b/dist/img/modules/large_fuel_tank.svg new file mode 100644 index 0000000..0d5e694 --- /dev/null +++ b/dist/img/modules/large_fuel_tank.svg @@ -0,0 +1,117 @@ + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + diff --git a/dist/img/modules/large_gyroscope.svg b/dist/img/modules/large_gyroscope.svg new file mode 100644 index 0000000..23ad29c --- /dev/null +++ b/dist/img/modules/large_gyroscope.svg @@ -0,0 +1,198 @@ + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + diff --git a/dist/img/modules/small_gyroscope.svg b/dist/img/modules/small_gyroscope.svg new file mode 100644 index 0000000..5bb1a98 --- /dev/null +++ b/dist/img/modules/small_gyroscope.svg @@ -0,0 +1,147 @@ + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + diff --git a/js/assets.mjs b/js/assets.mjs index 78d308d..789b46f 100644 --- a/js/assets.mjs +++ b/js/assets.mjs @@ -10,19 +10,39 @@ export const images = { }, modules: { capsule: { - small: 'modules/small_capsule.svg' + small: 'modules/small_capsule.svg', + large: 'modules/large_capsule.svg', + advanced: 'modules/advanced_capsule.svg' }, fuel: { - small: 'modules/small_fuel_tank.svg' + small: 'modules/small_fuel_tank.svg', + large: 'modules/large_fuel_tank.svg', + advanced: 'modules/advanced_fuel_tank.svg' }, thruster: { light: { off: 'modules/light_thruster.svg', - on: 'modules/light_thruster_on.svg', + on: 'modules/light_thruster_on.svg' + }, + heavy: { + off: 'modules/light_thruster.svg', + on: 'modules/light_thruster_on.svg' + }, + advanced: { + off: 'modules/light_thruster.svg', + on: 'modules/light_thruster_on.svg' } }, connector: { - xheavy: 'modules/xheavy_connector.svg' + xheavy: 'modules/xheavy_connector.svg', + advanced: 'modules/advanced_connector.svg', + }, + cargo: { + small: 'modules/cargo_bay.svg' + }, + gyroscope: { + small: 'modules/small_gyroscope.svg', + large: 'modules/large_gyroscope.svg' }, fuelcan: 'modules/fuelcan.svg' }, diff --git a/js/consts.mjs b/js/consts.mjs index fabe2f8..6bc3ca8 100644 --- a/js/consts.mjs +++ b/js/consts.mjs @@ -34,7 +34,7 @@ export const EDIT_MARGIN = 2; // Floating items. export const ENTITY_ROTATION_RATE = 0.01; // World generation. -export const PLANET_SPAWN_RATE = 50; +export const PLANET_SPAWN_RATE = 100; export const ENTITY_SPAWN_RATE = 8; export const MIN_CELESTIAL_SPACING = 15; export const FUEL_CAN_AMOUNT = 4; diff --git a/js/data.mjs b/js/data.mjs index 2190d22..82256ea 100644 --- a/js/data.mjs +++ b/js/data.mjs @@ -9,9 +9,34 @@ export const modules = { type: 'capsule', id: 'small', mass: 2, + value: 5, connectivity: [false, false, true, false], capacity: 2, rotation: 1 + }, + large: { + name: 'Large Capsule', + tooltip: 'A large, bulky capsule. Heavy, but has a lot of ' + + 'rotational power and storage space.', + type: 'capsule', + id: 'large', + mass: 4, + value: 10, + connectivity: [false, false, true, false], + capacity: 5, + rotation: 4 + }, + advanced: { + name: 'Advanced Capsule', + tooltip: 'A futuristic rocket capsule. Has a lot of storage ' + + 'space and rotational power while still being light.', + type: 'capsule', + id: 'advanced', + mass: 2, + value: 30, + connectivity: [false, false, true, false], + capacity: 4, + rotation: 5 } }, fuel: { @@ -21,20 +46,62 @@ export const modules = { type: 'fuel', id: 'small', mass: 1, + value: 1, connectivity: [true, false, true, false], fuelCapacity: 5 + }, + large: { + name: 'Large Fuel Tank', + tooltip: 'A large, heavy fuel tank capable of hold a lot of fuel.', + type: 'fuel', + id: 'large', + mass: 2, + value: 3, + connectivity: [true, false, true, false], + fuelCapacity: 15 + }, + advanced: { + name: 'Advanced Fuel Tank', + tooltip: 'A very efficient fuel storage tank.', + type: 'fuel', + id: 'advanced', + mass: 1, + value: 15, + connectivity: [true, false, true, false], + fuelCapacity: 12 } }, thruster: { light: { - name: 'Light Main Thruster', + name: 'Light Thruster', tooltip: 'Powerful enough to lift a small ship, but not much ' + 'more.', type: 'thruster', id: 'light', mass: 2, + value: 3, connectivity: [true, false, false, false], thrust: 10 + }, + heavy: { + name: 'Heavy Thruster', + tooltip: 'A powerful thruster for lifting heavy ships.', + type: 'thruster', + id: 'heavy', + mass: 5, + value: 6, + connectivity: [true, false, false, false], + thrust: 40 + }, + advanced: { + name: 'Advanced Thruster', + tooltip: 'A very efficient thruster using advanced technology. ', + type: 'thruster', + id: 'advanced', + mass: 2, + value: 20, + connectivity: [true, false, false, false], + thrust: 30 } }, connector: { @@ -45,7 +112,51 @@ export const modules = { type: 'connector', id: 'xheavy', mass: 5, + value: 3, connectivity: [true, true, true, true] + }, + advanced: { + name: 'Advanced 4-way Connector', + tooltip: 'Connects ship parts while remaining light.', + type: 'connector', + id: 'advanced', + mass: 1, + value: 15, + connectivity: [true, true, true, true] + } + }, + gyroscope: { + small: { + name: 'Small gyroscope', + tooltip: 'Provides a small amount of rotational power to the ship.', + type: 'gyroscope', + id: 'small', + mass: 3, + value: 7, + connectivity: [true, false, true, false], + rotation: 2 + }, + large: { + name: 'Large gyroscope', + tooltip: 'Provides a lot of rotational force for large ships.', + type: 'gyroscope', + id: 'large', + mass: 5, + value: 15, + connectivity: [true, false, true, false], + rotation: 4 + } + }, + cargo: { + small: { + name: 'Cargo bay', + tooltip: 'A cargo bay for storing modules.', + type: 'cargo', + id: 'small', + mass: 1, + value: 5, + connectivity: [true, false, true, false], + capacity: 5 } } } diff --git a/js/game/edit.mjs b/js/game/edit.mjs index aa5db27..4270154 100644 --- a/js/game/edit.mjs +++ b/js/game/edit.mjs @@ -85,6 +85,8 @@ function getAttributes() { thrust += t.module.thrust; } else if (t.type === 'gyroscope') { rotation += t.module.rotation; + } else if (t.type === 'cargo') { + cargo += t.module.capacity; } mass += t.module.mass; }); diff --git a/js/game/events.mjs b/js/game/events.mjs index 3d11cdb..fe770e4 100644 --- a/js/game/events.mjs +++ b/js/game/events.mjs @@ -22,6 +22,10 @@ export function init() { shipLanded = false; } +export function outOfFuel() { + gameOver('You ran out of fuel'); +} + export function playMusic() { audio.start('music'); audio.volume('music', 0.4); @@ -97,7 +101,6 @@ export function crash() { gameOver('You crashed'); audio.play('crash'); particle.createCrash(world.playerShip); - } export function gameOver(reason) { diff --git a/js/world/ship.mjs b/js/world/ship.mjs index 5f410e7..05d0f1c 100644 --- a/js/world/ship.mjs +++ b/js/world/ship.mjs @@ -23,6 +23,7 @@ export default class Ship extends Body { this.cargoCapacity = 0; this.thrust = 0; this.crashed = false; + this.timeWithoutFuel = 0; } get com() { @@ -69,6 +70,13 @@ export default class Ship extends Body { events.launchShip() } } + + if (this.fuel === 0 && !state.gameOver) { + if (this.timeWithoutFuel++ > 300) + events.outOfFuel(); + } else { + this.timeWithoutFuel = 0; + } } clearModules() { @@ -116,6 +124,8 @@ export default class Ship extends Body { this.thrust += m.data.thrust; } else if (m.type === 'gyroscope') { this.rotationPower += m.data.rotation; + } else if (m.type === 'cargo') { + this.cargoCapacity += m.data.capacity; } }); } diff --git a/js/world/spawn.mjs b/js/world/spawn.mjs index f1c244d..cca2264 100644 --- a/js/world/spawn.mjs +++ b/js/world/spawn.mjs @@ -105,10 +105,16 @@ function randomEntity(x, y) { 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]); + let type, id; + while (true) { + let arr = Object.entries(modules); + [type, arr] = arr[Math.random() * arr.length | 0]; + arr = Object.keys(arr); + id = arr[Math.random() * arr.length | 0]; + let value = modules[type][id].value; + if (Math.random() < (1 / value)) break; + } + entity = new Entity(x, y, type, id); } world.entities.add(entity);