Permalink
Browse files

Merge branch 'master' of https://github.com/dylanbeattie/KaboomJS

  • Loading branch information...
2 parents 7a2d14b + f039a81 commit 20225fccbdd9131c19af6285f09e0a06afb0cdf5 @robhawkes robhawkes committed Jun 4, 2011
Showing with 24 additions and 10 deletions.
  1. +2 −2 data/level.txt
  2. BIN public/images/clear4way.png
  3. +22 −8 public/js/game/kaboom.game.js
View
@@ -1,7 +1,7 @@
*****************
-*1 4*
-* *
+*1 * 4*
* *
+** *
* *
* *
* *
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -92,19 +92,33 @@ KaboomGame.prototype = {
{
if (p != null)
{
+ /* hacky "looks right for the image we've got values */
+ var width = 43;
+ var height = 38;
+
var newPos = new Position(
p.position.x + game.DISTANCE * p.velocity.dx,
p.position.y + game.DISTANCE * p.velocity.dy);
- var tilePos = game.pixelsToTiles(newPos);
- var tile = game.level.rows[tilePos.y][tilePos.x];
+
+ function goodPos(position)
+ {
+ var tilePos = game.pixelsToTiles(position);
+ var tile = game.level.rows[tilePos.y][tilePos.x];
+
+ try {
+ if (!tile.solid)
+ return true;
+ }
+ catch (ex) {
+ console.log(tilePos);
+ return false;
+ }
+ }
- try {
- if (!tile.solid)
+ var rightPos = new Position(newPos.x + width, newPos.y);
+ var downPos = new Position(newPos.x, newPos.y + height);
+ if (goodPos(newPos) && goodPos(rightPos) && goodPos(downPos))
p.position = newPos;
- }
- catch (ex) {
- console.log(tilePos);
- }
}
});
}

0 comments on commit 20225fc

Please sign in to comment.