Game Development Reference
In-Depth Information
Listing 4-28. CoinsController.m (doEndGame)
-(void)doEndGame{
[delegate gameOver:self with: coinsGame];
}
The animations created earlier in Listing 4-27 will call the task animationDidStop:finished: when
they are done, in the same way the scaling animations did. We use this callback to randomize the
matches and call updateCoinViews , shown in Listing 4-29.
Listing 4-29. CoinsController.m (updateCoinViews)
-(void)updateCoinViews{
int rowCount = [coinsGame rowCount];
int colCount = [coinsGame colCount];
for (NSNumber* row in matchingRows){
for (int c = 0;c<colCount;c++){
Coord coord = CoordMake([row intValue], c);
[self spinCoinAt:coord];
}
}
for (NSNumber* col in matchingCols){
for (int r = 0;r<rowCount;r++){
Coord coord = CoordMake(r, [col intValue]);
[self spinCoinAt:coord];
}
}
[self checkMatches];
}
The task updateCoinView is called when the UIImageViews that represent the coins are fully offscreen.
This task goes though each set of rows and columns from the previously matched sets and starts the
coins spinning again in their original locations, but with images that match the new values. Finally,
checkMatches is called again, to handle any cases of the new random values creating
new matches.
Summary
In this chapter, we explored how to create an input-driven game. This included understanding the
management of a game state, the basics of user input, and the use of core animation to create
animations. Game state is managed by creating a class to hold the data required to re-create
the game in a display-agnostic way. To allow the user to interact with the game, basic gesture
recognizers must be added to the correct views. A controller class interprets each user gesture in a
game-specific context and produces animations that reflect a change in the game state.
 
Search WWH ::




Custom Search