Skip to content

Commit

Permalink
[Linesh][#19] Feature: reset player when collision happens
Browse files Browse the repository at this point in the history
  • Loading branch information
EthanLin-TWer committed Mar 19, 2017
1 parent ef6fe59 commit 27c14ec
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
3 changes: 0 additions & 3 deletions js/Player.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,3 @@ export class Player {
return this
}
}


export let player = new Player(202, 83 * 3 + 55)
15 changes: 12 additions & 3 deletions js/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
*/

import Resources from './resources'
import { Game } from './constants'
import { allEnemies } from './Enemy'
import { player } from './Player'
import { Player } from './Player'

var Engine = (function (global) {
/* Predefine the variables we'll be using within this scope,
Expand All @@ -28,6 +29,7 @@ var Engine = (function (global) {
canvas = doc.createElement('canvas'),
ctx = canvas.getContext('2d'),
lastTime;
let player;

canvas.width = 505;
canvas.height = 606;
Expand Down Expand Up @@ -84,7 +86,14 @@ var Engine = (function (global) {
*/
function update(dt) {
updateEntities(dt);
// checkCollisions();
checkCollisions();
}

function checkCollisions() {
let collides = allEnemies.some(enemy => enemy.checkCollision(player))
if (collides) {
player = new Player(Game.col(3), Game.row(5))
}
}

/* This is called by the update function and loops through all of the
Expand Down Expand Up @@ -163,7 +172,7 @@ var Engine = (function (global) {
* those sorts of things. It's only called once by the init() method.
*/
function reset() {
// noop
player = new Player(Game.col(3), Game.row(5))
}

/* Go ahead and load all of the images we know we're going to need to
Expand Down

0 comments on commit 27c14ec

Please sign in to comment.