Skip to content

Instantly share code, notes, and snippets.

@writingdeveloper
Created November 20, 2017 07:03
Show Gist options
  • Save writingdeveloper/de4fe65fe67b3187cd43020bdb6c640f to your computer and use it in GitHub Desktop.
Save writingdeveloper/de4fe65fe67b3187cd43020bdb6c640f to your computer and use it in GitHub Desktop.
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);
};
// Update the enemy's position, required method for game
// Parameter: dt, a time delta between ticks
Enemy.prototype.update = function(dt) {
// You should multiply any movement by the dt parameter
// which will ensure the game runs at the same speed for
// all computers.
this.x += this.speed * dt;
// 505 defines the width of the Canvas.
// The code that initializes the left end again when the enemy is struck at the right end.
if (this.x >= 505) {
this.x = 0;
}
checkCollision(this);
};
// * Draw the enemy on the screen, required method for game
Enemy.prototype.render = function() {
ctx.drawImage(Resources.get(this.sprite), this.x, this.y);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment