From 9095d0c6b07a8eea737221628c6edd282ec822a3 Mon Sep 17 00:00:00 2001 From: zenoamaro Date: Sun, 30 Jun 2019 20:02:45 +0200 Subject: [PATCH] Fewer trajectory fades --- src/constants.js | 22 +++++++++++----------- src/main.js | 29 +++++++++++++---------------- 2 files changed, 24 insertions(+), 27 deletions(-) diff --git a/src/constants.js b/src/constants.js index 0d10b16..c05ef8a 100644 --- a/src/constants.js +++ b/src/constants.js @@ -25,15 +25,15 @@ export const PLAYER_COLORS = [ export const PLAYER_STARTING_WEAPONS = [ {type: 'babyMissile', ammo:Infinity}, {type: 'missile', ammo:5}, - {type: 'babyNuke', ammo:3}, - {type: 'nuke', ammo:1}, - {type: 'smallDirt', ammo:5}, - {type: 'dirt', ammo:3}, - {type: 'largeDirt', ammo:1}, - {type: 'smallDigBomb', ammo:5}, - {type: 'digBomb', ammo:3}, - {type: 'largeDigBomb', ammo:1}, - {type: 'tracer', ammo:Infinity}, + // {type: 'babyNuke', ammo:3}, + // {type: 'nuke', ammo:1}, + // {type: 'smallDirt', ammo:5}, + // {type: 'dirt', ammo:3}, + // {type: 'largeDirt', ammo:1}, + // {type: 'smallDigBomb', ammo:5}, + // {type: 'digBomb', ammo:3}, + // {type: 'largeDigBomb', ammo:1}, + // {type: 'tracer', ammo:Infinity}, ] export const WEAPON_TYPES = [ @@ -91,8 +91,8 @@ export const PROJECTILE_ITERATIONS_PER_FRAME = 30; export const PROJECTILE_ITERATION_PROGRESS = 0.01; export const PROJECTILE_MIN_SOUND_FREQUENCY = 220; export const PROJECTILE_MAX_SOUND_FREQUENCY = 2200; -export const TRAJECTORY_FADE_SPEED = 0.6; -export const TRAJECTORY_FLOAT_SPEED = 0.01; +export const TRAJECTORY_FADE_SPEED = 10; +export const TRAJECTORY_FLOAT_SPEED = 0.3; export const PARTICLE_AMOUNT = 30; export const PARTICLE_MIN_POWER_FACTOR = 0.4; diff --git a/src/main.js b/src/main.js index 07ccf13..0408395 100644 --- a/src/main.js +++ b/src/main.js @@ -189,8 +189,6 @@ function update() { } } - fadeTrajectories(TRAJECTORY_FADE_SPEED); - let trajectory = drawLineVirtual( prevProjectile.x, prevProjectile.y, projectile.x, projectile.y, @@ -286,6 +284,7 @@ function update() { } projectile = null; + fadeTrajectories(); state = 'start-turn'; } @@ -403,33 +402,31 @@ function drawPlayers() { function drawTrajectories() { traces.clearRect(0, 0, W, H); - for (let {x, y, c, a} of trajectories) { - traces.globalAlpha = a / 255; + for (let i=trajectories.length-1; i>=0; i--) { + const trajectory = trajectories[i]; + const {x, y, c} = trajectory; + traces.globalAlpha = trajectory.a / 255; plot(traces, x, y, c); } traces.globalAlpha = 1; } -function drawProjectile() { - if (!projectile) return; - plot(foreground, clamp(0, projectile.x, W-1), clamp(0, projectile.y, H-1), 'white'); -} - -function fadeTrajectories(amount) { +function fadeTrajectories() { for (let i=trajectories.length-1; i>=0; i--) { const trajectory = trajectories[i]; - trajectory.a -= amount; + trajectory.a -= TRAJECTORY_FADE_SPEED; trajectory.y -= TRAJECTORY_FLOAT_SPEED; - - if ( - trajectory.a <= 0 || trajectory.y <= 0 || - isTerrain(terrain, trajectory.x, trajectory.y) - ) { + if (trajectory.a <= 0 || trajectory.y <= 0) { trajectories.splice(i, 1); } } } +function drawProjectile() { + if (!projectile) return; + plot(foreground, clamp(0, projectile.x, W-1), clamp(0, projectile.y, H-1), 'white'); +} + function drawExplosions() { if (!explosion) return; const explosionType = EXPLOSION_TYPES[explosion.type];