PyGame - Unit 2 PyGame Unit 2 2-1 – 2-4 2.1 – Animation.

Slides:



Advertisements
Similar presentations
Games in Python – the easy way
Advertisements

Sprites, User Input, and Collision COSC 315 Fall 2014 Bridget M. Blodgett.
Creating Games For Windows, Xbox 360, and Windows Phone 7 Ryan Plemons
How Images are Represented Bitmap images (Dots used to draw the image) Monochrome images 8 bit grey scale images 24 bit colour Colour lookup tables Vector.
2 What is pyGame? A set of Python modules to make it easier to write games. –home page: –documentation:
Guide to Programming with Python
Week 10 Writing Games with Pygame, continued Special thanks to Scott Shawcroft, Ryan Tucker, and Paul Beck for their work on these slides. Except where.
MrsBillinghurst. net A2 Computing A2 Computing Projects Game Animation in Pascal.
COMP Bitmapped and Vector Graphics Pages Using Qwizdom.
CHAPTER 4 Images XNA Game Studio 4.0. Objectives Find out how the Content Manager lets you add pictures to Microsoft XNA games. Discover how pictures.
Lesson 6 Links. Creating Folders  For every web site/page, you need to create a separate folder  The computer cannot find links if they are not stored.
6-2 2D Graphics CSNB544 Mobile Application Development Thanks to Utexas Austin.
Creating Web Documents: Images, files, etc. Web graphics Paint Shop Pro for conversions File management, Ws-ftp demonstration (Return to HTML next week)
Image Storage Bitmapped Graphics – in which an image is represented as a collection of dots Vector Graphics – in which an image is represented as a set.
Spiral Rider PAGE 1. Set Up Scene 1.Add Stage-underwater scene 2.Add crab sprite 3.Add two fish sprites PAGE 2.
11 A First Game Program Session Session Overview  Begin the creation of an arcade game  Learn software design techniques that apply to any form.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 5 Working with Images Starting Out with Games & Graphics in.
“The Power At The Click Of A Mouse” (Using Power Point To Create A Presentation)
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.
Working with Graphics – Lesson 21 Working with Graphics Lesson 2.
Power Point Presentations “A how to primer”. Start with a “blank presentation” Instructions 1. Launch (or open) power point. 2. Close the office assistant,
AD 305 Electronic Visualization I : School of Art and Design : University of Illinois at Chicago : Spring 2007 Intro to Action Script 9 "The games of a.
PowerPoint Practice Exercise 1 1.Save this file in your AV-TECH Folder as PowerPoint Practice Exercise 1. 2.Open this file in PowerPoint. 3.Edit each slide.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Introduction to Android (Part.
Sprites, User Input, and Collision COSC 315 Fall 2014 Bridget M. Blodgett.
Reference: The Game Loop Animation / Game loop 1. Update variables 2. [Get input from the user] (GameLoop only) 3. Draw (using variables)
Game Art & Sound. Sound ● Midi files – Musical Instrument Digital Interface – Advantages ● small ● fast – Disadvantages ● synthesized ● rendered ● Wav.
AD 206 Intermediate CG : School of Art and Design : University of Illinois at Chicago : Spring 2009 Intro to Action Script 9 "The games of a people reveal.
CHAPTER 3 (P.49-53) Importing modules + pygame intro.
Scratch Creative Computing. INTRODUCTION TO SCRATCH Section 1.
Photo Story. How to use Photo Story Photo Story 3 can be located in the Accessories folder on school computers. You will need to have your pictures already.
Playing with Sprites. XNA Game Lifecycle In the faceBall demo program we bounced a smiley face around the graphical display against a background image.
Copyright © Texas Education Agency, All rights reserved.1 Web Technologies Motion Graphics & Animation.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Starting Out with Games & Graphics in C++ Tony Gaddis Chapter 8 The.
PowerPoint Basics Tutorial 2: A Slide Show In this tutorial you’re going to create a presentation from scratch. You will have to keep this presentation.
PyGame - Unit 1 PyGame Unit – – Introduction to PyGame.
1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Session 22 Game Graphics.
1 CSC 221: Computer Programming I Fall 2009 Introduction to programming in Scratch  animation sprites  motion, control & sensing  costume changes 
IE 411/511: Visual Programming for Industrial Applications Lecture Notes #2 Introduction to the Visual Basic Express 2010 Integrated Development Environment.
GAME:IT Paddle Ball Objectives: Review skills from Introduction Create a background Add simple object control (up and down) Add how to create a simple.
PyGame - Unit 4 PyGame Unit – Object Oriented Programming OOP.
Computer Programming with Scratch JAOIT 8. Scratch Scratch is a programming language that makes it easy to create your own interactive stories, animations,
Graphics in Python On entry: Run Python 2.78 from N: drive/computing and ICT VLE: Computing home page - check your feedback Success criteria: ●Understands.
Intro to Pygame Lecture 05. What is Pygame? It is a set of Python modules designed for writing games. It makes writing games possible for beginners. import.
(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.
Efficient Game Graphics From Flash MX 2004 Game Design Demystified.
3. Drawing Let’s Learn Saengthong School, June – August 2016 Teacher: Aj. Andrew Davison, CoE, PSU Hat Yai Campus
Reference: What is it? A multimedia python library – Window Management – Graphics geometric shapes bitmaps (sprites) – Input Mouse Keyboard.
13. Sprites. Outline 1.Game Things in Pygame (again) 2.The Pygame sprite Module 3.The Sprite Class 4.Groups of Sprites 5.Types of Collision Detection.
Sprites (Images) and Sounds
For those who hate computers.
Sound and more Animations
MOM! Phineas and Ferb are … Aims:
Pixels, Colors and Shapes
Catapult 2016.
Animations.
PYGAME.
Let’s Learn 2. Installing Pygame
8. Installing Pygame
9. Drawing.
9. Drawing Let's Learn Python and Pygame
Look at Me Mod 4 Lesson 3 Graphics Module 4- Build a Game.
Chapter 5 Working with Images
Importing modules + pygame intro
13. Sprites Let's Learn Python and Pygame
8. Starting Pygame Let's Learn Python and Pygame
Lecture 2 - Building a Monogame Windows Project
Let’s Learn 7. Sprites Saengthong School, June – August 2016
L L Line CSE 420 Computer Games Lecture #6 Game Foundations.
Presentation transcript:

PyGame - Unit 2 PyGame Unit – – Animation

PyGame - Unit 2 PyGame 2-1 Animation

PyGame - Unit 2 Objectives By the end of this unit you will be able to: –Define animation. –Create simple animation.

Animation Can you give me? –Examples of animation outside of video games??? PyGame - Unit 2

Drawing Images pygame.image.load() Sprite – An image loaded on to the Surface object. –Sprites can be PNG, JPG, GIF, or BMP image files. What are the tradeoffs of these file types??? Images must be loaded before they can be used: catImage = pygame.image.load(‘cat.png') PyGame - Unit 2

Loading Images Loading an Image Using.convert() backgroundImg = "images/background.jpg" background = pygame.image.load(backgroundImg).convert() Loading an Image Using.convert_alpha() –Image Transparency (imageFileName.png) pizzaImg = "images/pizza_cursor.png" mouseCursor = pygame.image.load(pizzaImg).convert_alpha() PyGame - Unit 2

.png File Types (Transparent Backgrounds) pointerImg = pygame.image.load('point.png').convert_alpha() DISPLAYSURF.blit(pointerImg, (100, 100)) point.png is a fancy pointer with a transparent background. We must do the.convert_alpha() Once drawn on the Surface object, it can be: –Blitted Copied to DISPLAYSURF so it will appear on the screen. PyGame - Unit 2

Demo (Transparency) transparent_vs_non-transparent.py PyGame - Unit 1

Blitting an Image Blitting - drawing the contents of one Surface onto another. Loading cat.png on a surface object named catImg. catImg = pygame.image.load('cat.png‘) We must blit (copy) the image’s Surface object to the display Surface object. DISPLAYSURF.blit(catImg, (catx, caty)) – (catx, caty) is a two integer tuple that determines where to position the image on DISPLAYSURF PyGame - Unit 2

Moving the Image (Inside of Game Loop) #Blit the Image to DISPLAYSURF DISPLAYSURF.blit(mouseCursor, (x, 160)) # Move the image (changing the x value) x += 1 # Updating the display. Pygame.display.update() PyGame - Unit 2

basic_animation.py Review basic_animation.pybasic_animation.py PyGame - Unit 2

Reading / Exercises Read the “Making Games with Python and PyGame” textbook PP pg2-1-1.py

PyGame - Unit 2 PyGame 2-2 Timing (Clock Object)

PyGame - Unit 2 Objectives By the end of this unit you will be able to: –Work with the pygame.time.Clock() Control the speed of our animation regardless of computing power.

The Clock Object If we created a game that ran great on an old computer, how would it run on the an extremely fast computer? fpsClock = pygame.time.Clock() Puts in small pauses on each iteration of the game loop. –Without pauses, our game program would run as fast as the computer could run it. PyGame - Unit 1

The Clock Objects tick() Method The Clock object’s tick() method should be called at the very end of the game loop, after the call to pygame.display.update(). FPS = pygame.display.update() fpsClock.tick(FPS) The length of the pause is calculated based on how long it has been since the previous call to tick() PyGame - Unit 1

cat_animation.py Review cat_animation.pycat_animation.py Review diagonal_animation.pydiagonal_animation.py PyGame - Unit 1

PyGame - Unit 2 Reading / Exercises Read the “Making Games with Python and PyGame” textbook PP. ?? – ?? pg2-1-1.py pg2-1-2.py ???

PyGame - Unit 2 PyGame 2-3 Displaying Text pygame.font.Font() Object

PyGame - Unit 2 Objectives By the end of this unit you will be able to: –Display text on the screen using the: pygame.font.Font() function to define font style and size to define a font object. Rendering the font and text into a surface object. Blitting it on to the screen.

Definition(s) Render - the process of generating an image on a computer screen. Anti-aliasing - a graphics technique for making text and shapes look less blocky by adding a little bit of blur to their edges. –It takes a little more processing time to draw with anti-aliasing, so: The graphics may look better, but Your program may run slower (but only just a little). PyGame - Unit 2

Anti-Aliasing (Continued) Left line is aliased –Blockier when zoomed out The line on the right is ant-aliased –Smoother when zoomed out. PyGame - Unit 2

Six steps to displaying text in PyGame. 1.Create a pygame.font.Font object. 2.Rendering the font object, text definitions, colors, size etc. onto a surface object. 3.Create a Rect object from the surface object by calling the surface object’s get_rect() method. 4. Set the position of the Rect object. 5.Blit the Surface object onto the desired surface object (typically DISPLAYSURF) 6.Call pygame.display.update() PyGame - Unit 2

Text code Sample fontObj = pygame.font.SysFont("comicsans", 32) textSurfaceObj = fontObj.render('Hello world!', True, GREEN, BLUE) textRectObj = textSurfaceObj.get_rect() textRectObj.center = (200, 150) while True: # main game loop DISPLAYSURF.fill(WHITE) DISPLAYSURF.blit(textSurfaceObj, textRectObj) PyGame - Unit 2

Creating a pygame.font.Font object (Step 1) fontObj = pygame.font.SysFont("comicsans", 32) Type face = comicsans Type Size = 32 pts PyGame - Unit 2

Font Objects – Render Method (Step 2) textSurfaceObj = fontObj.render('Hello world!', True, GREEN, BLUE) Font.render(‘text’, True, color, backcolor) Our text is ‘hello world!’ The True parameter means we want to anti- alias the text (more on this in the next slide) GREEN is the text color. BLUE is the background color PyGame - Unit 2

The Surface object’s get_rect() method (Step 3) Us this to create a Rect object from the Surface object by calling the Surface object's get_rect() method: textRectObj = textSurfaceObj.get_rect() You cannot position your text on the screen unless it is associated with a rect() object. PyGame - Unit 2

Set the Position of the Rect object (Step 4) textRectObj.center = (200, 150) PyGame - Unit 2

Blit the Text Object to the Surface Object (Step 5) We are attaching the text to DISPLAYSURF DISPLAYSURF.blit(textSurfaceObj, textRectObj) Blit the following to the primary Display Surface ( DISPLAYSURF ) –textSurfaceObj - Defines the text –textRectObj - Helps place on DISPLAYSURF PyGame - Unit 2

pygame.display.update() (Step 6) Draws the DISPLAYSURF on screen. Discuss Performance pygame.display.update() –Vs. pygame.display.flip() PyGame - Unit 2

Reading / Exercises Read the “Making Games with Python and PyGame” textbook PP. 28 – 30 pg2-3-1.py pg2-1-2.py???

PyGame - Unit 2 PyGame 2-4 Sounds pygame.mixer.Sound() Object

PyGame - Unit 2 Objectives By the end of this lesson you will be able to: –Play sound effects in PyGame. –Play background music in PyGame.

pygame.mixer.Sound() Object soundObj = pygame.mixer.Sound('beeps.wav') In this example, beeps.wav must be in the same folder as the module. Plays sound effects. PyGame - Unit 2

Play() and stop() Methods soundObj = pygame.mixer.Sound('beeps.wav‘) Plays the entire sound (unless stopped) –soundObj.play() Immediately stops the sound from playing –soundObj.stop() PyGame - Unit 2

Sound Effect Example import time soundObj = pygame.mixer.Sound('beeps.wav') soundObj.play() time.sleep(1) # wait for 1 second soundObj.stop() PyGame - Unit 2

Background Music Example pygame.mixer.music.load(‘song.wav') pygame.mixer.music.play(-1, 0.0) –See next slide for parameter descriptions. #...some more of your code goes here... pygame.mixer.music.stop() PyGame - Unit 2

Parameters for pygame.mixer.music.play() pygame.mixer.music.load(‘song.wav') pygame.mixer.music.play(-1, 0.0) pygame.mixer.music.play( NbrPlayTimes, StartPoint) NbrPlayTimes – The number of times you want the music to play It will play the number of times indicated means loop endlessly. StartPoint – The number of seconds into the music track to begin playing. -1 means loop endlessly PyGame - Unit 2

Reading / Exercise(s) Read the Making Games with Python and PyGame textbook PP. 31 – 32 (Sounds) Exercises ???? PyGame - Unit 2