Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit 20225fccbdd9131c19af6285f09e0a06afb0cdf5 2 parents 7a2d14b + f039a81
@robhawkes robhawkes authored
View
4 data/level.txt
@@ -1,7 +1,7 @@
*****************
-*1 4*
-* *
+*1 * 4*
* *
+** *
* *
* *
* *
View
BIN  public/images/clear4way.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
30 public/js/game/kaboom.game.js
@@ -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);
- }
}
});
}
Please sign in to comment.
Something went wrong with that request. Please try again.