Skip to content
am102841-code edited this page Aug 7, 2026 · 1 revision

Pygame

This page is for learning and practicing Pygame with Python. I want to use it to learn how games work and build more interactive projects.


What is Pygame?

Pygame is a Python library used to create games and other interactive programs.

It can be used for things like:

  • Graphics
  • Game windows
  • Keyboard input
  • Mouse input
  • Sounds
  • Music
  • Animations
  • Game physics
  • Collision detection

What I Want to Learn

Some of the Pygame concepts I want to learn and practice:

  • Creating a game window
  • Game loops
  • Drawing shapes
  • Loading images
  • Sprites
  • Keyboard controls
  • Mouse controls
  • Collision detection
  • Movement
  • Gravity
  • Jumping
  • Game physics
  • Animations
  • Sound effects
  • Music
  • Fonts and text
  • Menus
  • Buttons
  • Game states
  • Timers
  • Levels
  • Score systems
  • Health systems
  • Saving game data

Examples From Dungeon Platformer

I have used many of these concepts in my Dungeon Platformer project.

Player Movement

The player can move left and right using keyboard input.

keys = pygame.key.get_pressed()

if keys[pygame.K_LEFT]:
    player.x -= player_speed

if keys[pygame.K_RIGHT]:
    player.x += player_speed

This uses pygame.key.get_pressed() to check whether a key is currently being held down.


Jumping

The player can jump when the jump key is pressed.

if keys[pygame.K_SPACE] and on_ground:
    player_velocity_y = jump_strength

The on_ground condition prevents the player from continuously jumping while already in the air.


Gravity

The player needs to fall back down after jumping.

player_velocity_y += gravity
player.y += player_velocity_y

The vertical velocity increases because of gravity, which creates the falling effect.

This is one of the places where I started using physics concepts in a game.


Collision Detection

The game checks whether the player is touching objects such as platforms or obstacles.

if player.colliderect(platform):
    # Handle collision

colliderect() checks whether two pygame.Rect objects overlap.

I use collision detection for things like:

  • Platforms
  • Spikes
  • Obstacles
  • Other game objects

Random Obstacles

The Dungeon Platformer uses randomness to make some obstacles appear differently.

import random

obstacle_x = random.randint(100, 700)

Using random can make levels less predictable and allow different situations to happen during gameplay.


Loading Images

The game uses image files for things such as the player.

player_image = pygame.image.load("KNIGHT.png")

The image can then be used when drawing the player onto the screen.


Drawing Objects

Pygame can draw shapes directly onto the screen.

pygame.draw.rect(screen, platform_color, platform)

This can be useful for creating simple platforms, obstacles, and other objects without needing an image for every object.


Game Loop

The game repeatedly runs its main game loop while the game is active.

A simplified version looks like:

running = True

while running:
    # Handle events
    # Update game
    # Draw game
    # Update display

The game loop is what allows the game to continuously:

  1. Receive player input
  2. Update objects
  3. Check collisions
  4. Draw the new frame
  5. Repeat

Dungeon Platformer Features

Some features I have worked on in the Dungeon Platformer include:

  • Player movement
  • Jumping
  • Gravity
  • Platforms
  • Moving platforms
  • Spikes
  • Random obstacles
  • Multiple levels
  • A secret level
  • Player images
  • Collision detection
  • Level progression

The project currently has multiple levels and is helping me understand how different game systems can work together.


Projects I Want to Build

Simple Arcade Games

Start with smaller games to practice the basics.

Possible projects:

  • Pong
  • Snake
  • Breakout
  • Flappy Bird-style game
  • Space shooter
  • Dodge game
  • Reaction game

Platformer

Continue improving my platformer projects with:

  • Player movement
  • Jumping
  • Gravity
  • Platforms
  • Enemies
  • Obstacles
  • Levels
  • Checkpoints
  • Health
  • Score

Dungeon Game

A larger game involving exploration and combat.

Possible features:

  • Multiple rooms
  • Enemies
  • Items
  • Health
  • Weapons
  • Coins
  • Doors
  • Keys
  • Bosses
  • Multiple levels

Concepts I Want to Practice

I want to use Pygame to practice Python concepts while building games.

Some of these include:

  • Classes
  • Objects
  • Lists
  • Dictionaries
  • Functions
  • Loops
  • Conditionals
  • Random
  • File Handling
  • JSON
  • Object-oriented game design

Game Systems I Want to Learn

I want to eventually learn how to create larger game systems, including:

  • Inventory System
  • Achievement System
  • Save System
  • Level System
  • Enemy AI
  • Dialogue System
  • Quest System
  • Shop System
  • Experience System
  • Character Stats
  • Settings Menu
  • Pause Menu

Things I Want to Try

Some ideas I want to experiment with:

  • Animated sprites
  • Particle effects
  • Screen transitions
  • Camera movement
  • Procedural generation
  • Random levels
  • Different game modes
  • Boss fights
  • Multiplayer experiments
  • Controller support
  • Better menus
  • Custom pixel art
  • More advanced game physics

I'm going to keep using Pygame to practice Python while building increasingly complex games.

Clone this wiki locally