Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Don't move in the opposite direction

  • Loading branch information...
commit befae4a86c723a5f87a7e03af6fc71d752d79e56 1 parent ebb1ee9
@oscardelben authored
Showing with 16 additions and 8 deletions.
  1. +16 −8 Snake4iPhone/SnakeLayer.m
View
24 Snake4iPhone/SnakeLayer.m
@@ -305,11 +305,13 @@ - (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
@@ -317,11 +319,13 @@ - (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 = kMoveLeft;
+ if (self.direction != kMoveRight)
+ self.direction = kMoveLeft;
}
}
} else
@@ -331,11 +335,13 @@ - (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
@@ -343,11 +349,13 @@ - (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 = kMoveLeft;
+ if (self.direction != kMoveRight)
+ self.direction = kMoveLeft;
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.