Permalink
Browse files

Don't move in the opposite direction

  • Loading branch information...
1 parent ebb1ee9 commit befae4a86c723a5f87a7e03af6fc71d752d79e56 @oscardelben committed May 6, 2011
Showing with 16 additions and 8 deletions.
  1. +16 −8 Snake4iPhone/SnakeLayer.m
View
@@ -305,23 +305,27 @@ - (void)ccTouchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
if (normalizedLocation.y > normalizedLocation.x)
{
- self.direction = kMoveUp;
+ if (self.direction != kMoveDown)
+ self.direction = kMoveUp;
}
else
{
- self.direction = kMoveRight;
+ if (self.direction != kMoveLeft)
+ self.direction = kMoveRight;
}
} else
{
if (normalizedLocation.y > normalizedLocation.x)
{
- self.direction = kMoveUp;
+ if (self.direction != kMoveDown)
+ self.direction = kMoveUp;
}
else
{
- self.direction = kMoveLeft;
+ if (self.direction != kMoveRight)
+ self.direction = kMoveLeft;
}
}
} else
@@ -331,23 +335,27 @@ - (void)ccTouchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
if (normalizedLocation.y > normalizedLocation.x)
{
- self.direction = kMoveDown;
+ if (self.direction != kMoveUp)
+ self.direction = kMoveDown;
}
else
{
- self.direction = kMoveRight;
+ if (self.direction != kMoveLeft)
+ self.direction = kMoveRight;
}
} else
{
if (normalizedLocation.y > normalizedLocation.x)
{
- self.direction = kMoveDown;
+ if (self.direction != kMoveUp)
+ self.direction = kMoveDown;
}
else
{
- self.direction = kMoveLeft;
+ if (self.direction != kMoveRight)
+ self.direction = kMoveLeft;
}
}
}

0 comments on commit befae4a

Please sign in to comment.