CRE Programming Club Class 8 Robert Eckstein and Robert Heard.

Slides:



Advertisements
Similar presentations
Introduction to Macromedia Director 8.5 – Lingo
Advertisements

Summer Computing Workshop. Introduction to Variables Variables are used in every aspect of programming. They are used to store data the programmer needs.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Microsoft® Small Basic
Game Programming Patterns Game Loop
Microsoft® Small Basic
Announcements You survived midterm 2! No Class / No Office hours Friday.
Events Chapter 7. Interactivity The real world is interactive User determines order of actions instead of programmer.
Events Chapter 7. Interactive Real world is interactive User determines order of actions instead of programmer.
Right-click on the colored box and remove it.
Mrs. Chapman. Tabs (Block Categories) Commands Available to use Script Area where you type your code Sprite Stage All sprites in this project.
Scratch Programming Session 9 of 10 Review elements to use in stories, games, etc.
Game Design and Programming. Objectives Classify the games How games are design How games are implemented What are the main components of a game engine.
Classes, methods, and conditional statements We’re past the basics. These are the roots.
Systems Environment 3 Quick Revision Review of Exercises Introduction to TOM TOM Exercises.
How to Debug VB .NET Code.
Adding Automated Functionality to Office Applications.
SE320: Introduction to Computer Games Week 8: Game Programming Gazihan Alankus.
Mr. Wortzman. Tabs (Block Categories) Available Blocks Script Area Sprite Stage All sprites in this project.
Digital/ Analog Time 4th Strategies for Your Toolbox in Solving Problems Involving Digital/ Analog Time.
2 What is pyGame? A set of Python modules to make it easier to write games. –home page: –documentation:
What is RobotC?!?! Team 2425 Hydra. Overview What is RobotC What is RobotC used for What you need to program a robot How a robot program works Framework.
Welcome to the CRE Programming Club! Robert Eckstein and Robert Heard.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley This week: Whew!!! The last homework was tough! The homework for this week.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #005 (April somthin, 2015)
Making a Timer in Alice.
CATCH SCRATCH! Programming from Scratch. Remember Scratch?
Making a Boat Racing Game in Alice By Jenna Hayes Under the direction of Professor Susan Rodger Duke University, July 2010.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Study Guide For Test Chapter 5, 6,& 7 Test is Friday, May 15th.
CRE Programming Club - Class 7 Robert Eckstein and Robert Heard.
Review For Test Chapter 4 & 5 Test is Wednesday, January 27th.
Events Chapter 7 Part 2. While a Key is Pressed Event Specialized event An event occurs when you press a key and continues until you take your finger.
Checking for Collisions: Alternative Method Erin Taylor Under the Direction of Susan Rodger July 2015 Duke University.
Art 315 Lecture 5 Dr. J. Parker AB 606. Last time … We wrote our first program. We used a tool called GameMaker. The program we wrote causes a ball to.
CPS120 Introduction to Computer Science Iteration (Looping)
VB Games: Preparing for Memory Brainstorm controls & events Parallel structures (again), Visibility, LoadPicture, User-defined procedures, Do While/Loop,busy.
Welcome to the CRE Programming Club! Robert Eckstein and Robert Heard.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
CRE Programming Club - Class 4 Robert Eckstein and Robert Heard.
Computer Systems Week 7: Looping and Input/Output with 3-bit Alma Whitfield.
Making a Timer in Alice By Jenna Hayes under the direction of Professor Susan Rodger Duke University July
CS324e - Elements of Graphics and Visualization Timing Framework.
ITEC 109 Lecture 11 While loops. while loops Review Choices –1 st –2 nd to ?th –Last What happens if you only use ifs? Can you have just an else by itself?
CRE Programming Club Class 3 (Install Small Basic on the new computers! Double-click on I:/smallbasic.msi)
Game Programming Patterns Game Loop From the book by Robert Nystrom
CRE Programming Club - Class 2 Robert Eckstein and Robert Heard.
CRE Programming Club Class #9 Robert Eckstein and Robert Heard.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
CompSci Introduction to Jam’s Video Game Package.
Beginning Fortran Introduction 13 October 2009 *Black text on white background provided for easy printing.
CRE Programming Club - Class 5 Robert Eckstein and Robert Heard.
Lesson 1. Security At the menu bar at the top you will see the word Tools. Click your mouse on Tools scroll down to Macro. Move the Mouse over and down.
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.
Repetition everywhere – comparing while in a method and as an event Susan Rodger Duke University July 2010.
CRE Programming Club - Class 3 Robert Eckstein and Robert Heard.
(More) Event handling. Input and Windowed-OS’s Windowed OS’s (Windows, OSX, GUI-linux’s) send messages (events) when the user does something “on” the.
Game Maker Tutorials Introduction Clickball IntroductionClickball Where is it? Shooting Where is it?Shooting.
Collision Theory and Logic
Event Loops and GUI Intro2CS – weeks
Collision Theory and Logic
Starter Write a program that asks the user if it is raining today.
elppa legoog erawdrah erawtfos margorp Cisab llams Apple Google
AN INTRODUCTION TO: POWERPOINT.
Tonga Institute of Higher Education
Game Loop Update & Draw.
WEEK 8 COURSE PROJECT PRESENTATION NAME: ALEXANDER WEISS CLASS: CIS115.
Presentation transcript:

