SlideShare a Scribd company logo
Microsoft® Small BasicResponding to EventsEstimated time to complete this lesson: 1 hour
Responding to EventsIn this lesson, you will learn about:Creating interactive games in Small Basic that respond to events.
Fun with Shapes And you also know that you can use these shapes, controls, and events collectively to create interactive games in Small Basic. Let’s see how…So far, you have learned to insert and animate various shapes in your Small Basic programs.You have also learned to use controls and keyboard and mouse events to include interactivity in your Small Basic program.
Make the Turtle Draw – The GameIn this simple game, you tell the Turtle to draw unique shapes in the graphics window by defining the number of sides.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. The game demonstrates how the user can make the Turtle draw colorful, unique shapes by specifying a color and the number of sides.
Make the Turtle Draw – How to PlaySo how do you play this game?Steps to play the game:First, you need to select a color from the color palette.
Next, you specify the number of sides, so you can define what the Turtle should draw.
When you click Submit, the Turtle starts drawing.Make the Turtle Draw - CodeNow let’s understand the code for the game in detail…To create this game, you use the GraphicsWindowto 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.
Bounce the Ball – The GameLet’s move to a complex game now. In this game, you keep a ball above the ground by using the mouse to click the ball to keep it afloat. Notice how we use mouse events to keep the ball from touching the ground. The ball responds to mouse clicks and stays afloat.The objective of the game is to keep the ball afloat as long as possible.
Bounce the Ball – How to PlaySo how do you play this game?Steps to play the game:On the screen, a ball is dropped on the ground.
You click the ball to make it bounce up in the air.
You must keep the ball from touching the ground. To do so, keep clicking the ball.

More Related Content

PPT
Introduction to Scratch Programming
PPTX
4.1 playing with shapes
PPTX
4.3 collision detection
PPTX
4.4 advanced games
PPTX
2.3 exploring shapes
PPT
Scratch Lesson 2 – Paint Editor
PPT
Scratch for Data Logging and Graphing
PPT
An Intro to Scratch Programming for Parents
Introduction to Scratch Programming
4.1 playing with shapes
4.3 collision detection
4.4 advanced games
2.3 exploring shapes
Scratch Lesson 2 – Paint Editor
Scratch for Data Logging and Graphing
An Intro to Scratch Programming for Parents

What's hot (20)

PPTX
Computer Coding with Scratch: Lesson 2_primaryschoollessons
PPTX
2.2 turtle graphics
PPTX
3 Kodu
PDF
Scratch Animation
PPTX
Programming in scratch
PPT
Kodu
PPTX
2.1 graphics window
PDF
Coding Basics with Scratch
PDF
Intro to Dimension
PPTX
Interactive Project - Production Reflection
PPTX
Scratch programming introduction to game creation
PDF
Lasso tool
PPTX
Google sketch up
PPT
Scratch Lesson 1 – Basics
PPTX
learn sketchup (for the beginners)
PPTX
6. production reflection(2)
PPTX
Presentation q4
PDF
Sketchup modul
PPTX
Scratch an Editing App
PPTX
Scratch Programming
Computer Coding with Scratch: Lesson 2_primaryschoollessons
2.2 turtle graphics
3 Kodu
Scratch Animation
Programming in scratch
Kodu
2.1 graphics window
Coding Basics with Scratch
Intro to Dimension
Interactive Project - Production Reflection
Scratch programming introduction to game creation
Lasso tool
Google sketch up
Scratch Lesson 1 – Basics
learn sketchup (for the beginners)
6. production reflection(2)
Presentation q4
Sketchup modul
Scratch an Editing App
Scratch Programming
Ad

Similar to 4.2 responding to events (20)

