Skip to content

Commit

Permalink
[Linesh][#22] Feature: enemy should be able to cross the screen
Browse files Browse the repository at this point in the history
  • Loading branch information
EthanLin-TWer committed Mar 19, 2017
1 parent 74274e6 commit cad5fb1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 3 additions & 0 deletions js/Enemy.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ export class Enemy {

update(dt) {
this.x += dt * this.speed
if (this.x > Game.col(6)) {
this.x -= Game.col(6)
}
}

render() {
Expand Down
11 changes: 10 additions & 1 deletion test/unit/enemy.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Player } from '../../js/Player'

describe('enemy', () => {

describe('move functionality', () => {
describe('move functionalities', () => {
it('should be able to move', () => {
let enemy = new Enemy(Game.col(1), Game.row(2), Speed.NORMAL)
enemy.update(1)
Expand All @@ -27,6 +27,15 @@ describe('enemy', () => {

expect(enemy.speed).to.equal(Speed.VERY_SLOW)
})

it('should cross the screen when disappear in the right boundary', () => {
let enemy = new Enemy(Game.col(5), Game.row(2), Speed.NORMAL)

enemy.update(1)

expect(enemy.speed).to.equal(400)
expect(enemy.x).to.equal(Math.abs(Game.col(6) - Game.col(5) - 400))
})
})

describe('collision detection', () => {
Expand Down

0 comments on commit cad5fb1

Please sign in to comment.