We now turn our attention to the way we move the snake. Since we want as much of the snake's control inside the snake object, we will be generating our own
move
method, instead of using setPosition
.
#define gridSize 22
In the SNDefinitions.h
file we have created a gridSize
definition that works well with the graphics we have defined for this project. Having a centralized gridSize
definition allows us to alter the dimensions of the playfield in one place. With that definition fresh in our minds, let's look at the move
method.
-(void) move { CGPoint moveByCoords; // Based on the direction, set the coordinate change switch (self.snakeDirection) { case kUp: moveByCoords = ccp(0,gridSize); break; case kLeft: moveByCoords = ccp(-gridSize,0); break; case kDown: moveByCoords = ccp(0,-gridSize); break; case kRight: ...