From 03c3d3ec42bbd017b7b87a628ecce00719008c0a Mon Sep 17 00:00:00 2001 From: zenoamaro Date: Wed, 3 Jul 2019 01:04:15 +0200 Subject: [PATCH] Parachutes --- src/constants.js | 8 ++++++-- src/gfx.js | 10 ++++++++++ src/main.js | 44 +++++++++++++++++++++++++++++++++----------- 3 files changed, 49 insertions(+), 13 deletions(-) diff --git a/src/constants.js b/src/constants.js index c446f0b..485c9a7 100644 --- a/src/constants.js +++ b/src/constants.js @@ -30,8 +30,8 @@ export const PLAYER_STARTING_WEAPONS = [ {type: 'babyRoller', ammo:5}, {type: 'roller', ammo:3}, {type: 'superRoller', ammo:1}, - {type: 'mirv', ammo:5}, - {type: 'xmirv', ammo:3}, + {type: 'mirv', ammo:3}, + {type: 'xmirv', ammo:1}, {type: 'leapfrog', ammo:3}, {type: 'superLeapfrog', ammo:1}, {type: 'smallDirt', ammo:5}, @@ -81,6 +81,10 @@ export const DEATH_SPECS = [ {type: 'dirtCone', r: 400}, ]; +export const PLAYER_STARTING_TOOLS = [ + {type: 'parachute', ammo: 1}, +]; + export const MAX_WIND = 25; export const DEFAULT_KEYPRESS_DELAY = 150; diff --git a/src/gfx.js b/src/gfx.js index 9ef2d6c..90e7d6d 100644 --- a/src/gfx.js +++ b/src/gfx.js @@ -93,6 +93,16 @@ export function drawCircle(ctx, x, y, r, color) { } } +export function drawSemiCircle(ctx, x, y, r, color) { + x = Math.round(x); + y = Math.round(y); + r = Math.round(r); + for (let cy = -r; cy <= 0; cy++) { + const w = Math.round(Math.sqrt(r*r - cy*cy)); + drawRect(ctx, x-w, y+cy, w*2, 1, color); + } +} + /** @param align {CanvasTextAlign} */ /** @param baseline {CanvasTextBaseline} */ export function drawText(ctx, text, x, y, color, align='left', baseline='top') { diff --git a/src/main.js b/src/main.js index e75e0d4..262b2f8 100644 --- a/src/main.js +++ b/src/main.js @@ -1,6 +1,6 @@ import {AI_TYPES} from './ai.js'; -import {DEATH_SPECS, EXPLOSION_SHAKE_REDUCTION_FACTOR, H, MAX_EXPLOSION_SHAKE_FACTOR, MAX_WIND, PARTICLE_AMOUNT, PARTICLE_FADE_AMOUNT, PARTICLE_MAX_POWER_FACTOR, PARTICLE_MIN_LIFETIME, PARTICLE_MIN_POWER_FACTOR, PARTICLE_POWER_REDUCTION_FACTOR, PARTICLE_TIME_FACTOR, PARTICLE_WIND_REDUCTION_FACTOR, PLAYER_ANGLE_FAST_INCREMENT, PLAYER_ANGLE_INCREMENT, PLAYER_ANGLE_TICK_SOUND_INTERVAL, PLAYER_COLORS, PLAYER_ENERGY_POWER_MULTIPLIER, PLAYER_EXPLOSION_PARTICLE_POWER, PLAYER_FALL_DAMAGE_FACTOR, PLAYER_FALL_DAMAGE_HEIGHT, PLAYER_INITIAL_POWER, PLAYER_MAX_ENERGY, PLAYER_POWER_FAST_INCREMENT, PLAYER_POWER_INCREMENT, PLAYER_POWER_TICK_SOUND_INTERVAL, PLAYER_STARTING_WEAPONS, PLAYER_TANK_BOUNDING_RADIUS, PLAYER_TANK_Y_FOOTPRINT, TRAJECTORY_FADE_SPEED, TRAJECTORY_FLOAT_SPEED, W, WEAPON_TYPES, Z} from './constants.js'; -import {createCanvas, drawLine, drawRect, drawText, loop, plot} from './gfx.js'; +import {DEATH_SPECS, EXPLOSION_SHAKE_REDUCTION_FACTOR, H, MAX_EXPLOSION_SHAKE_FACTOR, MAX_WIND, PARTICLE_AMOUNT, PARTICLE_FADE_AMOUNT, PARTICLE_MAX_POWER_FACTOR, PARTICLE_MIN_LIFETIME, PARTICLE_MIN_POWER_FACTOR, PARTICLE_POWER_REDUCTION_FACTOR, PARTICLE_TIME_FACTOR, PARTICLE_WIND_REDUCTION_FACTOR, PLAYER_ANGLE_FAST_INCREMENT, PLAYER_ANGLE_INCREMENT, PLAYER_ANGLE_TICK_SOUND_INTERVAL, PLAYER_COLORS, PLAYER_ENERGY_POWER_MULTIPLIER, PLAYER_EXPLOSION_PARTICLE_POWER, PLAYER_FALL_DAMAGE_FACTOR, PLAYER_FALL_DAMAGE_HEIGHT, PLAYER_INITIAL_POWER, PLAYER_MAX_ENERGY, PLAYER_POWER_FAST_INCREMENT, PLAYER_POWER_INCREMENT, PLAYER_POWER_TICK_SOUND_INTERVAL, PLAYER_STARTING_TOOLS, PLAYER_STARTING_WEAPONS, PLAYER_TANK_BOUNDING_RADIUS, PLAYER_TANK_Y_FOOTPRINT, TRAJECTORY_FADE_SPEED, TRAJECTORY_FLOAT_SPEED, W, WEAPON_TYPES, Z} from './constants.js'; +import {createCanvas, drawLine, drawRect, drawSemiCircle, drawText, loop, plot} from './gfx.js'; import {afterKeyDelay, key} from './input.js'; import {clamp, deg2rad, distance, parable, random, randomInt, vec, wrap} from './math.js'; import {PROJECTILE_TYPES} from './projectiles.js'; @@ -49,7 +49,8 @@ for (let [color, borderColor] of PLAYER_COLORS) { x, y, a, c: color, cb: borderColor, p: PLAYER_INITIAL_POWER, - weapons: PLAYER_STARTING_WEAPONS.map(x => ({...x})), // FIXME + tools: PLAYER_STARTING_TOOLS.map(x => ({...x})), // FIXME: Ghetto clone + weapons: PLAYER_STARTING_WEAPONS.map(x => ({...x})), // FIXME: Ghetto clone currentWeapon: 0, energy: PLAYER_MAX_ENERGY, ai: i !== 0 ? sample(Object.keys(AI_TYPES)) : undefined, @@ -197,8 +198,17 @@ function update() { stable = false; player.y++; if (player.fallHeight++ >= PLAYER_FALL_DAMAGE_HEIGHT) { + if (player.energy > 0 && player.parachute) continue; + const parachute = player.tools.find(x => x.type === 'parachute'); + if (player.energy > 0 && parachute && parachute.ammo > 0) { + player.parachute = parachute; + parachute.ammo--; + continue; + } player.energy -= PLAYER_FALL_DAMAGE_FACTOR; } + } else { + player.parachute = null; } } if (stable) state = 'destroy-players'; @@ -227,16 +237,13 @@ function update() { return state = 'player-win'; } - const player = players[currentPlayer]; - - const weaponType = player.weapons[player.currentWeapon]; - if (weaponType.ammo <= 0) { - player.weapons = player.weapons.filter(x => x !== weaponType); + for (let player of players) { + player.weapons = player.weapons.filter(x => x.ammo > 0); + player.tools = player.tools.filter(x => x.ammo > 0); + player.currentWeapon = wrap(0, player.currentWeapon, player.weapons.length-1); + player.fallHeight = 0; } - player.currentWeapon = wrap(0, player.currentWeapon, player.weapons.length-1); - player.fallHeight = 0; - for (let p=0; p