/r/pygame
Pygame is a set of Python modules designed for writing games.
Pygame adds functionality on top of the excellent SDL library. This allows you to create fully featured games and multimedia programs in the python language.
Pygame is highly portable and runs on nearly every platform and operating system.
Despite the name, content related to other Python game libraries (pyglet, panda3d, etc.) is also welcome.
If asking for help with your code, please provide a link to the entire code and resources if possible. Consider making a Github account if you don't have one already.
In Python indentation is part of the language syntax and as such is extremely important.
When posting code every line must be indented an additional four spaces. You can indent the code in a text editor before pasting, or after pasting into reddit, highlight the text and press the editor button that looks like this <>
.
You can also place small amounts of code inline
by surrounding it with ticks:
`like this`
If you have a large amount of code to share it would be best use a third party site for posting code. Gist is a really good choice. For code that relies on external resources like images please create a repo on github or similar.
When posting links please provide a brief description in the comments of the thread. Failure to do so may result in post removal.
Installation notes for Microsoft Windows users
It is easier to install python32 and pygame32 even if you are running a 64-bit version of Microsoft Windows.
/r/pygame
Hi, I am developing a game using pygame and the game is very very buggy. it's a 2D tile-based game. It's very simple and the mechanics is just collision, no game physics. I need someone to handle collision and positioning of spawn that's all. Please contact me if you're interested thank you
Id like to make it so that the height of the window reduces by a given amount of pixels over a given amount of time. I've tried this through a subroutine and through putting a nested while loop in the running loop. No errors when run, on the left program it prints "three" (indicating that subroutine is indeed being called) and the window works fine at 1280x720 60fps, but no change is seen,
I mean does it work well in Pygame, or does it slow down the game?
What is this coming before I run my main game
Hey everyone,
For a while now, I’ve been working on an open-source eye-tracking Python library called EyeGestures, and I’ve been brainstorming how it might be used in gaming. Since most laptops today come with a built-in camera, gaze tracking could become a creative new way to receive user input.
This library isn’t just about detecting blinks; it tracks where the user looks and how long they gaze (dwell) on certain elements.
For example, what if you were exploring a dark dungeon, and only the area around your gaze was illuminated? Or maybe use gaze to focus on where a spell should be cast.
This isn’t just about asking what games already use gaze/eye tracking; I’m curious about the creative mechanics we could come up with. So spin your creative brains!
Best,
Hi everyone I'm trying to download Pygame on Mac OS but every time I seem to click the download link on the website nothing seems to be happening?
my OS version is macOS Sequoia 15.1
Any ideas what I can do to resolve this?
I've never used PyGame before but started messing around last month and made a Roguelite Deckbuilder type game (I have just been messing around building the game engine so ignore that the gameplay is just clones of other games and that the art is just placeholders quickly generated by AI).
- I deployed it on itch: https://elthran.itch.io/edge-of-ascension
- I also made a mobile version, which woks, but is not very smooth: https://elthran.itch.io/playground-edge-of-ascension
A lot of it was pretty challenging to build and I would love feedback on what seems right or wrong about it. I think the card UI of manipulating cards in the player's hand is weird but I can't place my finger on what is weird about it. Also, I'm not really sure if I should be loading images for each card as they are generated or should I load all images of all cards at game launch and then just reuse those loaded images? If anyone familiar with PyGame could check it out and give me any feedback that would be great because I am very new to this.
Hey guys, I'm stuck on this project where I'm trying to build a logic gates simulator in pygame. I have all my gates as PNG images, but I'm struggling to connect them with lines. The lines are being drawn as a shape on layer above pngs and can't return anything by which I can identify the connection in code. I want them to work like actual connectors
I am wondering if its possible to share pyjama simulation that I am working on the web, do we have something viable
As some of you may know, I'm creating a roguelite called "Starship Sprout." It's finished and ready to go...at least, the Itch version is ready (packaged with auto py and converted to installer with InnoSetup).
I want to publish to the MS Store but I can't get the MSIX package correctly set up. I'm following the MSIX packaging tool through, but it keeps failing to identify an exe entry point.
Anyone have any experience with this?
So at first i tried to install it on 3.13 but then i heard that it can only be installed on 3.8 or lower so i downloaded that but "pip install pygame" wont work for either and im just confused
I have a class that is used to create particle effects with a function that creates instances of the class and adds them to a group do put on the screen and display. I have one animation that is 5 frames long that ends after completing one animation. Another animation is 6 frames long and for some reason will not end.
Kind of at a loss as to why the player attack only goes off once but the enemy attack repeats constantly.
if attack_button.draw(screen, text_present):
print('Attack button clicked.')
animation_player.create_particles('slash-horizontal', player.rect.midbottom)
damage_to_enemy = enemy.take_damage(player.damage)
dialogue_text = f"You attacked the {enemy.name} and dealt {damage_to_enemy} damage."
if enemy.health > 0:
print('create enemy attack animation')
animation_player.create_particles('enemy-slash', enemy.rect.midbottom)
damage_to_player = player.take_damage(enemy.damage)
dialogue_text = dialogue_text + f" The {enemy.name} attacked you and dealt {damage_to_player} damage."
Edit:
I did some more investigating. For some reason, when I use the create_particles function and instantiate a new ParticleEffect, it is not doing anything besides the initial initialization. It doesn't do any of these print statements:
class ParticleEffect(
pygame
.
sprite
.
Sprite
):
def __init__(self, type:str, start_position:tuple[int], animation_player:AnimationPlayer, animation_frames:list[pygame.Surface], groups:list[pygame.sprite.Group], target:pygame.Rect=None) -> None:
super().__init__(groups)
self.sprite_type = type
print(f"type = {self.sprite_type}")
print(f"type = {type}")
self.animation_player = animation_player
if self.sprite_type in ['star-effect', 'lightning bolt', 'energy-smack', 'fireball-hit', 'slash-horizontal', 'slash-upward', 'enemy-slash']:
self.loop = False
else:
self.loop = True
print(f"loop = {self.loop}")
self.frame_index = 0
self.animation_speed = 0.10
self.frames = animation_frames
print(f"length of frames = {len(self.frames)}")
self.image = self.frames[self.frame_index]
self.rect = self.image.get_rect(midbottom = start_position)
self.rect_surface = pygame.Surface(self.rect.size)
self.rect_surface.fill('red')
self.target = target.midbottom
if target:
self.dx = (self.target[0] - start_position[0]) / 60
self.dy = (self.target[1] - start_position[1]) / 60
else:
self.dx = 0
self.dy = 0
so I have a school project for the end of the year. adnd uring the summer I worked on this level editor. I did follow a tutiral but most of the code is my own algorithm as some things I just couldn't find a way of doing. but using the tutrial allowed me to learn new ways of approuching certain problems and now I just fix and add stuff without tutirals (the last part where I press play I was just messing around with something before hand)
I'm having an issue. I want to read and preferably have offline pygame help, and everywhere I look says to run: "python -m pygame.docs" like it should just work for everybody with pygame installed, but it doesn't work for me (I have to run it as "python3 -m python.docs" because just plain python doesn't work at all, but that's not the issue anyway). I get the error: "/usr/bin/python3: No module named pygame.docs" and I even searched the whole file system for "pygame.docs" and there's nothing.
I'm using linux, kubuntu 24.04.1 specifically if that helps. I installed pygame by running "sudo apt install python3-pygame" since "pip install pygame" would only work if I created a venv (wasn't the case when I tried it on windows, of course linux and windows operate differently, but I wanted pygame installed globally and not just in some virtual env) and I didn't try sudo before it because many people recommended against that for various reasons, and it installed fine and I checked that by importing pygame and running help(pygame) and that printed out the help for it so it is installed.
Can anybody help me with this, I even installed "python-pygame-doc" thinking that maybe the name changed or something but I can't run that, it's just a folder that has some pygame help and example .py files but they all give just a bit of info and point to an online website for more info. I would really like offline documentation (I take laptop deep into the woods with me sometimes and let my dog run and there's no internet so that's why I really want the offline help) and it seems like consensus is pygame.docs is that but it didn't install with pygame. Please help. Thanks.
Is it possible to know if a window is fullscreen with an attribute/method of the class or do i have to keep track of it by myself?
Is there any documentation on gamepad controls for the steam deck?
Based on the existing docs not every controller uses the same button or axis values for what a player might consider identical controls.
Started work on this for a game jame
Hello, So basically I have a list of a few rects, I positioned the rects in such a way that theyre all next to each other. Now I want to create movement for my rects. I did it by just chaning x y depending on what the user clicks. But when for example the rects are in a straight line and I want it to move upwards, only the first rect should move upwards then the second should continue to move normally until its in the same position where the first rect was originally and also start moving upwards then the third should only move upwards when its again at the same position where the first rect was originally and continuing that
I used the library pygame for my tetris.
Here's a gameplay video on youtube, and the source code from github.
If you have time, please take a look on my game or my source code and if possible, give me advices to improve the gameplay, or tell me if there's any issue.
And it would be great for me if you could leave a like on youtube or github, it always makes my life better.
Hope you like it. Edit: tysm for 20 likes, can you do the same in github?
So I know the problem is:
mpos = pygame.mouse.get_pos()
if clickable.collidepoint(mpos):
amt += clickstrength
print (amt)
mpos = 0
It seems to repeat an arbitrary amount of times and I only want it to happen once!
Hello, I don't know if this the right place to ask for ideas if there's a better one you can tell me.
I'm doing this project for school that consists of a Guitar Hero style game, but instead of a guitar you play a 1 octave piano (12 tiles total). The game is done, but now I just need to add songs to play in it. To play songs, the game reads a .txt file containing rows of 12 columns each, and where I want to put a note I put a '0' there, and I have to add empty rows for silence or time without piano notes. I already made 3 songs, all by hand. My problem is that I have to sync the notes with the music (the music is an mp3 file that plays in the background) and that's the most time consuming part, each song took me between 3 and 4 hours, even worse, once I had some songs, for some reason the ones made previously get out of sync again, and sometimes they get back in sync, because it's very random and dependent on the speed at which the program can run. Any better ideas than doing it by hand? I tried converting MIDI files to the format I need and creating a simple tool to help me "compose" the songs, but it didn't work very well.
hey guys and girls, lets say you have one character that uses pygame.sprite.Sprite. how do u make the sprite collide with a group? i had been putting the one sprite in groupsingle but im sure there is a better way.