Microsoft® Small Basic<br />Collision Detection<br />Estimated time to complete this lesson: 1 hour<br />
Collision Detection<br />In this lesson, you will learn about:<br />Using the concept of collision detection in games. <br />
What is Collision Detection?<br />Now let’s talk about collision detection in games.<br />In general, collision detection is about determining the intersection of two moving objects.<br />Collision detection in games takes place in the following steps:<br /><ul><li> Selecting two objects to be tested for collision.
Checking whether a collision occurred between the identified objects or not.</li></li></ul><li>How to Detect Collision?<br />Before we discuss how to detect collisions, you should consider what happens to two objects when they collide. <br />Collision detection is a basic aspect of two- and three-dimesional games. Algorithms help to detect the collision. Most games use posteriori collision detection—that is, they detect the collision after it has occurred.<br />One of the objects could destroy the other, one could move the other, or both of them might move from their previous positions.<br />
Hit the Target – The Game<br />You use the logic of collision detection to detect the collision between the turtle and the target. The game ends as soon as the two objects collide.<br />The game involves two objects: the turtle and the target. The player has to make the turtle hit the target by entering the correct angle and the distance.<br />Now that you have understood the concept of collision detection in games, let’s make a game that uses the logic of collision detection.<br />
Hit the Target – How to Play<br />It’s time to play the game!<br />Steps to play the game:<br /><ul><li>Enter the angle to set the direction that the turtle will move.
Enter the distance that the turtle needs to cover to hit the target.
Click the ‘Reset’ button to reset the position of the target.</li></li></ul><li>Hit the Target – The Code<br />Now let’s understand the code for the game in detail…<br /><ul><li>Use the GraphicsWindow object to create the user interface.
Next, use the Controls object to add a click button and text box and set the size of control buttons.
Use the Shapes object to add an image of the shape, and to move and animate the shape and set its opacity level.
Use the Turtle object and you can set its angle and moving distance by using the Math object.</li></li></ul><li>Let’s Summarize…<br />Congratulations! Now you know how to:<br />Use the concept of collision detection in games. <br />
It’s Time to Apply Your Learning…<br />Using the concept of collision detection, create a game that involves two objects: a bucket and apples. The apples fall randomly from the top of the screen. The player tries to catch the apples in the bucket. The game runs for 30 seconds. Include a score board to display the total number of apples caught by the player in 30 seconds. <br />Your game should look somewhat like the following.<br />