Skip to content

Instantly share code, notes, and snippets.

@RichardMarks
Created January 15, 2011 12:30
Show Gist options
  • Save RichardMarks/780878 to your computer and use it in GitHub Desktop.
Save RichardMarks/780878 to your computer and use it in GitHub Desktop.
changes for warpin project
// Add to MapEntity.as - this is not the full MapEntity.as file.
/**
* checks if there is a warp that collides with the specified entity
* @param e - the entity to test collision against
* @return null if no warp is found, and the WarpPoint object if there is one
*/
public function CheckWarpCollidesWith(e:Entity):WarpPoint
{
// loop through each warp in the warps container
for each(var w:WarpPoint in warps)
{
// if the entity hitbox collides with the warp
if (e.collidePoint(e.x, e.y, w.Position.x, w.Position.y))
{
// return the warp object
return w;
}
}
// we didn't find any warps in this position, so we return null
return null;
}
// Add to Player.as - this is not the full Player.as file.
private function HandleWarps():void
{
var e:Entity = collide("warpdir", x, y);
if (e)
{
trace("collided with a WarpDirection instance at pixel coordinate:", x, ",", y);
var warp:WarpPoint = Global.location.CheckWarpCollidesWith(e);
if (warp)
{
// perform the warp
trace("found WarpPoint, warping.");
warp.Go();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment