Skip to content

Commit

Permalink
Allow the arrows to pass over water
Browse files Browse the repository at this point in the history
  • Loading branch information
timotei committed Sep 17, 2011
1 parent 6ab745b commit b039df5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 10 additions & 5 deletions egp_story/LevelMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ public void Draw( SpriteBatch spriteBatch, GameTime gameTime )
/// Returns true if the rectangle's bounds are on valid position (walkable)
/// </summary>
/// <param name="rectangle">The rectangle to check the bounds for</param>
/// <param name="waterWalkable">Whether to consider water to be walkable (e.g., flying objects)</param>
/// <returns></returns>
public bool CheckRectangleBounds( Rectangle rectangle )
public bool CheckRectangleBounds( Rectangle rectangle, bool waterWalkable = false )
{
if ( !Mask.Bounds.Contains( rectangle ) )
return false;
Expand All @@ -100,19 +101,23 @@ public bool CheckRectangleBounds( Rectangle rectangle )
rectangle.Height--;
// upper left
Color texel = GetTexel( rectangle.Y, rectangle.X );
if ( texel == Color.White || texel == Color.Black ) {
if ( texel == Color.White || texel == Color.Black ||
( waterWalkable && texel == Color.Blue ) ) {

// upper right
texel = GetTexel( rectangle.Y, rectangle.Right );
if ( texel == Color.White || texel == Color.Black ) {
if ( texel == Color.White || texel == Color.Black ||
( waterWalkable && texel == Color.Blue ) ) {

// bottom right
texel = GetTexel( rectangle.Bottom, rectangle.Right );
if ( texel == Color.White || texel == Color.Black ) {
if ( texel == Color.White || texel == Color.Black ||
( waterWalkable && texel == Color.Blue ) ) {

// bottom left
texel = GetTexel( rectangle.Bottom, rectangle.X );
if ( texel == Color.White || texel == Color.Black ) {
if ( texel == Color.White || texel == Color.Black ||
( waterWalkable && texel == Color.Blue ) ) {
return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion egp_story/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public override void Update( LevelMap levelMap, GameTime gameTime )
// remove this
_projectilesShot.Dequeue( );
}
else if ( !levelMap.CheckRectangleBounds( projectileBox ) ) {
else if ( !levelMap.CheckRectangleBounds( projectileBox, true ) ) {
//TODO: add hit animation
_projectilesShot.Dequeue( );
}
Expand Down

0 comments on commit b039df5

Please sign in to comment.