Skip to content

Instantly share code, notes, and snippets.

View writingdeveloper's full-sized avatar
🏠
Working from home

Si Hyeong Lee writingdeveloper

🏠
Working from home
View GitHub Profile
// 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]);
};
// 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;
// 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() {
@writingdeveloper
writingdeveloper / app.js
Created November 20, 2017 07:03
Udacity Project
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);
@writingdeveloper
writingdeveloper / app.js
Created November 20, 2017 06:54
app.js
// 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) {