1 / 16

Game Rules Implementation

Game Rules Implementation. Lecture 5. Revisit . 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

dotty
Download Presentation

Game Rules Implementation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Game Rules Implementation Lecture 5

  2. Revisit • 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. Overview of Lab 5 INPUT PROCESS OUTPUT Part 3 Part 1 Part 2 Collision Detection Game End Condition Tutorial 5

  4. Missing Parts of the Game • 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 • 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 Radius of Balloon Distance between userImage and balloon Radius of user Image Collide Not Collide

  7. Part 1: Whether Balloons Collide with UserImage Algorithm • 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 • 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 Index 0 1 2 3 4 Index Traverse 0 Original Target Array 1 2 0 Original Index 1 3 4 3 0 1 New Index 2 3 New Target Array Not considered

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

  10. Part 2: Whether the balloons collide with the bullets Algorithm I • 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 • 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 • 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 • 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 = [[UIAlertViewalloc] initWithTitle:@”Game Ended”messages:@”Times Up !!! Please try again” delegate:selfcancelButtonTitle:@”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

  15. Part ∞: Challenges • 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

More Related