From cb93c61774daedc72b578a7bb4cebd063c333f65 Mon Sep 17 00:00:00 2001 From: zenoamaro Date: Fri, 28 Jun 2019 02:18:54 +0200 Subject: [PATCH] Terrain colors --- main.js | 10 +++++++--- terrain.js | 49 +++++++++++++++++++++++++++++++++++++++---------- weapons.js | 14 +++++++------- 3 files changed, 53 insertions(+), 20 deletions(-) diff --git a/main.js b/main.js index 0f045f2..efac304 100644 --- a/main.js +++ b/main.js @@ -11,7 +11,7 @@ import {AI_TYPES} from './ai.js'; let idle = false; -let state = 'start-turn'; +let state = 'start-game'; const players = []; let currentPlayer = 0; let projectile = null; @@ -60,8 +60,12 @@ for (let color of PLAYER_COLORS) { function update() { idle = false; - if (state === 'start-turn') { + if (state === 'start-game') { wind = randomInt(-MAX_WIND, +MAX_WIND); + state = 'start-turn'; + } + + else if (state === 'start-turn') { state = 'aim'; } @@ -272,7 +276,7 @@ function fadeProjectiles(amount) { function drawExplosions() { const explosionType = EXPLOSION_TYPES[explosion.type]; - explosionType.draw(explosion, foreground); + explosionType.draw(explosion, foreground, terrain); } function drawStatus() { diff --git a/terrain.js b/terrain.js index 71973a0..e9e4a60 100644 --- a/terrain.js +++ b/terrain.js @@ -1,5 +1,6 @@ -import {createCanvas, drawRect, clipCanvas} from './gfx.js'; -import {coords2index} from './math.js'; +import {createCanvas, drawRect, clipCanvas, drawCircle} from './gfx.js'; +import {coords2index, random, randomInt, clamp} from './math.js'; +import {sample} from './utils.js'; let cachedImageData; @@ -10,18 +11,46 @@ function cacheImageData(ctx) { export function createTerrain(width, height) { const terrain = createCanvas(width, height); + const generateTerrain = sample(Object.values(TERRAIN_TYPES)); generateTerrain(terrain); return terrain; } -export function generateTerrain(ctx) { - const {width, height} = ctx.canvas; - for (let x=0; x