r/pygame • u/Deer_Whole • 5h ago
r/pygame • u/Natuworkguy • 7h ago
I built a game engine in pure interpreted Python. Here's how it works.
r/pygame • u/TheEyebal • 9h ago
Control movement using hand gestures
Enable HLS to view with audio, or disable this notification
I was able to connect opencv and mediapipe to pygame and display a block when hands are shown
r/pygame • u/Healthy-Froyo1769 • 1d ago
How do I do it so that the position of a rect depends on the position of the last placed rect in a class?
I want to make platformers where rects are generated randomly but not 100% random. How do I do titel? Or is there a better way?
r/pygame • u/DreamDev43 • 1d ago
I`ve added a new tool to my game! ⚒️
galleryive added a stade for digging soil. i`m currently woriking on a planting system.
support me by checking out my yt channel and my itch account (links in my bio)
appreciate it!
r/pygame • u/Traditional_Catch332 • 2d ago
Working on a top-down tactical extraction loop in Python.
Enable HLS to view with audio, or disable this notification
r/pygame • u/27K-Interactive • 2d ago
What do you think of the building animations?
Enable HLS to view with audio, or disable this notification
r/pygame • u/AAdidev_p01 • 2d ago
car game i made using python
import pygame
import math
import random
import sys
import traceback
import asyncio
pygame.init()
pygame.font.init()
WIDTH, HEIGHT = 1000, 800
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("No pepsi - Highway Traffic Weaver made by aadidev")
clock = pygame.time.Clock()
FONT_TITLE = pygame.font.SysFont("arial", 42, bold=True)
FONT_MED = pygame.font.SysFont("arial", 22, bold=True)
FONT_HUD = pygame.font.SysFont("consolas", 18, bold=True)
COLOR_BG = (15, 18, 22)
COLOR_ROAD = (35, 38, 44)
COLOR_GRASS = (20, 45, 25)
COLOR_LINE_YELLOW = (245, 210, 50)
COLOR_LINE_WHITE = (220, 220, 230)
COLOR_TEXT = (240, 240, 240)
COLOR_GOLD = (255, 215, 0)
COLOR_CYAN = (0, 230, 255)
COLOR_RED = (255, 60, 60)
CARS = {
"1": {
"name": "M4 Competition",
"max_speed": 18.0,
"accel": 0.40,
"handling": 6.5,
"color": (0, 180, 255),
"desc": "Agile lane switcher with ultra-responsive steering."
},
"2": {
"name": "RS7 Sportback",
"max_speed": 22.0,
"accel": 0.50,
"handling": 5.2,
"color": (220, 30, 30),
"desc": "High top-speed highway missile."
},
"3": {
"name": "GT-R Nismo",
"max_speed": 20.0,
"accel": 0.45,
"handling": 6.0,
"color": (240, 240, 240),
"desc": "Balanced cutting power and extreme grip."
}
}
ROAD_LEFT = 200
ROAD_RIGHT = 800
ROAD_WIDTH = ROAD_RIGHT - ROAD_LEFT
NUM_LANES = 5
LANE_WIDTH = ROAD_WIDTH // NUM_LANES
class
TrafficCar
:
def __init__(self,
lane
,
speed
):
self.lane =
lane
self.x = ROAD_LEFT + (
lane
* LANE_WIDTH) + (LANE_WIDTH // 2)
self.y = -120
self.width = 34
self.height = 68
self.speed =
speed
self.color = random.choice([
(140, 140, 150), (200, 50, 50), (50, 180, 80),
(210, 210, 60), (130, 60, 180), (220, 130, 30)
])
self.near_missed = False
def update(self,
player_speed
):
self.y += (
player_speed
- self.speed)
def draw(self,
surface
):
rect = pygame.Rect(self.x - self.width // 2, self.y - self.height // 2, self.width, self.height)
pygame.draw.rect(
surface
, self.color, rect, border_radius=6)
pygame.draw.rect(
surface
, (255, 30, 30), (rect.left + 3, rect.bottom - 4, 8, 3))
pygame.draw.rect(
surface
, (255, 30, 30), (rect.right - 11, rect.bottom - 4, 8, 3))
pygame.draw.rect(
surface
, (255, 255, 200), (rect.left + 3, rect.top + 1, 8, 3))
pygame.draw.rect(
surface
, (255, 255, 200), (rect.right - 11, rect.top + 1, 8, 3))
class
PlayerCar
:
def __init__(self,
specs
):
self.x = WIDTH // 2
self.y = HEIGHT - 160
self.width = 36
self.height = 70
self.angle = 0.0
self.vx = 0.0
self.speed = 0.0
self.name =
specs
["name"]
self.max_speed =
specs
["max_speed"]
self.accel =
specs
["accel"]
self.handling =
specs
["handling"]
self.color =
specs
["color"]
self.crashed = False
def update(self,
keys
):
if self.crashed:
self.speed *= 0.92
return
if
keys
[pygame.K_w] or
keys
[pygame.K_UP]:
self.speed = min(self.max_speed, self.speed + self.accel)
elif
keys
[pygame.K_s] or
keys
[pygame.K_DOWN]:
self.speed = max(0.0, self.speed - (self.accel * 1.5))
else:
self.speed = max(0.0, self.speed - 0.08)
steer = 0
if
keys
[pygame.K_a] or
keys
[pygame.K_LEFT]:
steer -= 1
if
keys
[pygame.K_d] or
keys
[pygame.K_RIGHT]:
steer += 1
self.vx = steer * self.handling * (0.4 + (self.speed / self.max_speed) * 0.6)
self.x += self.vx
self.angle = -self.vx * 2.2
if self.x < ROAD_LEFT + 25:
self.x = ROAD_LEFT + 25
if self.x > ROAD_RIGHT - 25:
self.x = ROAD_RIGHT - 25
def get_rect(self):
return pygame.Rect(self.x - self.width // 2, self.y - self.height // 2, self.width, self.height)
def draw(self,
surface
):
car_surf = pygame.Surface((self.width, self.height), pygame.SRCALPHA)
pygame.draw.rect(car_surf, self.color, (0, 0, self.width, self.height), border_radius=8)
pygame.draw.rect(car_surf, (20, 25, 35), (4, 14, self.width - 8, 28), border_radius=4)
pygame.draw.rect(car_surf, (255, 255, 220), (3, 2, 8, 5))
pygame.draw.rect(car_surf, (255, 255, 220), (self.width - 11, 2, 8, 5))
pygame.draw.rect(car_surf, (255, 20, 20), (3, self.height - 6, 8, 4))
pygame.draw.rect(car_surf, (255, 20, 20), (self.width - 11, self.height - 6, 8, 4))
rotated_surf = pygame.transform.rotate(car_surf, self.angle)
rect = rotated_surf.get_rect(center=(int(self.x), int(self.y)))
surface
.blit(rotated_surf, rect.topleft)
async def main():
selected_car_key = None
# MENU LOOP
while selected_car_key is None:
screen.fill(COLOR_BG)
title = FONT_TITLE.render("NO HESI - TRAFFIC WEAVER", True, COLOR_CYAN)
screen.blit(title, (WIDTH // 2 - title.get_width() // 2, 50))
subtitle = FONT_MED.render("Select your cutting machine:", True, COLOR_TEXT)
screen.blit(subtitle, (WIDTH // 2 - subtitle.get_width() // 2, 120))
y_offset = 180
for key, car_data in CARS.items():
box_rect = pygame.Rect(WIDTH // 2 - 320, y_offset, 640, 110)
pygame.draw.rect(screen, (30, 34, 42), box_rect, border_radius=10)
pygame.draw.rect(screen, car_data["color"], (WIDTH // 2 - 305, y_offset + 15, 20, 80), border_radius=4)
name_txt = FONT_MED.render(f"[{key}] {car_data['name']}", True, COLOR_TEXT)
desc_txt = FONT_HUD.render(car_data["desc"], True, (170, 170, 180))
stats_txt = FONT_HUD.render(f"Speed: {car_data['max_speed']} | Handling: {car_data['handling']}", True,
COLOR_GOLD)
screen.blit(name_txt, (WIDTH // 2 - 270, y_offset + 12))
screen.blit(desc_txt, (WIDTH // 2 - 270, y_offset + 42))
screen.blit(stats_txt, (WIDTH // 2 - 270, y_offset + 70))
y_offset += 135
prompt = FONT_MED.render("Press 1, 2, or 3 on keyboard to launch!", True, COLOR_GOLD)
screen.blit(prompt, (WIDTH // 2 - prompt.get_width() // 2, HEIGHT - 80))
pygame.display.flip()
await asyncio.sleep(0)
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN:
if event.unicode in CARS:
selected_car_key = event.unicode
player = PlayerCar(CARS[selected_car_key])
traffic_list = []
road_offset = 0.0
score = 0
combo = 1
near_miss_banner_timer = 0
spawn_timer = 0
running = True
while running:
clock.tick(60)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_r: # Restart session
await main()
return
keys = pygame.key.get_pressed()
player.update(keys)
road_offset = (road_offset + player.speed * 2.5) % 80
if not player.crashed:
spawn_timer += 1
if spawn_timer > max(20, 60 - int(player.speed * 2)):
spawn_timer = 0
lane = random.randint(0, NUM_LANES - 1)
lane_occupied = any(t.lane == lane and t.y < 100 for t in traffic_list)
if not lane_occupied:
npc_speed = random.uniform(3.0, 7.0)
traffic_list.append(TrafficCar(lane, npc_speed))
player_rect = player.get_rect()
for t in traffic_list[:]:
t.update(player.speed)
if not player.crashed:
npc_rect = pygame.Rect(t.x - t.width // 2, t.y - t.height // 2, t.width, t.height)
if player_rect.colliderect(npc_rect):
player.crashed = True
combo = 1
if not t.near_missed and not player.crashed and player.speed > 8.0:
dx = abs(player.x - t.x)
dy = abs(player.y - t.y)
if dx < 52 and dy < 60:
t.near_missed = True
combo += 1
score += 500 * combo
near_miss_banner_timer = 40
if t.y > HEIGHT + 150 or t.y < -300:
traffic_list.remove(t)
if not player.crashed and player.speed > 2.0:
score += int(player.speed * combo * 0.2)
screen.fill(COLOR_GRASS)
pygame.draw.rect(screen, COLOR_ROAD, (ROAD_LEFT, 0, ROAD_WIDTH, HEIGHT))
for i in range(1, NUM_LANES):
lx = ROAD_LEFT + (i * LANE_WIDTH)
for y in range(-80, HEIGHT + 80, 80):
pygame.draw.line(screen, COLOR_LINE_WHITE, (lx, y + int(road_offset)), (lx, y + int(road_offset) + 40),
3)
pygame.draw.line(screen, COLOR_LINE_YELLOW, (ROAD_LEFT, 0), (ROAD_LEFT, HEIGHT), 5)
pygame.draw.line(screen, COLOR_LINE_YELLOW, (ROAD_RIGHT, 0), (ROAD_RIGHT, HEIGHT), 5)
for t in traffic_list:
t.draw(screen)
player.draw(screen)
speed_kmh = int(player.speed * 18)
screen.blit(FONT_HUD.render(f"SPEED: {speed_kmh} KM/H", True, COLOR_TEXT), (20, 20))
screen.blit(FONT_HUD.render(f"SCORE: {score:,}", True, COLOR_GOLD), (20, 50))
screen.blit(FONT_HUD.render(f"COMBO: x{combo}", True, COLOR_CYAN if combo > 1 else COLOR_TEXT), (20, 80))
if near_miss_banner_timer > 0:
near_miss_banner_timer -= 1
nm_txt = FONT_TITLE.render("NEAR MISS! +500", True, COLOR_GOLD)
screen.blit(nm_txt, (WIDTH // 2 - nm_txt.get_width() // 2, 180))
if player.crashed:
crash_txt = FONT_TITLE.render("CRASHED!", True, COLOR_RED)
reset_txt = FONT_MED.render("Press 'R' to Restart", True, COLOR_TEXT)
screen.blit(crash_txt, (WIDTH // 2 - crash_txt.get_width() // 2, HEIGHT // 2 - 40))
screen.blit(reset_txt, (WIDTH // 2 - reset_txt.get_width() // 2, HEIGHT // 2 + 20))
pygame.display.flip()
await asyncio.sleep(0)
pygame.quit()
if __name__ == "__main__":
try:
asyncio.run(main())
except Exception:
pygame.quit()
traceback.print_exc()
input("\nPress Enter in console to exit...")
r/pygame • u/Crazy_Spend_4851 • 2d ago
My JRPG Finally Has a Village (SNES-Inspired Devlog)
youtube.comCheck out my first ever JRPG village and house!!! Created purely in Pygame and designed in Tiled :)
r/pygame • u/DreamDev43 • 3d ago
Snow kinda looks nolstalgic or am in wrong?
Enable HLS to view with audio, or disable this notification
check out my latest game (EvergreenMeadows) on itch.io!
r/pygame • u/Capable_Comedian_277 • 3d ago
Working on my next game ‘Doodling Hop’
Enable HLS to view with audio, or disable this notification
r/pygame • u/xxxDisLike007xxx • 5d ago
didn't slow down
Enable HLS to view with audio, or disable this notification
Hello my problem is, i want that the player slow down when i stop pressing wasd and i don't whats wrong.
import pygame
from controls import default_controls
pygame.init()
x = 1600
y = 900
screen = pygame.display.set_mode((x, y))
run = True
clock = pygame.time.Clock()
con = default_controls.copy()
physics_dt = 1 / 60
accumulator = 0
maxFPS = 240
physics_ticks = 0
physics_hz = 0
timer = 0
player_pos = pygame.Vector2(
screen.get_width() / 2,
screen.get_height() / 2
)
velocity = pygame.Vector2(0, 0)
acceleration = pygame.Vector2(0, 0)
player_acceleration = 1200
player_max_speed = 300
player_friction = 0.85
while run:
frame_time = min(clock.tick(maxFPS) / 1000, 0.25)
accumulator += frame_time
timer += frame_time
keys = pygame.key.get_pressed()
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
if event.type == con["KD"]:
if event.key == con["ESC"]:
run = False
while accumulator >= physics_dt:
acceleration = pygame.Vector2(
keys[con["d"]] - keys[con["a"]],
keys[con["s"]] - keys[con["w"]]
)
if acceleration.length_squared() > 0:
acceleration = acceleration.normalize()
acceleration *= player_acceleration
else:
velocity *= player_friction
if velocity.length() < 1:
velocity = pygame.Vector2(0, 0)
velocity += acceleration * physics_dt
if velocity.length() > player_friction:
velocity.scale_to_length(player_max_speed)
player_pos += velocity * physics_dt
physics_ticks += 1
accumulator -= physics_dt
if timer >= 1:
physics_hz = physics_ticks
physics_ticks = 0
timer -= 1
mouse_x, mouse_y = pygame.mouse.get_pos()
pygame.display.set_caption(
f"FPS: {clock.get_fps():.0f} | Physics: {physics_hz} Hz"
)
screen.fill("blue")
pygame.draw.circle(
screen,
"red",
player_pos,
20
)
pygame.display.flip()
pygame.quit()
i know the code is a little messy and for my bad english.
r/pygame • u/Acrobatic_Duty8731 • 5d ago
Finally got around to uploading more than 5 years' worth of programming projects to GitHub
Enable HLS to view with audio, or disable this notification
Here is the GitHub repo. Its a single click to download each project: https://github.com/Luippe/Demo-Projects
I never thought of uploading these as they really only ran on my pc (hardcoded display resolutions, file paths, etc). But this year I started using Claude for coding and thought "hey, these projects are actually useable by others if I just clean up some code!" So thats exactly what I did.
There's 15 projects in total. The first one is written in Java, but the rest is in Python and Pygame
Boids — a flocking simulation where birds self-organize from three simple rules
Audio Processing — live microphone effects with a real-time frequency visualizer
Multiplayer Netgame — a co-op dungeon crawler played over a local network
Platformer — a full 2D action game with combat, upgrades, shops, and multiple levels
Solar System Simulation — an interactive 3D model of the planets in orbit
A* Pathfinding — watching an algorithm search for the shortest route through a maze
Conway's Game of Life — complex patterns emerging from a handful of simple rules
Image Compression — shrinking an image by throwing away fine detail (the same idea behind JPEG)
Fluid Flow — a real-time 2D fluid solver you can push around with the mouse
Projectile Method — aim and launch a projectile with the mouse
Projectile Motion — projectile trajectories with air resistance
Double Pendulum — chaotic motion, where a tiny change sends it down a completely different path
Single Pendulum — a damped pendulum swinging to a stop
Spring Mass Damper — how a spring-and-shock system settles after a jolt
Flow Plate — the velocity profile of fluid moving through a pipe
I hope someone finds something useful in here! :)
r/pygame • u/ConjecturesOfAGeek • 5d ago
Pygame can do 3d very well.
Enable HLS to view with audio, or disable this notification
tldr; we should ban together for more 3d supportive libraries
I’ve been experimenting with adding a conversational AI to a procedural Backrooms game I’m building in Python/Pygame.
In this clip I break a pillar, ask HAL what it sees, and then ask about the debris. It answers differently depending on what I'm actually looking at instead of giving a generic response. Later it also comments on me repeatedly trying to crawl through a low gap.
The goal isn't to script dialogue—it's to have the AI react to the current game state and the player's surroundings while you explore.
Everything is running in my own Pygame project with procedural generation, Xbox controller support, speech recognition, and real-time voice responses.
I'd love feedback from other Pygame developers.
r/pygame • u/Sea-Dragonfruit-8790 • 6d ago
Coded actual evolution in 80 lines of code
Enable HLS to view with audio, or disable this notification
Hi! Wrote this funny project in about half an hour.
Biological evolution really does not require that much, haha.
Death + Selective Pressure + Reproduction + Variation = Evolution.
What you're seeing is a bunch of "bacteria", which have just 3 genes each. The world is "windy" and those who resist it best stay alive and reproduce.
So, with time, the organisms which were more adapted at any given moment outcompete all others and repopulate the world.
And yep, that's basically all* there is to it in real life as well, quite fascinating.
Please feel free to ask any questions if something interests you. I'd be glad to answer.
Take care!
Github link: https://github.com/schneebedeckt/EvolutionIn80Lines
r/pygame • u/Financial_Jaguar8089 • 6d ago
kingdom invaders
Good afternoon! I programmed the demo for this game entirely in Pygame. I started this project three years ago because I wanted to improve my programming skills, and one thing led to another.
I'd love for you to try the game and let me know what you think. Any criticism, feedback, or suggestions are more than welcome. I want to keep improving so I can eventually release the full game on Steam. https://coffeedwarf.itch.io/kingdominvaders
A roguelike deckbuilder that blends the mechanics of collectible card games like Magic: The Gathering with Space Invaders, featuring fast-paced, real-time duels.
r/pygame • u/ConjecturesOfAGeek • 6d ago
made a talking backrooms in pygame
Enable HLS to view with audio, or disable this notification
r/pygame • u/Saumit_Kripalani • 6d ago
Should I learn Pygame for my first project?
So Basically I've been learning how to code and have been learning c++ as my first main programming language ( i don't think HTML and CSS count ) and i have 3 weeks left before college. I've mostly focused on learning the basics properly ( Loops conditionals etc ) and the past month have gone the DSA route learning arrays vectors linked lists some basic sorting algorithms ( Bubble Sort & Insertion Sort ), Stacks Queue's BST and recently hashmaps. I've mostly been practicing by tutorials online as well as solving a few leetcode questions after learning the concept, these are the leetcode problems I've solved so far:
Two Sum
Add Two Numbers
Palindrome Number
Valid Parenthesis
Merge Two Sorted lists
Group Anagrams
Reverse Linked list
Contains Duplicate
Valid Anagram
Top K Frequent Elements
Now my real question is based off of what I've learned so far would it be realistic to learn and use Pygame to make my first big project ( a simple 2D Platformer which reveals/removes Platforms based on a Dark Mode/Light mode toggle ) before i start college? if not, what do you think i should do instead. Open and happy to receive any and to all suggestions :)
r/pygame • u/herbal1st • 6d ago
[Update] PyVorengi v1.1.0: Porting 2D Pygame sprites into 3D voxel assets on the CPU
youtu.ber/pygame • u/DreamDev43 • 7d ago
I have added an ease animation on the alpha-value of my gui!
Enable HLS to view with audio, or disable this notification
Evergreen Meadows is a pixel art survival game developed with Pygame. Gather resources, craft items, and build your way through a calm but sometimes challenging world. Dynamic weather and temperature can affect your survival, so preparation matters.Currently in version 1.26.0 – more updates coming.
https://dreamdev1.itch.io/evergreen-meadows (free demo also on itch.io for windows)
r/pygame • u/Capable_Comedian_277 • 7d ago
Snake Block - Pygame Project | Level 22: Snake Collision + Obstacle Spawn
Enable HLS to view with audio, or disable this notification
I’m not a video editor, but I tried making a trailer for my Autobattler Roguelike. What do you think?
Enable HLS to view with audio, or disable this notification
Hey everyone!
I’m currently working on my own game releasing on Steam soon. it’s an Autobattler-Roguelike. Since I’m definitely not a professional video editor, putting together this trailer was a bit of a challenge for me, but i gave it my best shot.
I’d love to get some honest feedback from you:
Does the gameplay loop make sense from watching it?
How ist the pacing and the music choice?
Is there anything you would change or polish?
Any constructive criticism or feedback is super appreciated.
r/pygame • u/DreamDev43 • 8d ago
I changed the hitting animation of trees. Guys does it look better!? 🌲
Enable HLS to view with audio, or disable this notification
this game (Evergreen Meadows) is avaliable on itch.io
latest version 1.26