Presentation is loading. Please wait.

Presentation is loading. Please wait.

Reference: www.pygame.org. What is it? A multimedia python library – Window Management – Graphics geometric shapes bitmaps (sprites) – Input Mouse Keyboard.

Similar presentations


Presentation on theme: "Reference: www.pygame.org. What is it? A multimedia python library – Window Management – Graphics geometric shapes bitmaps (sprites) – Input Mouse Keyboard."— Presentation transcript:

1 Reference: www.pygame.org

2 What is it? A multimedia python library – Window Management – Graphics geometric shapes bitmaps (sprites) – Input Mouse Keyboard Gamepad / Joystick – Sound SoundFX Music

3 How to get it (at home) www.pygame.org Make sure you have 32-bit python installed. Download the matching pygame version – pygame-1.9.2a0.win32-py3.2.msi Try this at the prompt: >>> import pygame – If no errors, you’re all set!

4 First example Goals: – Create a window – Keep it up for 3 seconds – Shut it down

5 Surfaces A 2d array of (RGB) pixels – An image (sprite) – Rendered (at run-time) text – A mini-map – A HUD – An interface to the window’s contents. – In pygame, Surfaces are objects. Look up the methods in the “Surfaces” section of pygame docs. Double Buffering – Monitor refreshes – Life without D.B. – D.B. in pygame

6 Drawing shapes in pygame [Look at the pygame docs] – pygame.draw module [Example: Drawing things] [Example: Drawing n circles] – Evenly spaced – Shifting colors [Example: Animating a circle]

7 The Game Loop Animation / Game loop 1.Erase the screen 2.[Get input from the user] (GameLoop only) 3.Update variables 4.Draw (using variables) 5.Flip – [Brain absorbs info while new screen is being drawn]

8 A Game Loop "problem" So…a game loop run on these would be faster / slower. Character moving at 100 pixels / s. – Suppose we write it on the IIgs – What would it look like on the Alienware? IIgs image: http://oldcomputers.net/appleiigs.htmlhttp://oldcomputers.net/appleiigs.html Alienware image: http://www.dell.com/us/p/alienware-area51-alx/pd?refid=alienware-area-51-alx Do these run at the same speed?

9 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. – Advantage: simple – Disadvantages: If the computer can't reach 60fps, there will be differences. time.sleep pauses everything. We could do useful work during that pause – AI calculations – physics – etc.

10 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.


Download ppt "Reference: www.pygame.org. What is it? A multimedia python library – Window Management – Graphics geometric shapes bitmaps (sprites) – Input Mouse Keyboard."

Similar presentations


Ads by Google