-
Notifications
You must be signed in to change notification settings - Fork 0
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.
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
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
I have used many of these concepts in my Dungeon Platformer project.
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_speedThis uses pygame.key.get_pressed() to check whether a key is currently being held down.
The player can jump when the jump key is pressed.
if keys[pygame.K_SPACE] and on_ground:
player_velocity_y = jump_strengthThe on_ground condition prevents the player from continuously jumping while already in the air.
The player needs to fall back down after jumping.
player_velocity_y += gravity
player.y += player_velocity_yThe 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.
The game checks whether the player is touching objects such as platforms or obstacles.
if player.colliderect(platform):
# Handle collisioncolliderect() checks whether two pygame.Rect objects overlap.
I use collision detection for things like:
- Platforms
- Spikes
- Obstacles
- Other game objects
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.
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.
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.
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 displayThe game loop is what allows the game to continuously:
- Receive player input
- Update objects
- Check collisions
- Draw the new frame
- Repeat
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.
Start with smaller games to practice the basics.
Possible projects:
- Pong
- Snake
- Breakout
- Flappy Bird-style game
- Space shooter
- Dodge game
- Reaction game
Continue improving my platformer projects with:
- Player movement
- Jumping
- Gravity
- Platforms
- Enemies
- Obstacles
- Levels
- Checkpoints
- Health
- Score
A larger game involving exploration and combat.
Possible features:
- Multiple rooms
- Enemies
- Items
- Health
- Weapons
- Coins
- Doors
- Keys
- Bosses
- Multiple levels
I want to use Pygame to practice Python concepts while building games.
Some of these include:
ClassesObjectsListsDictionariesFunctionsLoopsConditionalsRandomFile HandlingJSON- Object-oriented game design
I want to eventually learn how to create larger game systems, including:
Inventory SystemAchievement SystemSave SystemLevel SystemEnemy AIDialogue SystemQuest SystemShop SystemExperience SystemCharacter StatsSettings MenuPause Menu
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.
Pet Simulator Game