Presentation is loading. Please wait.

Presentation is loading. Please wait.

Game Rules Implementation Lecture 5 1. Revisit 2  Lab 4 – Other Input Methods  Touches Basics  Relationship between TouchesBegan, TouchesMoved, and.

Similar presentations


Presentation on theme: "Game Rules Implementation Lecture 5 1. Revisit 2  Lab 4 – Other Input Methods  Touches Basics  Relationship between TouchesBegan, TouchesMoved, and."— Presentation transcript:

1 Game Rules Implementation Lecture 5 1

2 Revisit 2  Lab 4 – Other Input Methods  Touches Basics  Relationship between TouchesBegan, TouchesMoved, and TouchesEnded  Getting Touch Point on screen  Handling MultiTaps and MultiTouches  Touches Actions and Gestures  Dragging on UserImage  Moving to change orientation of the userImage  Tilting Devices  Accelerometer Reading Basics  Tilting devices to move the userImage

3 Tutorial 5 Overview of Lab 5 3 INPUT PROCESSOUTPUT Collision Detection Game End Condition Part 1 Part 2 Part 3

4 Missing Parts of the Game 4  Collision Detection  This is necessary to detect whether various animating images collide with each other, so as to determine scores and allow the game to progress  Part 1: Whether the balloons collide with the userImage  Part 2: Whether the balloons collide with the bullets  Game End Condition  This is necessary to determine when the game should end

5 Common Collision Technique I 5  Each image object is treated as a circle with a radius on the screen  The radius can be approximated by width/2 or height/2  If the sum of the radius of two objects is less than the distance between their center positions  Then, the two objects are considered to be collided.  To simplify your work, you can add the following method to the view controller to check whether two objects collide  -(bool) collide : (float) x1 : (float) y1 : (float) r1 : (float) x2 : (float) y2 : (float) r2 {  float centerDistance = sqrt(pow((x1-x2),2) + pow((y1-y2),2));  return (centerDistance < (r1 + r2));  }

6 Collision Detection Technique II 6 Radius of Balloon Distance between userImage and balloon Radius of user Image Not Collide Collide

7 Part 1: Whether Balloons Collide with UserImage Algorithm 7  For each target balloon, check whether it collides with userImage  If yes,  Remove it from targetDataArray and targetImageArray  Generate enough targets so that the total number of targets is still DEFAULT_TARGET_NUM_ON_SCREEN

8 Issue on Forward Traversing the Targets Data or Image Array 8  Maybe we can consider the following situation:  We have a target data Array of 5 elements  If target collides with the userImage  The corresponding target is removed from the array Original Index0 1 234 Original Target Array Original Index 0 1 34 New Target Array New Index 0 1 23 0 Index Traverse 2 1 3 Not considered

9 Backward Traverse 9  Again, the conditions are the same as before, but we traverse the array from backward direction 9 1 234 Original Target Array Original Index 0 1 34 New Target Array New Index 0 1 23 4 Index Traverse 2 3 1 Considered

10 Part 2: Whether the balloons collide with the bullets Algorithm I 10  For each bullet,  For each target, check whether it collides with the target  If yes,  Check if it is the current target  If yes,  Update targetsLeft and targetsShot  Update current target and next target  Remove the bullet and balloon  Generate a new balloon

11 Part 2: Whether the balloons collide with the bullets Algorithm II 11  Basically, the algorithm here is very similar to that of Part 1  Except  Need to consider the traverse on two arrays  Need to update the scores shown on the screen  Need to update the current target window and next target window  Does forward traverse issue occur in this case? Why?  How can we solve it?

12 Part 3 – Game End Conditions 12  When you first design the game, you must have designed the game objective  In this game, our objective is to shoot a certain amount of targets shown on the current target window within a certain time limit  We can see from the objective that  Winning Condition – Shoot a certain amount of targets before time end  Losing Condition – time up  When the game end, we should  Stop the timer and reset the accelerometer  Display a message to show whether you win or lose

13 Display a Pop up window 13  In iPhone, you can display a pop up window to alert the user with some special event.  This is known as UIAlertView  // First of all, we have to initiate an UIAlertView object with the associated title and message.  // Here, we also set it to show one button only  UIAlertView * av = [[UIAlertView alloc] initWithTitle:@”Game Ended” messages:@”Times Up !!! Please try again” delegate:self cancelButtonTitle:@”Finish” otherButtonTitles:nil, nil, ni];  // The alertView is pop up  [av show];  // Since it has already been pop up, we can release the memory used to hold the alert view  [av release];

14 Display when game ended 14

15 Part ∞: Challenges 15  Introduce sound effects, such as, balloon “pops” when hit by a bullet  Note that two sound files are provided  Different difficulty levels  Keeping best score  Multiplayer game, etc.  Other interesting game rules?

16 Q & A 16


Download ppt "Game Rules Implementation Lecture 5 1. Revisit 2  Lab 4 – Other Input Methods  Touches Basics  Relationship between TouchesBegan, TouchesMoved, and."

Similar presentations


Ads by Google