collinhover / impactplusplus

Impact++ is a collection of additions to ImpactJS with full featured physics, dynamic lighting, UI, abilities, and more.
http://collinhover.github.com/impactplusplus
MIT License
276 stars 59 forks source link

ig.game.isInsideLevel always returns false if "level" is one of the shapesPasses #122

Closed jeremyfry closed 10 years ago

jeremyfry commented 10 years ago

To reproduce: Remove the shapesPasses asignment from main.js in supercollider. Now attempt to fire a projectile, in ability-shoot ig.game.isInsideLevel(x,y) will always return false and cause no projectile to be created.

I tried setting up a bunch of different collision maps to figure out why this was happening but could never be considered "inside the level". I then noticed in both examples shapesPasses is defined and a levels property is omitted. When building applying properties to the node in pathfinding.js line 482 is always false so inside level never gets set to false.

Not sure if this is a misunderstanding of how to build levels or an actual bug. Thanks!

collinhover commented 10 years ago

The isInsideLevel method is honestly a bit unstable. If your level has a collision map that doesn't form a shape that wraps around the entire level, this check will always fail. The reason being, this does a point in polygon test based on the collision shapes extracted. If your collision map has a gap in it, for example the second level of the SUPERCOLLIDER, it will always think it is outside the level.

Another example is to consider a square room with collision tiles all around it. In this case, the test will be correct. If you added a pit with no collision bottom, the test will fail, and if you gave the pit a bottom, the test should work again.

That said, if there are no shapes extracted from the map, the test should always pass. Can you confirm that this is not the case?

jeremyfry commented 10 years ago

Looks like that corrected it. It looks like I had a one way tile at one point along the perimeter of my collision map. That apparently counts as a gap where as the slopes don't. Changing that tile to a solid collision tile fixed the issue.

collinhover commented 10 years ago

Ah, interesting. I believe the reason I set it that way is because I'm assuming only solid tiles, whether square or sloped, would make a solid shape. One way tiles are a special case that could be either a gap or a wall, and to be safe I always treat it as a gap.