CRE Programming Club Class 8 Robert Eckstein and Robert Heard

Introduction to Game Design Games have to be fun. Games have be challenging. The best games are easy to learn and difficult to master.

The Loop All games start with a simple loop. The loop will continue until the program is exited. There is often a second loop on the inside that is a “control loop,” and handles things like pausing or quitting the current game (but not the program itself.) We’ll see an example of this shortly.

What State Are You In? Laying Down Sitting Walking Jumping Running Biking How do you go from one state to another?

The State Machine Games often make use a (finite) state machine. A state machine is a very common tool in programming. A state machine is a fancy name for a program that is always in one--and exactly one--of several states. Common game states: main menu, starting level, playing level, finishing level, paused, cutscene, etc.

Transitions and Events State machines have to have the ability to move from one state to another: these are called transitions. Transitions are usually started with events. An event might be the user pressing a key, clicking a mouse, or something in the program’s logic that says it’s time for a transition to occur. Something triggers them.

playGame = “True” While (playGame = "True") ‘ Do something inside the loop... ‘ And something else... ‘ What happens if playGame is set to “False”? EndWhile A Simple Game Loop

We Immediately Have a Problem... Computers come with different CPUs that run at different speeds! A faster CPU will race through the game loop more rapidly than a slower CPU. That means your game may run too slowly on older CPUs, or too quickly on newer CPUs! We need the game to run at a consistent speed on all platforms.

Creating Delays Remember that one of the Clock object operations could be used like a stopwatch? What if we start measuring the time at the beginning of the loop... startClock = Clock.ElapsedMilliseconds Elapsed milliseconds since what? The epoch, which in typically exactly midnight on January 1st, 1970.

How Long Did It Take to Run? We then ask the computer for the current elapsed milliseconds at the end of the loop and subtract what we got at the start of the loop... timeTaken = Clock.ElapsedMilliseconds - startClock

At the End of the Loop... We then write some delay code to ensure that the program runs at the same speed no matter how fast the computer is... delay = 50 - timeTaken If (delay > 0) Then Program.Delay(delay) EndIf

Frames Per Second (fps) Where did we get 50 from? Nowhere. But we can instead specify a number that represents how long each “frame” is. Remember that 1000 milliseconds = 1 second. Divide by fps to get the number of milliseconds each “frame” should take! delay = (1000/fps)-timeTaken If (delay > 0) Then Program.Delay(delay) EndIf

Import JGT It looks something like this, inside the game loop... If (currentState = DISPLAY_LEVEL) Then ElseIf (currentState = PLAY_GAME) Then ElseIf (currentState = END_LEVEL) Then EndIf

Work With This Program Notice that the program has three states. The program starts in the first state, then jump to the second state, then to the third. How do we transition? You’ll do this by changing the state variable in one loop to be equal to the next state.

Another Possible State Machine If (currentState = INIT_LEVEL) Then initLevel() ElseIf (currentState = INTRODUCE_LEVEL) Then introduceLevel() ElseIf (currentState = PLAY_LEVEL) Then playLevel() ElseIf (currentState = END_LEVEL) Then endLevel() EndIf

Subroutine initLevel Sub initLevel ' Each time we start a new level, we add 1 to the level number levelNumber = levelNumber EndSub What other initialization might we need here?

Back To JGT020 Sub displayLevelText levelText = Shapes.AddText("Level " + currentLevel) Shapes.Move(levelText, GraphicsWindow.Width / , GraphicsWindow.Height / ) Shapes.ShowShape(levelText) EndSub

What About This? Sub hideLevelText Shapes.HideShape(levelText) EndSub

Using the State Machine displayLevelText() Program.Delay(5000) hideLevelText() currentState = PLAY_GAME This last part is needed to transition the state machine to the PLAY_GAME state.

Homework Create subroutine(s) that handle the PLAY_GAME state. Use the homework from last week to help you. Can you change its color? Its size? Can you click on it somehow with the mouse? Can you use the keyboard? Create subroutine(s) that handle the END_LEVEL state. Maybe you can put up text that says “Level Completed”

Next Time... We’re going to learn about what happens when shapes collide.