We now have a game that contains objects, and their movements have been set, but nothing will happen when the objects collide with one another. This would obviously limit any type of fun we would have with this game. To set this up, we are going to need to open the Event Editor. There are several ways to open the editor. First, you can click on its icon (see Figure 9.19). You can also open the Event Editor from the View menu. Lastly, you can use the shortcut combination of Ctrl+E to open it. Whichever method you prefer is fine.
Figure 9.19: The icon is one way to open the editor.
Once the window is open, double-click New Condition, which displays the New Condition window (see Figure 9.20).
Figure 9.20: The New Condition window.
Double-click the ball icon in the window. This will display the pop-up menu displayed in Figure 9.21. We are setting up the collision that will occur between the brick and the ball, so we need to choose Collisions, Another Object. This will open the Test a collision window seen in Figure 9.22. Choose Brick from the available objects and then click OK. Your Event Editor is now updated with this collision (see Figure 9.23).
Figure 9.21: The pop-up menu as displayed.
Figure 9.22: The test a collision window.
Figure 9.23: The event has been created.
Now we have a collision event that will be executed every time a ball and a brick collide. When the objects collide during the game, the Event Editor will cause an action to occur, but we have yet to create the exact action we would like to have. At this time, we are going to right-click on the square beneath the column in which the brick is displayed (see Figure 9.24). You can choose Destroy from the pop-up menu. A check mark is now visible in the Event Editor at the intersection point of the action and the brick column, like the one seen in Figure 9.25.
Figure 9.24: The brick column.
Figure 9.25: A check mark is now visible.
Now the brick is going to be destroyed when a ball collides with it, but if the ball collides with the bat, it will simply continue through it. We need to make it bounce during such a collision. We can create the event the same way we did for the brick and ball, but this time, we need to substitute the bat (see Figure 9.26).
Figure 9.26: The brick is replaced by the bat in this event.
We have the event, and now need to create the action. As already mentioned, we would like the ball to bounce with this collision, so we don’t want either the ball or the bat to be destroyed with this collision. Right-click the square beneath the ball and then choose Movement, Bounce (see Figure 9.27).
Figure 9.27: The ball will now bounce.
We now have the ball moving and colliding with the objects on the screen, but if the ball reaches any of the screen borders, it will continue to move into empty space. We will create an event to handle this as well. First, double-click New Condition and then double-click Ball. Choose Position, Test position of “Ball 1,” which can be seen in Figure 9.28. The Test position of “Ball 1” window is displayed (see Figure 9.29). Click on the arrows inside the square for left, right, and up but not down and click OK. The reason for this is simple. If the ball tries to leave in the left, right, or up direction, we need to have the ball bounce. If it leaves the bottom, we need an entirely different approach. The new entry in the Event Editor is seen as the ball leaves the play area on the top, left, or right (see Figure 9.30). Right-click the column beneath the ball and choose Movement, Bounce.
Figure 9.28: The pop-up menu has many options.
Figure 9.29: Test position of “Ball 1”window.
Figure 9.30: The new entry in the Event Editor.
The last event in this chapter again deals with the ball and testing its position, but this time, we need to create the event with the ball leaving the bottom position. After we create the event, right-click on the chessboard square and choose End the Application. Save the game and then choose Play to try out the application. Depending on your screen resolution, you may not see much of the action. Instead, choose Run, Application or hit F8 to see the running game (see Figure 9.31). Because this is a demo version, you may also see a notice such as that in Figure 9.32. If you get this window, click Continue to display the game.
Figure 9.31: The game is running.
Figure 9.32: Because we are using a demo version, you may see this screen.