diff --git a/21g30t1e75.js b/21g30t1e75.js index 83ce25a..9b21ee0 100644 --- a/21g30t1e75.js +++ b/21g30t1e75.js @@ -17,7 +17,7 @@ GameLib.CustomCode.GRID_HEIGHT = 10; GameLib.CustomCode.GRID_OFFSET_X = 1; GameLib.CustomCode.GRID_OFFSET_Y = 8; -GameLib.CustomCode.SPEED_INITIAL = 0.5; +GameLib.CustomCode.SPEED_INITIAL = 1; GameLib.CustomCode.ORIENTATION_UP = 0; GameLib.CustomCode.ORIENTATION_LEFT = 1; @@ -35,6 +35,14 @@ GameLib.CustomCode.POWERUP_LIFE = 1; GameLib.CustomCode.POWERUP_SLOW = 2; GameLib.CustomCode.MAX_POWERUP_ITEMS = 3; +GameLib.CustomCode.SPEED_GRAIN = 0.1; +GameLib.CustomCode.MAX_SPEED = 0.3; +GameLib.CustomCode.MIN_SPEED = GameLib.CustomCode.SPEED_INITIAL; + +GameLib.CustomCode.ANIMATION_SPEED_GRAIN = 0.2; +GameLib.CustomCode.MIN_ANIMATION_SPEED = 2; +GameLib.CustomCode.MAX_ANIMATION_SPEED = 10; + GameLib.CustomCode.FOOD_BACON = 0; GameLib.CustomCode.FOOD_CHEESE = 1; GameLib.CustomCode.FOOD_ONION = 2; @@ -530,7 +538,7 @@ GameLib.CustomCode.prototype.getFreeGridPosition = function() { if (positions.length === 0) { return null; } - + var index = GameLib.Utils.GetRandomInt(0, positions.length); return positions[index]; @@ -774,7 +782,7 @@ GameLib.CustomCode.prototype.createPowerup = function(delta) { } var position = this.getFreeGridPosition(); - + if (position === null) { this.gameOver(true); } else { @@ -784,7 +792,7 @@ GameLib.CustomCode.prototype.createPowerup = function(delta) { null, position ); - + } }.bind(this); @@ -1146,7 +1154,7 @@ GameLib.CustomCode.prototype.extend = function(gameObject, position, orientation if (this.snake.length === GameLib.CustomCode.GRID_WIDTH * GameLib.CustomCode.GRID_HEIGHT) { this.gameOver(true); } - + }.bind(this); /** @@ -1154,7 +1162,52 @@ GameLib.CustomCode.prototype.extend = function(gameObject, position, orientation * @param gameObject */ GameLib.CustomCode.prototype.powerup = function(gameObject) { - console.log('powerup'); + + if (gameObject.objectType !== GameLib.CustomCode.OBJECT_TYPE_POWERUP) { + throw new Error('wrong type of game object'); + } + + if (gameObject.type === GameLib.CustomCode.POWERUP_LIFE) { + + this.lives += 1; + + if (this.lives > 3) { + this.lives = 3; + } + + } + + if (gameObject.type === GameLib.CustomCode.POWERUP_SPEED) { + + this.speed -= GameLib.CustomCode.SPEED_GRAIN; + + if (this.speed < GameLib.CustomCode.MAX_SPEED) { + this.speed = GameLib.CustomCode.MAX_SPEED; + } + + this.animation.translationSpeed += GameLib.CustomCode.ANIMATION_SPEED_GRAIN; + + if (this.animation.translationSpeed > GameLib.CustomCode.MAX_ANIMATION_SPEED) { + this.animation.translationSpeed = GameLib.CustomCode.MAX_ANIMATION_SPEED; + } + + } + + if (gameObject.type === GameLib.CustomCode.POWERUP_SLOW) { + + this.speed += GameLib.CustomCode.SPEED_GRAIN; + + if (this.speed > GameLib.CustomCode.MIN_SPEED) { + this.speed = GameLib.CustomCode.MIN_SPEED; + } + + this.animation.translationSpeed -= GameLib.CustomCode.ANIMATION_SPEED_GRAIN; + + if (this.animation.translationSpeed < GameLib.CustomCode.MIN_ANIMATION_SPEED) { + this.animation.translationSpeed = GameLib.CustomCode.MIN_ANIMATION_SPEED; + } + + } this.powerups.splice( this.powerups.indexOf(gameObject),