CRE Programming Club - Class 7 Robert Eckstein and Robert Heard.

Slides:



Advertisements
Similar presentations
Sprite-visual object (actor on the stage) Scripts- Tells actors (sprites) what to do.
Advertisements

Getting Started with PowerPoint
Introduction to Macromedia Director 8.5 – Lingo
Create a Simple Game in Scratch
Create a Simple Game in Scratch
Microsoft® Small Basic
This symbol is used to; Start a flow-chart; Stop a singe flow-chart (or all flow charts in that program); Mark the Start of a Sub-Routine (a separate.
Microsoft® Small Basic
Visual Basic.NET BASICS Lesson 10 Do Loops. 2 Objectives Explain what a loop is. Use the Do While and Do Until loops. Use the InputBox function. Use the.
Scratch Programming Session 9 of 10 Review elements to use in stories, games, etc.
Games and Simulations O-O Programming in Java The Walker School
Chapter 9 Introduction to ActionScript 3.0. Chapter 9 Lessons 1.Understand ActionScript Work with instances of movie clip symbols 3.Use code snippets.
1 - buttons Click “Step Forward” to execute one line of the program. Click “Reset” to start over. “Play,” “Stop,” and “Step Back” are disabled in this.
Welcome to the CRE Programming Club! Robert Eckstein and Robert Heard.
MrsBillinghurst. net A2 Computing A2 Computing Projects Game Animation in Pascal.
XP Tutorial 5 Buttons, Behaviors, and Sounds. XP New Perspectives on Macromedia Flash MX Buttons Interactive means that the user has some level.
Making a Timer in Alice.
Programming 101 The Common Palette Content provided by Connor Statham (6 th Grade Student) Formatting by Shannon Sieber.
Making a Boat Racing Game in Alice By Jenna Hayes Under the direction of Professor Susan Rodger Duke University, July 2010.
Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.
Programming & Scratch. Programming Learning to program is ultimately about learning to think logically and to approach problems methodically. The building.
 Make sure you are subscribed to announcements on Moodle.  Activity 4 will be due 48hrs after your lab ends.
Selecting, Formatting, and Printing a finished Report…….
EET 2259 Unit 7 Case Structures; Sequence Structures  Read Bishop, Sections 5.4 and 5.5.  Lab #7 and Homework #7 due next week.  Quiz #3 next week.
Chapter 9 - VB.Net by Schneider1 Chapter 9 – Additional Controls and Objects 9.1 List Boxes, Combo Boxes, and the File-Opening Control The List Box Control.
Welcome to the CRE Programming Club! Robert Eckstein and Robert Heard.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
The PictureBox Control Prefix Prefix – pic Image Property PictureBox Image Property – Changes the image or file that appears inside of the PictureBox SizeMode.
CRE Programming Club - Class 4 Robert Eckstein and Robert Heard.
Game Maker Terminology
Making a Timer in Alice By Jenna Hayes under the direction of Professor Susan Rodger Duke University July
Piñata Game: Keeping Score in Alice By Maggie Bashford Professor Susan Rodger Duke University July
Digital Electronics and Computer Interfacing Tim Mewes 4. LabVIEW - Advanced.
Lab 1 : Introduction to LabView 1 Southern Methodist University Bryan Rodriguez.
Loops & Graphics IP 10 Mr. Mellesmoen Recall Earlier we wrote a program listing numbers from 1 – 24 i=1 start: TextWindow.WriteLine(i) i=i+1 If.
Creating a Simple Game in Scratch Barb Ericson Georgia Tech June 2008.
CRE Programming Club Class 3 (Install Small Basic on the new computers! Double-click on I:/smallbasic.msi)
Create a Halloween Computer Game in Scratch Stephanie Smullen and Dawn Ellis Barb Ericson October 2008.
CRE Programming Club - Class 2 Robert Eckstein and Robert Heard.
CRE Programming Club Class #9 Robert Eckstein and Robert Heard.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4: Events Programming with Alice and Java First Edition by John Lewis.
Lesson 2: Reading a program. Remember: from yesterday We learned about… Precise language is needed to program Actors and Classes Methods – step by step.
CRE Programming Club Class 8 Robert Eckstein and Robert Heard.
CRE Programming Club - Class 5 Robert Eckstein and Robert Heard.
Open a new Flash File Action Script 2.0. Create a button like you did last lesson and name it Click to Play.
Programming 101 The Common Palette Content provided by Connor Statham (9 th Grade Student) Formatting by Shannon Sieber.
5 Event Handling Interactive Programming Suggested Reading Interaction: Events and Event Handling, Supplemental Text for CPSC 203 Distributed this term.
CRE Programming Club - Class 4 Robert Eckstein and Robert Heard.
Tutorial 8: Manipulating Strings1 Tutorial 8 Manipulating Strings.
CRE Programming Club - Class 3 Robert Eckstein and Robert Heard.
Creating a Simple Game in Scratch Barb Ericson Georgia Tech May 2009.
Game Maker Tutorials Introduction Clickball IntroductionClickball Where is it? Shooting Where is it?Shooting.
Create a Halloween Computer Game in Scratch
Programming & Scratch.
Scratch for Interactivity
Using the Stopwatch object
Let's Race! Typing on the Home Row
Starter Write a program that asks the user if it is raining today.
The Execution Of Sleep()
Unit 2 Programming.
Number and String Operations
Microsoft® Small Basic
Fundamentals of Computer Organisation & Architecture
Problem Solving Designing Algorithms.
Additional Topics in VB.NET
User Input Keyboard input.
Creating a Simple Game in Scratch
EET 2259 Unit 7 Case Structures; Sequence Structures
under the direction of Professor Susan Rodger
Presentation transcript:

CRE Programming Club - Class 7 Robert Eckstein and Robert Heard

Understanding Events Certain objects in Small Basic have events that you can “subscribe” to. In order to subscribe to an event, create a subroutine, then assign the name of the subroutine to the event in the object. Whenever the event happens, the subroutine is called to “handle” the event. This can be almost never, or several times a second.

Events Events are something in computers that we call interrupts. With an interrupt, everything is going smoothly in the main program, until something outside the program needs to get the program’s attention. At that point, execution in the main program is brought to a halt, and the subroutine that handles the interrupt is run.

Import VSX414 GraphicsWindow.KeyDown = handleKeyPress GraphicsWindow.Show() looping = "True" While (looping) TextWindow.WriteLine("Happily looping...") Program.Delay(500) EndWhile Sub handleKeyPress TextWindow.WriteLine("Key Down is " + GraphicsWindow.LastKey) EndSub

Adding... Import PDG320 GraphicsWindow.KeyDown = handleKeyPress GraphicsWindow.KeyUp = handleKeyUp GraphicsWindow.MouseMove = handleMouseMove GraphicsWindow.MouseDown = handleMouseClick GraphicsWindow.Show() looping = "True" While (looping) TextWindow.WriteLine("Happily looping...") Program.Delay(1000) EndWhile

Import PDG320 Sub handleKeyPress TextWindow.WriteLine("Key Down is " + GraphicsWindow.LastKey) EndSub Sub handleKeyUp TextWindow.WriteLine("Key Up is " + GraphicsWindow.LastKey) EndSub Sub handleMouseMove TextWindow.WriteLine("Mouse is at " + GraphicsWindow.MouseX + "," + GraphicsWindow.MouseY) EndSub Sub handleMouseClick TextWindow.WriteLine("Mouse is clicked") EndSub

These Are the Key Lines... GraphicsWindow.KeyDown = handleKeyPress GraphicsWindow.KeyUp = handleKeyUp GraphicsWindow.MouseMove = handleMouseMove GraphicsWindow.MouseDown = handleMouseClick They assign subroutines to these events....

The Program Object Program.Delay(time) - This will cause the program to wait for a certain amount of time, specified as a number in milliseconds. Program.End() - This will cause the program to immediately terminate.

Timer There is also a Timer object if you want Small Basic to let you know when a certain amount of time has passed. You tell the object how often the time interval is, and give it the name of a subroutine. Timer.Interval = 1000 Timer.Tick = OnTimerTick Sub OnTimerTick TextWindow.WriteLine(“Timer has ticked”) EndSub

The Timer Object Why Would You Use This? Perhaps you have a clock in your program that needs to count down or up every second... You can also use it to help show an obstacle or enemy in your game. (A new one comes on screen every 3 seconds.)

The Sound Object Look at the reference documentation for the Sound Object Small Basic gives you the ability to play some elementary or complex sounds. A bell ringing, a chime, and a click are three of the sounds that you get for “free” with Small Basic.

Import QRL274 looping = "True" While (looping) Program.Delay(3000) Sound.PlayBellRing() TextWindow.WriteLine("Playing bell ring") Program.Delay(3000) Sound.PlayChime() TextWindow.WriteLine("Playing chime") Program.Delay(3000) Sound.PlayBellRingAndWait() TextWindow.WriteLine("Played bell ring") EndWhile

What’s the Difference Between Play and PlayAndWait? The Play() operations will play the sound and immediately continue running the program (even if the sound hasn’t finished yet). The PlayAndWait() operations will play the sound and stop the program until the sound has completed playing. Why would you want to use either one?

Import XMV444 filepath = " Sound.PlayAndWait(filepath) Sound.Play(filepath) Program.Delay(1000) Sound.Pause(filepath) Program.Delay(1000) Sound.Play(filepath) Program.Delay(500) Sound.Pause(filepath) Program.Delay(500) Sound.Play(filepath) Program.Delay(500) Sound.Stop(filepath)

We Can Play a Sound, Pause It, Continue Playing It, and Stop It The Sound.Play() operation will start to play the sound, and immediately continues running the program. The Sound.Pause() operation pauses the sound. The Sound.Stop() operation stops and resets.

The Text Object Look at the reference documentation for the Text object The Text object allows you to manipulate Strings. We can get the length of a string, append to it, check for text inside of it, etc.

Text - Import LKW972 TextWindow.Write("Enter a valid address: ") ID = TextWindow.Read() m = Text.IsSubText( ID, ".") n = Text.IsSubText( ID, If (m = "True") And (n = "True") Then TextWindow.WriteLine("Valid address.") Else TextWindow.WriteLine("Invalid address.") EndIf

What is SubText? Text.isSubText(text, subText) - Gets whether or not a given subText is a subset of the larger text. Text.GetSubText(text, start, length) - Gets a sub-text from the given text. Text.GetSubTextToEnd(text, start) - Gets a sub-text from the given text from a specified position to the end.

More Text Operations Text.GetIndexOf(text, subText) - Finds the position where a sub-text appears in the specified text. Text.ConvertToLowerCase(text) - Converts the given text to lower case. Text.ConvertToUpperCase(text) - Converts the given text to upper case.

Names - Import JFG395 TextWindow.Write("Enter your full name: ") Name = TextWindow.Read() c = Text.GetIndexOf(Name, " ") firstName = Text.GetSubText(Name, 1, c-1) lastName = Text.GetSubTextToEnd(Name, c+1) TextWindow.WriteLine("First name: " + firstName) TextWindow.WriteLine("Last name: " + lastName)

How Did We Separate The Names? We asked the Text object to locate the first instance of a “space” in the string. We then took the substring from position 1 up to the position before the space (c-1) and made that the first name. We took the substring from position c+1 to the end and made that the last name.

Assignment Create a Timer that calls a subroutine every 5 seconds. In that subroutine, play the bells sound...unless it’s been 30 seconds, at which point, you should play the chimes instead. Or… create a shape on top of a graphics window that will move up, down, left, and right if you press the arrow keys. Create a “wrap around” if the shape goes off the edge of the screen.

Next Time... We’re going to learn about stacks and the main game loop.