diff --git a/src/main.js b/src/main.js index 61f1617..dcb70ce 100644 --- a/src/main.js +++ b/src/main.js @@ -7,7 +7,7 @@ import {PROJECTILE_TYPES} from './projectiles.js'; import {generateSky} from './sky.js'; import {playTickSound} from './sound.js'; import {clipTerrain, closestLand, collapseTerrain, generateTerrain, isTerrain, landHeight} from './terrain.js'; -import {sample} from './utils.js'; +import {sample, shuffle} from './utils.js'; import {EXPLOSION_TYPES} from './weapons.js'; @@ -56,15 +56,12 @@ function init() { } function initPlayers() { - let i=0; - for (let [color, borderColor] of PLAYER_COLORS) { - const x = 50 + (W-100) / 5 * i; - const y = landHeight(terrain, x) + 1; - const a = x > W/2 ? 45 : 180-45; + for (let i=0; i ({...x})), // FIXME: Ghetto clone @@ -76,8 +73,18 @@ function initPlayers() { parachute: null, fallHeight: 0, }); - clipTerrain(terrain, (ctx) => drawRect(ctx, x-4, 0, 8, y, ctx.color)); - i++; + } + + // Randomize positions + players = shuffle(players); + + // Positions + for (let i=0; i W/2 ? 45 : 180-45; + clipTerrain(terrain, (ctx) => drawRect(ctx, player.x-4, 0, 8, player.y, ctx.color)); } } diff --git a/src/utils.js b/src/utils.js index b6055e8..5b28048 100644 --- a/src/utils.js +++ b/src/utils.js @@ -4,6 +4,23 @@ export function sample(arr) { return arr[randomInt(0, arr.length-1)]; } +export function without(arr, item) { + return arr.filter(x => x !== item); +} + +export function shuffle(arr) { + const result = []; + let original = [...arr]; + + for (let i=0; i