π Lesson 4: Set Up Your Game Window
Letβs create a Pygame window and draw your player sprite.
Step 1: Start Pygame & Create a Window
import pygame
pygame.init()
screen = pygame.display.set_mode((800, 600))
pygame.display.set_caption("Space Invader")
Quick Tips:
pygame.init()starts the engine.set_mode()picks the size.set_caption()names your window.
Step 2: Load and Draw the Player
# Save player.png in the same folder first
player_img = pygame.image.load("player.png")
player_x, player_y = 368, 500
def draw_player(x, y):
screen.blit(player_img, (x, y))
In the next lesson, you will move the player with the arrow keys.