Reference: www.pygame.org. The Game Loop Animation / Game loop 1. Update variables 2. [Get input from the user] (GameLoop only) 3. Draw (using variables)

Slides:



Advertisements
Similar presentations
Create a Simple Game in Scratch
Advertisements

Computer Organization. The Nature of Data Spreadsheets give us a way to create processes that manipulate data We can think of a piece of data as a quantity.
Create a Simple Game in Scratch
Game Programming Patterns Game Loop
How do games work? Game Workshop July 4, Parts Sprites/pictures Map/background Music/sounds Player character Enemies Objects.
6/13/20151 CS 160: Lecture 13 Professor John Canny Fall 2004.
Announcements At the end of your project, you’ll be given an opportunity to make a standalone (.exe) version of your project. For this to work, you’ll.
Exercise A) Find out how tock in that figure works manually. Enter expression expressions such as (tock 0) and (tock 1) into DrScheme's Interactions.
Sketchify Tutorial Graphics and Animation in Sketchify sketchify.sf.net Željko Obrenović
Games Development Practices Semester 2 Overview CO2301 Games Development 1 Week 14.
AGD: 5. Game Arch.1 Objective o to discuss some of the main game architecture elements, rendering, and the game loop Animation and Games Development.
SE320: Introduction to Computer Games Week 8: Game Programming Gazihan Alankus.
What is Scratch? Scratch as Logo Dr. Ben Schafer Department of Computer Science University of Northern Iowa.
INTRODUCTION TO SCRATCH. About Me Resources Scratch Website Learn Scratch Washington-Lee Computer.
2 What is pyGame? A set of Python modules to make it easier to write games. –home page: –documentation:
Guide to Programming with Python
PacMan by Midway, released 1980 CSE 380 – Computer Game Programming Real-Time Game Architecture.
There are different types of translator. An Interpreter Interpreters translate one instruction at a time from a high level language into machine code every.
Introduction to TouchDevelop
Lecture 02: Intro to SDL Topics: Downloading / Installing SDL Linking (in general and for SDL) SDL basics References:
Visual Basic .NET BASICS
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 7 The Game Loop and Animation Starting Out with Games & Graphics.
Programming games Show your version of Bo the dog. Start cannonball Preview: video, audio work session (cannonball) Homework: Cannonball with ball in a.
References: Wikipedia PHYSICS + VECTORS.  Why physics?  Good for every game developer to know.  Physics formulae are often vector-based  A good chance.
13-Nov-15 (1) CSC Computer Organization Lecture 7: Input/Output Organization.
2.1. T HE G AME L OOP Central game update and render processes.
11 General Game Programming Approach. The program is event-driven The program is event-driven –Messages = events –So as all windows system (for example.
Super Pong Andrew S. Dunsmore CSC436 August 2004.
Game Programming Patterns Game Loop From the book by Robert Nystrom
Physics + Vectors References: xyz. Variable frame rates (review) Two options for handling it: – Option1: Cap frame rates When moving / rotating express.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4: Events Programming with Alice and Java First Edition by John Lewis.
Tutorial 7 Creating Animations. XP Objectives Learn about animation Create a timeline Add AP divs and graphics to a timeline Move and resize animation.
T HE G AME L OOP. A simple model How simply could we model a computer game? By separating the game in two parts: – the data inside the computer, and –
Unit 1: Computing Fundamentals. Computer Tour-There are 7 major components inside a computer  Write down each major component as it is discussed.  Watch.
CompSci 44.1 Game Package Introduction to Jam’s Video Game Package.
Scratch for Interactivity Dr. Ben Schafer Department of Computer Science University of Northern Iowa.
CS F EBRUARY 9, 2016 P ARTS G AME A RCHITECTURE, M EMORY, AND I/O S YSTEMS G AME T IMING G AME T IMING G AME P ARALLELISM G AME P ARALLELISM.
PyGame - Unit 1 PyGame Unit – – Introduction to PyGame.
1 CSC 221: Computer Programming I Fall 2009 Introduction to programming in Scratch  animation sprites  motion, control & sensing  costume changes 
PyGame - Unit 2 PyGame Unit – – Animation.
FlowArm PLTW Programming
(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.
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.
Accomplish more with macros! Presenter: Joyce Bell Princeton University
Section06: Sequences Chapter 4 and 5. General Description "Normal" variables x = 19 – The name "x" is associated with a single value Sequence variables:
Reference: What is it? A multimedia python library – Window Management – Graphics geometric shapes bitmaps (sprites) – Input Mouse Keyboard.
Section06: Sequences Chapter 4 and 5.
Sound and more Animations
Scratch for Interactivity
Catapult 2016.
Animations.
Part II Reference:
PYGAME.
WITH PYGAME ON THE RASPBERRY PI
Let’s Learn 2. Installing Pygame
8. Installing Pygame
Keyboard Input.
Game Loops + Part II Reference:
Scratch for Interactivity
Introduction to Object-Oriented Programming
Game Loop Frame Rate.
8. Starting Pygame Let's Learn Python and Pygame
Game Loop Update & Draw.
Games Development Practices Semester 2 Overview
L L Line CSE 420 Computer Games Lecture #6 Game Foundations.
CSC 221: Introduction to Programming Fall 2018
CoE Software Lab II 1. Pygame Intro , Semester 2,
Presentation transcript:

Reference:

The Game Loop Animation / Game loop 1. Update variables 2. [Get input from the user] (GameLoop only) 3. Draw (using variables) 1. Erase the screen 2. Actual drawing code (using variables) 3. Flip 4. Repeat [Brain absorbs info while new screen is being drawn in steps 1-4]

Window input (common to nearly all OS's) Application == Window (to the OS)  Application might have sub-windows  Buttons, Menus, … OS sends messages (events) to the App  Upon creation  Minimize / Maximize / Resize / Close  Mouse / Keyboard / Gamepad events

Events and pygame Pygame gives us two choices:  Event Handling: Handle (new) events manually  Ask pygame for a list of Event objects with pygame.event.get()  Iterate through it (hint: while or later a for loop) If this event is important to our app, handle it.  [We’ll do this after looking at sequences]  Device-polling: Let pygame process the events and then we poll pygame.  Call pygame.event.pump() Process all waiting events Saves result in status variables  Access the status variables  Hybrid:  Use pygame.event.get.  Handle events of interest  Use device polling for the rest [Example of each: moving circle, switch color w/ space, close button (w/ mouse over)]

A few more pygame tidbits Clock objects  tick  get_fps Sounds / Music  loading and playing

A Game Loop "problem" So…a game loop run on these would be faster / slower. Character moving at 1 pixels / update.  Suppose we write it on the IIgs  What would it look like on the Alienware? IIgs image: Alienware image: Do these run at the same speed?

A Game Loop "problem", cont. Solution #1: Insert pauses  Set a desired frame rate (60fps == 1/60s per frame)  Calculate time since last frame  Insert a time.sleep if necessary (or use the clock object)  Advantage: simple  Disadvantages:  If the computer can't reach 60 fps, there will be differences.  time.sleep pauses everything. We could do useful work during that pause AI calculations physics etc.  If we want to change the target fps, we have to change movement / rotation amounts everywhere in our code.

A Game Loop "problem", cont. Solution #2: Adjust movements based on dt  Let the computer run as fast as possible  Calculate dT (the time since last frame)  Express desired movments speeds as a velocity (e.g. 100 pixels / s)  Each frame, velocity * dT is the distance to move.  On a slow computer…  On a fast computer…  This is what's done on most PC games and most modern consoles.  Disadvantages: we have to do an extra multiply every frame.

Example [Adjust moving circle example to run at a constant rate] [Animated "Bjorn" character (Reiner's tileset)] 

Parting Thought [Playing background music and sound effects]