From 37eab40230db4163d1c4d2619f0aa47d13fc29a6 Mon Sep 17 00:00:00 2001 From: zenoamaro Date: Mon, 24 Jun 2019 01:26:56 +0200 Subject: [PATCH] Constants --- constants.js | 29 +++++++++++++++++++++++++++++ main.js | 26 +++++++++++++------------- weapons.js | 7 ------- 3 files changed, 42 insertions(+), 20 deletions(-) create mode 100644 constants.js diff --git a/constants.js b/constants.js new file mode 100644 index 0000000..49f4caa --- /dev/null +++ b/constants.js @@ -0,0 +1,29 @@ +export const W = 640; +export const H = 400; +export const Z = 2; + +export const MAX_PLAYERS = 6; + +export const PLAYER_COLORS = [ + 'tomato', + 'royalblue', + 'greenyellow', + 'gold', + 'hotpink', + 'orchid', +]; + +export const WEAPON_TYPES = [ + {id:'baby-missile', name:'Baby Missile', xr:5}, + {id:'missile', name:'Missile', xr:10}, + {id:'baby-nuke', name:'Baby Nuke', xr:50}, + {id:'nuke', name:'Nuke', xr:100}, +]; + +export const PLAYER_INITIAL_POWER = 300; +export const MAX_WIND = 25; +export const REDUCTION_FACTOR = 10; +export const MIN_BULLET_SOUND_FREQUENCY = 220; +export const MAX_BULLET_SOUND_FREQUENCY = 2200; +export const PROJECTILE_ITERATIONS_PER_FRAME = 30; +export const PROJECTILE_ITERATION_PROGRESS = 0.01; diff --git a/main.js b/main.js index 06bf072..b152ae5 100644 --- a/main.js +++ b/main.js @@ -1,12 +1,12 @@ +import {H, MAX_BULLET_SOUND_FREQUENCY, MAX_WIND, MIN_BULLET_SOUND_FREQUENCY, PLAYER_COLORS, PLAYER_INITIAL_POWER, REDUCTION_FACTOR, W, WEAPON_TYPES, Z, PROJECTILE_ITERATIONS_PER_FRAME, PROJECTILE_ITERATION_PROGRESS} from './constants.js'; +import {createCanvas, drawLine, drawRect, drawText, loop} from './gfx.js'; import {key} from './input.js'; -import {createTerrain, clipTerrain, isTerrain, landHeight, collapseTerrain} from './terrain.js'; -import {createCanvas, drawLine, loop, drawText, drawRect} from './gfx.js'; -import {wrap, clamp, parable, deg2rad, vec, randomInt} from './math.js'; -import {drawExplosion, WEAPONS} from './weapons.js'; -import {createOsc, audio} from './sound.js'; +import {clamp, deg2rad, parable, randomInt, vec, wrap} from './math.js'; import {createSky} from './sky.js'; +import {audio, createOsc} from './sound.js'; +import {clipTerrain, collapseTerrain, createTerrain, isTerrain, landHeight} from './terrain.js'; +import {drawExplosion} from './weapons.js'; -const W = 640; const H = 400; const Z = 2; let state = 'start-turn'; const players = []; @@ -29,16 +29,16 @@ const projectiles = createCanvas(W, H); // Init players let i=0; -for (let color of ['tomato', 'royalblue', 'greenyellow', 'gold', 'hotpink', 'orchid']) { +for (let color of PLAYER_COLORS) { const x = Math.round(50 + (W-100) / 5 * i); const a = x > W/2 ? 45 : 180-45; - players.push({x, y:landHeight(terrain, x), a, p:300, c:color, weapon:WEAPONS[i%WEAPONS.length]}); + players.push({x, y:landHeight(terrain, x), a, p:PLAYER_INITIAL_POWER, c:color, weapon:WEAPON_TYPES[i%WEAPON_TYPES.length]}); i++; } function update() { if (state === 'start-turn') { - wind = randomInt(-25, +25); + wind = randomInt(-MAX_WIND, +MAX_WIND); state = 'aim'; } @@ -74,11 +74,11 @@ function update() { fadeProjectiles(1); fadeCount = 0; } - for (let i=0; i<30; i++) { + for (let i=0; i