DOC
6. pong
PPTX
Pong on SCRATCH Directions
PPTX
Pong on SCRATCH Directions
PPT
DigiGirlzSmallBasic
PPTX
Gamemaker lesson 1
PPTX
3.4 events and interactivity
PDF
DOC
Visual basic
PDF
Introducing small basic
PPT
Chapter 01: Intro to VB2010 Programming
PDF
Software engineering modeling lab lectures
PPT
LESSON 1- VISUAL BASIC PROGRAMMING.ppt
PDF
Ict project pdf
PPTX
UNIT I.pptx
PDF
Moreno Xec
PPTX
Object Oriented Programming I
PPTX
IGD-U01L01-Presentation Game develo.pptx
PPTX
GameMaker 1) intro to gamemaker
KEY
ARTDM 170, Week 7: Scripting Interactivity
PPTX
Lesson one presentation
6. pong
Pong on SCRATCH Directions
Pong on SCRATCH Directions
DigiGirlzSmallBasic
Gamemaker lesson 1
3.4 events and interactivity
Visual basic
Introducing small basic
Chapter 01: Intro to VB2010 Programming
Software engineering modeling lab lectures
LESSON 1- VISUAL BASIC PROGRAMMING.ppt
Ict project pdf
UNIT I.pptx
Moreno Xec
Object Oriented Programming I
IGD-U01L01-Presentation Game develo.pptx
GameMaker 1) intro to gamemaker
ARTDM 170, Week 7: Scripting Interactivity
Lesson one presentation
Ad

More from allenbailey (14)

PPTX
5.1 sharing code
PPTX
3.6 debugging aids
PPTX
3.5 the controls object
PPTX
3.3 the math object
PPTX
3.2 stacks and arrays
PPTX
3.1 file input and output
PPTX
2.6 flickr, image list, and network objects
PPTX
2.5 clock, desktop, and dictionary objects
PPTX
2.4 sound, program, and text objects
PPTX
1.5 branching and subroutines
PPTX
1.4 conditions and loops
PPTX
1.3 variables
PPTX
1.2 statements, properties, and operations
PPTX
1.1 introduction to small basic
5.1 sharing code
3.6 debugging aids
3.5 the controls object
3.3 the math object
3.2 stacks and arrays
3.1 file input and output
2.6 flickr, image list, and network objects
2.5 clock, desktop, and dictionary objects
2.4 sound, program, and text objects
1.5 branching and subroutines
1.4 conditions and loops
1.3 variables
1.2 statements, properties, and operations
1.1 introduction to small basic

Recently uploaded (20)

