Skip to content

Commit

Permalink
Lazers now disappear when they hit things, added enemies back in.
Browse files Browse the repository at this point in the history
  • Loading branch information
anotheredward committed Jun 5, 2013
1 parent ffaad50 commit 7bbb6af
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions spacerogue.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ var map_data = [

",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,",
",################################, ",
",#@......#..............#.......#, ",
",#@......#....g.........#.......#, ",
",#.......#.......#......#.......#,,,,,,",
",#....####.......#..............######,",
",#....####.......#..g...........######,",
",#....#..........#......#............#,",
",#...............#......#............#,",
",#....#....#######......########.....#,",
Expand All @@ -17,11 +17,11 @@ var map_data = [
" ,#...#, ,#...#,",
" ,#...#,,,,,,,,,,,,#...#,",
" ,#...#.############...#,",
" ,#....................#,",
" ,#....g...............#,",
" ,######################,",
" ,,,,,,,,,,,,,,,,,,,,, ,,,,,,,,,,,,,,,,,,,,,,,,",
" ,#############.#####, ",
" ,#.................#,",
" ,#.....g...........#,",
" ,#.................#,",
" ,###################,",
" ,,,,,,,,,,,,,,,,,,,,,",
Expand Down Expand Up @@ -119,16 +119,22 @@ var Game = (function () {
if (!map[y][x].walkable)
return false;

if (getEntityAtPosition(x, y) != null)
return false;

return true;
};

var getEntityAtPosition = function(x, y) {
for (var key in entities) {
if (entities.hasOwnProperty(key)) {

This comment has been minimized.

Copy link
@Qu4Z

Qu4Z Jun 6, 2013

Owner

I know I wrote this line, but it's time we used _.js. I've made an issue for it: #2

var ch = entities[key];
if (ch.x() == x && ch.y() == y)
return false;
var entity = entities[key];
if (entity.x() == x && entity.y() == y)
return entity;
}
}

return true;
};
return null;
}

var makeEntity = (function (x, y, ch, col) {
var last_dir = { x: 1, y: 0 };
Expand Down Expand Up @@ -227,7 +233,13 @@ var Game = (function () {
base.last_dir = dir;

base.act = function() {
base.move(base.last_dir);
if(!base.move(base.last_dir)){
for(var i=0; i < entities.length; i++) {
if (entities[i].x == base.x && entities[i].y == base.y)
entities.splice(i,1);

This comment has been minimized.

Copy link
@Qu4Z

Qu4Z Jun 6, 2013

Owner

What happens if it hits the player? (Technically not possible atm, but as soon as we add deflection or anything...)
I feel like we should do more than just remove the entity from the entity list. At very least because it's still in the scheduler.
Maybe if (entity.onLasered) entity.onLasered(); or something

}
scheduler.remove(base);
}
};

return base;
Expand Down

0 comments on commit 7bbb6af

Please sign in to comment.