Download iPhone Game Development
Transcript
3,3,3,3,3,3,3,3,3,3,3,3
3,3,3,3,3,3,3,3,3,3,3,3
3,3,3,3,3,3,3,3,3,3,3,3
3,3,3,3,3,3,3,3,3,3,3,3
3,3,3,3,3,3,3,3,3,3,3,3
3,3,3,3,3,3,3,3,3,3,3,3
0,0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0,0,0
3,3,3,3,3,3,3,3,3,3,3,3
3,3,3,3,3,3,3,3,3,3,3,3
3,3,3,3,3,3,3,3,3,3,3,3
3,3,3,3,3,3,3,3,3,3,3,3
0,0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0,0,0
In this level, we use the physics flag 3 to represent water tiles.
Crocodiles
The crocodile includes three frames of swimming, three frames of beginning the attack,
and six frames of jumping out of the water to snap at the player’s character. This is
unrealistic behavior for a crocodile, but at the risk of misrepresenting nature, it gives
the player an exciting explanation for why she just lost.
The definition of the Croc class includes an integer that tracks the direction of the
crocodile (it flips between 1 and –1 as the crocodile turns around at the edge of the
level) and a CGRect representing the bounds of the croc that the player must avoid:
@interface Croc : Entity {
int direction; //-1 or 1, for pacing back and forth across the level.
CGRect bounds; //used for hit detection on jumping player.
}
- (bool) under:(CGPoint)point;
- (void) attack:(Entity*) other;
@end
The interesting functions in the Croc class include under:, attack:, and update:. The
under: function will return true if the given point collides with the crocodile’s bounds
(offset by its current position):
- (bool) under:(CGPoint)point {
if(
point.x > self.position.x
point.x < self.position.x
point.y > self.position.y
point.y < self.position.y
) return true;
return false;
}
+
+
+
+
bounds.origin.x
bounds.origin.x
bounds.origin.y
bounds.origin.y
&&
+ bounds.size.width &&
&&
+ bounds.size.height
Level 4 Implementation | 167