Small energy optimization

This commit is contained in:
zenoamaro committed 2019-06-27 22:49:57 +02:00
1 parent a5fa585d11
commit 903ab705d8
1 file changed
+6
+6
View File
@@ -10,6 +10,7 @@ import {sample} from './utils.js';
import {AI_TYPES} from './ai.js'; import {AI_TYPES} from './ai.js';
let idle = false;
let state = 'start-turn'; let state = 'start-turn';
const players = []; const players = [];
let currentPlayer = 0; let currentPlayer = 0;
@@ -57,6 +58,8 @@ for (let color of PLAYER_COLORS) {
} }
function update() { function update() {
idle = false;
if (state === 'start-turn') { if (state === 'start-turn') {
wind = randomInt(-MAX_WIND, +MAX_WIND); wind = randomInt(-MAX_WIND, +MAX_WIND);
state = 'aim'; state = 'aim';
@@ -95,6 +98,8 @@ function update() {
playTickSound(); playTickSound();
} else if (key(' ')) { } else if (key(' ')) {
shoot = {a, p}; shoot = {a, p};
} else {
idle = true;
} }
if (shoot) { if (shoot) {
@@ -236,6 +241,7 @@ function update() {
} }
function draw() { function draw() {
if (idle) return;
foreground.clearRect(0, 0, W, H); foreground.clearRect(0, 0, W, H);
if (projectile) drawProjectile(); if (projectile) drawProjectile();
for (let tank of players) drawPlayer(tank); for (let tank of players) drawPlayer(tank);