PPTX
Hacking Movie – Best Films on Cybercrime & Digital Intrigue
PDF
TAIPANQQ SITUS MUDAH MENANG DAN MUDAH MAXWIN SEGERA DAFTAR DI TAIPANQQ DAN RA...
PPTX
the-solar-system.pptxxxxxxxxxxxxxxxxxxxx
PPTX
shbthd htsh htrw hw htr 5w h5e 54 y.pptx
PPTX
PRECISION AGRICULTURE- 1.pptx for agriculture
PPTX
Other Dance Forms - G10 MAPEH Reporting.pptx
DOCX
Elisabeth de Pot, the Witch of Flanders .
PPT
business model and some other things that
PPTX
the Honda_ASIMO_Presentation_Updated.pptx
PDF
Keanu Reeves Beyond the Legendary Hollywood Movie Star.pdf
PDF
Rare Big Band Arrangers Who Revolutionized Big Band Music in USA.pdf
PPTX
What Makes an Entertainment App Addictive?
PPTX
providenetworksystemadministration.pptxhnnhgcbdjckk
PDF
How Old Radio Shows in the 1940s and 1950s Helped Ella Fitzgerald Grow.pdf
PDF
Rakshabandhan – Celebrating the Bond of Siblings - by Meenakshi Khakat
PPTX
SPARSH-SVNITs-Annual-Cultural-Fest presentation for orientation
PDF
EVs U-5 ONE SHOT Notes_c49f9e68-5eac-4201-bf86-b314ef5930ba.pdf
PDF
oppenheimer and the story of the atomic bomb
DOCX
Nina Volyanska Controversy in Fishtank Live_ Unraveling the Mystery Behind th...
PDF
Gess1025.pdfdadaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Hacking Movie – Best Films on Cybercrime & Digital Intrigue
TAIPANQQ SITUS MUDAH MENANG DAN MUDAH MAXWIN SEGERA DAFTAR DI TAIPANQQ DAN RA...
the-solar-system.pptxxxxxxxxxxxxxxxxxxxx
shbthd htsh htrw hw htr 5w h5e 54 y.pptx
PRECISION AGRICULTURE- 1.pptx for agriculture
Other Dance Forms - G10 MAPEH Reporting.pptx
Elisabeth de Pot, the Witch of Flanders .
business model and some other things that
the Honda_ASIMO_Presentation_Updated.pptx
Keanu Reeves Beyond the Legendary Hollywood Movie Star.pdf
Rare Big Band Arrangers Who Revolutionized Big Band Music in USA.pdf
What Makes an Entertainment App Addictive?
providenetworksystemadministration.pptxhnnhgcbdjckk
How Old Radio Shows in the 1940s and 1950s Helped Ella Fitzgerald Grow.pdf
Rakshabandhan – Celebrating the Bond of Siblings - by Meenakshi Khakat
SPARSH-SVNITs-Annual-Cultural-Fest presentation for orientation
EVs U-5 ONE SHOT Notes_c49f9e68-5eac-4201-bf86-b314ef5930ba.pdf
oppenheimer and the story of the atomic bomb
Nina Volyanska Controversy in Fishtank Live_ Unraveling the Mystery Behind th...
Gess1025.pdfdadaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

4.2 responding to events

  • 1. Microsoft® Small BasicResponding to EventsEstimated time to complete this lesson: 1 hour
  • 2. Responding to EventsIn this lesson, you will learn about:Creating interactive games in Small Basic that respond to events.
  • 3. Fun with Shapes And you also know that you can use these shapes, controls, and events collectively to create interactive games in Small Basic. Let’s see how…So far, you have learned to insert and animate various shapes in your Small Basic programs.You have also learned to use controls and keyboard and mouse events to include interactivity in your Small Basic program.
  • 4. Make the Turtle Draw – The GameIn this simple game, you tell the Turtle to draw unique shapes in the graphics window by defining the number of sides.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. The game demonstrates how the user can make the Turtle draw colorful, unique shapes by specifying a color and the number of sides.
  • 5. Make the Turtle Draw – How to PlaySo how do you play this game?Steps to play the game:First, you need to select a color from the color palette.
  • 6. Next, you specify the number of sides, so you can define what the Turtle should draw.
  • 7. When you click Submit, the Turtle starts drawing.Make the Turtle Draw - CodeNow let’s understand the code for the game in detail…To create this game, you use the GraphicsWindowto 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.
  • 8. Bounce the Ball – The GameLet’s move to a complex game now. In this game, you keep a ball above the ground by using the mouse to click the ball to keep it afloat. Notice how we use mouse events to keep the ball from touching the ground. The ball responds to mouse clicks and stays afloat.The objective of the game is to keep the ball afloat as long as possible.
  • 9. Bounce the Ball – How to PlaySo how do you play this game?Steps to play the game:On the screen, a ball is dropped on the ground.
  • 10. You click the ball to make it bounce up in the air.
  • 11. You must keep the ball from touching the ground. To do so, keep clicking the ball.
  • 12. The timer keeps track of how many seconds you keep the ball from touching the ground.Bounce the Ball – The CodeNow let’s understand the code for the game in detail…To develop this game, you use the GraphicsWindowobjectto create the user interface. 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 executed when a particular mouse event occurs.
  • 13. Let’s Summarize…Congratulations! Now you know how to:Create interactive games in Small Basic that respond to events.
  • 14. It’s Time to Apply Your Learning…Write a program to display a graphics window, and perform the following steps:Create two buttons: Label one button True, and label the other button False.
  • 15. Create a series of statements to be displayed on the screen.
  • 16. For any statement, the user will click True or False.
  • 17. The user scores points by guessing correctly.

