Professional Documents
Culture Documents
Responding to Events
Estimated time to complete this lesson: 1 hour
Responding to Events
In this lesson, you will learn how to:
Create interactive games that respond to events.
You have also learned how to use controls and keyboard and mouse events to include interactivity in your Small Basic program.
And you also know that you can use these shapes, controls, and events collectively to create interactive games in Small Basic.
The game demonstrates how to work with colors and use the properties of Turtle and GraphicsWindow to draw different shapes.
Notice how you use the Turtle object to draw shapes and how you use mouse and keyboard events to choose the color and the number of sides.
Steps to play the game: First, you must select a color from the color palette. Next, you define what shape the Turtle should draw by specifying the number of sides.
To create this game, you use the GraphicsWindow to create a user interface. You use the Controls object to add a button and a text box and set the size for the control buttons. You use the Shapes object to add different shapes. Then, you use the Shapes object to show, move, and hide shapes. You also use the Turtle object and set its angle, speed, and position. You use different conditions for different actions.
The objective of the game is to keep the ball afloat as long as possible.
Notice how we use mouse events to keep the ball from touching the ground. The ball responds to mouse clicks and stays afloat.
To develop this game, you create the user interface by using the GraphicsWindow object. You use the Controls object to define the mouse event that will be used to balance the ball. You use the Shapes object to add the image of the ball. You also use conditional statements to define the action to be performed when a particular mouse event occurs.
Lets Summarize