Drawing shapes with PyGame
Requirements:
- Python
- Pygame
Step 1: Getting the starter
Mentors' note:
The code below is the starter you need to give to the ninjas, it imports all the needed packages for the game and has an infinite loop that updates the screen with new information
Make them run this code once (which just starts a black game screen) and make them change the size of the Display (by changing the values in set_mode), let them play with wider or taller screens, square and rectangle screens
- [ ] Simply copy and paste this in a new file called "game.py"
- [ ] Run the code and see what it does (reminder: to run the code you need to open a terminal in the folder and type
python game.py
)
# Base from http://usingpython.com/pygame-intro/
# Importing pygame
import pygame, sys
from pygame.locals import *
# Initialize module
pygame.init()
# Create a window of 300 width and 300 height
DISPLAY = pygame.display.set_mode((300,300))
# Names the window "My game"
pygame.display.set_caption('My game')
# Runs the game
while True:
# ------- CODE HERE -------
# -------------------------
# get all events
for event in pygame.event.get():
# quit when user want to quit
if event.type == QUIT:
pygame.quit()
sys.exit()
# refresh display
pygame.display.update()