Download presentation
Presentation is loading. Please wait.
Published byMoses Wilkinson Modified over 8 years ago
1
Intro to Pygame Lecture 05
2
What is Pygame? It is a set of Python modules designed for writing games. It makes writing games possible for beginners. import pygame
3
Base Pygame Program import pygame pygame.init() size = (400,700) screen = pygame.display.set_mode(size) clock = pygame.time.Clock() while not done: for event in pygame.event.get(): if event.type == pygame.QUIT: done = True pygame.display.flip() clock.tick(30) pygame.quit() import pygame pygame.init() size = (400,700) screen = pygame.display.set_mode(size) clock = pygame.time.Clock() while not done: for event in pygame.event.get(): if event.type == pygame.QUIT: done = True pygame.display.flip() clock.tick(30) pygame.quit()
4
Initialization This is needed before you can use any of pygame’s features. import pygame pygame.init() import pygame pygame.init()
5
Screen Makes the window the game will be played in import pygame pygame.init() size = (400,700) screen = pygame.display.set_mode(size) import pygame pygame.init() size = (400,700) screen = pygame.display.set_mode(size)
6
Game Loop # Main Loop! while not done: for event in pygame.event.get(): if event.type == pygame.QUIT: done = True screen.fill(blue) pygame.display.flip() clock.tick(30) # Main Loop! while not done: for event in pygame.event.get(): if event.type == pygame.QUIT: done = True screen.fill(blue) pygame.display.flip() clock.tick(30)
7
Quitting This isn’t necessary, but it cleanly exits the program pygame.quit()
8
RGB Colours RGB is short for red, green, and blue Range from 0 to 255. white = (255,255,255) black = (0,0,0) red = (255,0,0) green = (0,255,0) blue = (0,0,255) white = (255,255,255) black = (0,0,0) red = (255,0,0) green = (0,255,0) blue = (0,0,255)
9
Normal Graphics
10
Pygame Graphics
11
Filling in the Background We usually need to fill the background in every loop screen.fill(blue)
12
Pygame drawing We can draw any kind of basic shapes in Python
13
How to Draw in Pygame We use the pygame.draw function pygame.draw.rect(Surface, color, Rect) pygame.draw.circle(Surface, color, pos, radius) pygame.draw.ellipse(Surface, color, Rect) pygame.draw.line(Surface, color, start_pos, end_pos, width) pygame.draw.rect(Surface, color, Rect) pygame.draw.circle(Surface, color, pos, radius) pygame.draw.ellipse(Surface, color, Rect) pygame.draw.line(Surface, color, start_pos, end_pos, width)
14
How Do I Remember All That Easy: go to the documentation http://www.pygame.org/docs/ref/draw.html
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.