Editor's Notes

  • #12: Solution:' Copyright (c) Microsoft Corporation. All rights reserved.GraphicsWindow.Hide()gw = 500gh = 350scoreBoxLeft = 200passedQuestion = 0score = 0Clicked = ""i = 1Q[1] = "Nile is the longest river in the world."Q[2] = "The highest mountain in the world is Mount Everest."Q[3] = "Zambia is also known as the 'Country of Copper'."Q[4] = "The coldest place on the earth is in Siberia."Q[5] = "Sydney is the capital of the USA."Q[6] = "The river Jordan flows out into the Dead sea."Q[7] = "Mumbai is the capital of India."Q[8] = "Africa is the largest coffee growing continent in the world."Q[9] = "The largest desert in the world is Sahara Desert."Q[10] = "London is the capital of the UK."A[1] = "True"A[2] = "True"A[3] = "True"A[4] = "True"A[5] = "False"A[6] = "True"A[7] = "False"A[8] = "False"A[9] = "True"A[10] = "True"ArrayRandom[1] = "5234162"ArrayRandom[2] = "1896523"ArrayRandom[3] = "5974216"ArrayRandom[4] = "2756194"randomNumber = Math.GetRandomNumber(Array.GetItemCount(ArrayRandom))GraphicsWindow.CanResize = "False"GraphicsWindow.Width = gwGraphicsWindow.Height = ghGraphicsWindow.Top = (Desktop.Height - gh) / 2GraphicsWindow.Left = (Desktop.Width - gw) / 2GraphicsWindow.Title = "True or False"GraphicsWindow.Show()Controls.ButtonClicked = OnButtonClickedCreateUI()Sub CreateUIGraphicsWindow.BrushColor = "Purple"GraphicsWindow.FontName = "Verdana"GraphicsWindow.FontSize = 14GraphicsWindow.DrawRectangle(10, 10, 480, 330) trueButton = Controls.AddButton("True", 30, 210) falseButton = Controls.AddButton("False", 320, 210) Controls.SetSize(trueButton, 150, 100)Controls.SetSize(falseButton, 150, 100)GraphicsWindow.DrawText(220, 300, "Result")resultTextBox = Shapes.AddText("")Shapes.Move(resultTextBox, 220, 250)scoreTextBox = Shapes.AddText("Score: 0")Shapes.Move(scoreTextBox, 404, 15)StartGame() EndSubSub StartGamepassedQuestion = Text.GetSubText(ArrayRandom[randomNumber], i, 1) If i <= 7 Thenqx = 60qy = 90 GraphicsWindow.BrushColor = "LightBlue"GraphicsWindow.FillRectangle(200, 220, 100, 80) GraphicsWindow.FillRectangle(20, 50, 460, 100) GraphicsWindow.BrushColor = "Blue"GraphicsWindow.DrawBoundText(qx - 20, qy, 420 "" + Q[passedQuestion])currentAnswer = A[passedQuestion]Else Program.Delay(1000)GraphicsWindow.ShowMessage("Your Score is " + score, "Game Over")Program.End()EndIfi = i + 1EndSubSub OnButtonClickedclickedButtonCaption = Controls.GetButtonCaption(Controls.LastClickedButton)If currentAnswer = clickedButtonCaption Then lastAnswer = "Correct"Shapes.Move(resultTextBox, 220, 250) score = score + 1ElselastAnswer = "Incorrect"Shapes.Move(resultTextBox, 212, 250)EndIfShapes.SetText(resultTextBox, lastAnswer) Shapes.SetText(scoreTextBox, "Score: " + score)StartGame()EndSub