This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Display Score | |
var displayScoreLevel = function(aScore, aLevel) { | |
var canvas = document.getElementsByTagName('canvas'); | |
var firstCanvasTag = canvas[0]; | |
scoreLevelDiv.innerHTML = 'Score : ' + aScore + ' / ' + 'Level : ' + aLevel; | |
document.body.insertBefore(scoreLevelDiv, firstCanvasTag[0]); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// KeyPress Settings | |
Player.prototype.handleInput = function(keyPress) { | |
if (keyPress == 'left') { | |
player.x -= player.speed; | |
} | |
if (keyPress == 'up') { | |
player.y -= player.speed - 20; | |
} | |
if (keyPress == 'right') { | |
player.x += player.speed; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Definition Player | |
var Player = function(x, y, speed) { | |
this.x = x; | |
this.y = y; | |
this.speed = speed; | |
this.sprite = 'images/char-boy.png'; | |
}; | |
Player.prototype.update = function() {} | |
Player.prototype.render = function() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Enemy_Rock.prototype.update = function(dt) { | |
this.x += this.speed * dt; | |
if (this.x >= 505) { | |
this.x = 0; | |
} | |
checkCollision(this); | |
}; | |
Enemy_Rock.prototype.render = function() { | |
ctx.drawImage(Resources.get(this.sprite), this.x, this.y); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Enemies our player must avoid | |
var Enemy = function(x, y, speed) { | |
this.x = x; | |
this.y = y; | |
this.speed = speed; | |
// The sprite continuously crops and displays the image. | |
this.sprite = 'images/enemy-bug.png'; | |
}; | |
var Enemy_Rock = function(x, y, speed) { |
NewerOlder