Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
2 views

Python 2 - P5 - Pygame - p1

The document provides an overview of the Pygame library, highlighting its simplicity and usefulness for developing 2D games in Python. It covers key concepts such as the Game Loop, event handling, and updating displays, along with practical examples for creating characters and managing frame rates. Additionally, it includes a practice exercise to enhance the game by adding another character.

Uploaded by

hao451653
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Python 2 - P5 - Pygame - p1

The document provides an overview of the Pygame library, highlighting its simplicity and usefulness for developing 2D games in Python. It covers key concepts such as the Game Loop, event handling, and updating displays, along with practical examples for creating characters and managing frame rates. Additionally, it includes a practice exercise to enhance the game by adding another character.

Uploaded by

hao451653
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 19

PYTHON 2

PYGAME
TS. NGUYỄN HOÀNG LONG
BỘ MÔN TIN HỌC TRẮC ĐỊA
0916666384
nguyenhoanglong@humg.edu.vn

1
2 PYGAME
• The Pygame library is probably the most
well known python library when it comes
to making 2D games.
• It’s not the most advanced or high level
library, but it’s simple and easy to learn
• The Pygame framework includes several
modules with functions for drawing
graphics, playing sounds, handling mouse
input, and other things that developers
need while developing games in Python.
3
CREATE A PYGAME FILE

4
RUN THE PYGAME

5
THE GAME LOOP
• Every game that exists has what we call a
“Game Loop”.
• The Game Loop is where all the game
events occur, update and get drawn to the
screen.
• Once the initial setup and initialization of
variables is out of the way, the Game Loop
begins where the program keeps looping
over and over until an event of type QUIT
occurs

6
EVENT OBJECTS
• An “Event” occurs when the user performs a
specific action, such as clicking his mouse or
pressing a keyboard button. Pygame records each
and every event that occurs.
• We can find out which events have happened by
calling the pygame.event.get() function, which
returns a list of pygame.event.Event objects
• One of the many attributes (or properties) held by
event objects is type. The type attribute tells us
what kind of event the object represents.
• If you take a look at the example shown earlier,
you’ll see we used event.type == QUIT to
determine whether the game was to be closed or
not.

7
CHANGE THE TITLE

8
CHANGE THE TITLE

9
DISPLAY UPDATE

10
DISPLAY UPDATE

11
FRAME PER SECOND (FPS)

12
FRAME PER SECOND (FPS)

13
CONTROL FPS

14
CREATE CHARACTERS

15
CREATE CHARACTERS

16
SURFACE.blit()

# display the object with


give coordinate
WIN.blit(Object, (x, y))

#example
WIN.blit(SUPERMAN_IMAGE, (200,
50))

17
RESIZE CHARACTER

18
PRACTISE 5-1

Add another super hero to your game

Get icon from https://www.flaticon.com/

19

You might also like