Skip to content

Commit

Permalink
[Linesh][#23] Refactor: pull render() method up to base Movable class
Browse files Browse the repository at this point in the history
  • Loading branch information
EthanLin-TWer committed Mar 19, 2017
1 parent 11bc557 commit eaeafd4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
5 changes: 0 additions & 5 deletions js/Enemy.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import Resources from './resources'
import { Movable } from './Movable'
import { Game, Speed } from './constants'

Expand All @@ -15,10 +14,6 @@ export class Enemy extends Movable {
}
}

render() {
ctx.drawImage(Resources.get(this.sprite), this.x, this.y)
}

checkCollision(player) {
if (player.y !== this.y) return false

Expand Down
6 changes: 6 additions & 0 deletions js/Movable.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import Resources from './resources'

export class Movable {
constructor(x, y, sprite) {
this.x = x
this.y = y
this.sprite = sprite
}

render() {
ctx.drawImage(Resources.get(this.sprite), this.x, this.y)
}
}
4 changes: 0 additions & 4 deletions js/Player.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ export class Player extends Movable {
return this.y === Game.row(0)
}

render() {
ctx.drawImage(Resources.get(this.sprite), this.x, this.y)
}

handleInput(movement) {
switch (movement) {
case 'left':
Expand Down

0 comments on commit eaeafd4

Please sign in to comment.