From 8c4638e5b14bb895c02ee5be850f8e5dbc1a3608 Mon Sep 17 00:00:00 2001 From: Ben Date: Tue, 16 Oct 2018 20:50:25 +0100 Subject: [PATCH] bleh --- JavaScript/Snetris/index.js | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/JavaScript/Snetris/index.js b/JavaScript/Snetris/index.js index 56b9861..7ae65ed 100644 --- a/JavaScript/Snetris/index.js +++ b/JavaScript/Snetris/index.js @@ -118,6 +118,7 @@ class Block { } if (this.pixelPos.y >= this.targetPixelPos.y) { this.falling = false; + this.velocity = 0; this.pixelPos.y = this.targetPixelPos.y; } @@ -142,17 +143,24 @@ class Block { } /*<==== GAME INITIALIZATION ====>*/ -let GameGrid = [ ]; // 0 = empty, 1 = snake, 2 = apple -for (let i = 0; i < GAME_SIZE.x; i++) { - GameGrid[i] = [ ]; - for (let j = 0; j < GAME_SIZE.y; j++) { - GameGrid[i][j] = 0; - } -} +let GameGrid; +let Blocks; +let ActiveSnake; +let ActiveApple; -let Blocks = [ ]; -let ActiveSnake = new Snake(); -let ActiveApple = new Apple(); +function setup() { + GameGrid = [ ]; // 0 = empty, 1 = snake, 2 = apple + for (let i = 0; i < GAME_SIZE.x; i++) { + GameGrid[i] = [ ]; + for (let j = 0; j < GAME_SIZE.y; j++) { + GameGrid[i][j] = 0; + } + } + + Blocks = [ ]; + ActiveSnake = new Snake(); + ActiveApple = new Apple(); +} /*<==== GAME LOGIC AND EVENT HANDLING ====>*/ let stop = false; @@ -242,6 +250,7 @@ function handleKeyDown(event) { } } +setup(); window.addEventListener('keydown', handleKeyDown); setInterval(gameLoop, 1000 / UPDATE_RATE); setInterval(animationLoop, 1000 / ANIMATE_RATE);