Questions tagged [pygame]

Pygame is a set of Python modules designed for writing video games. Use this tag only if you are using the Pygame library and not if you have a question about programming a game in Python in general.

Pygame is a free Python library released under the Lesser General Public License (GNU LGPL) version 2.1 (according to its GitHub page), aimed at creating video games. It's built on top of , is highly portable and runs on nearly every platform and operating system.

References

Documentation

Games using Pygame

19430 questions
3
votes
1 answer

Using joystick module from PyGame

Exact code with commenting can be found here, or here. while done==False: for event in pygame.event.get(): if event.type == pygame.QUIT: done=True if event.type == pygame.JOYBUTTONDOWN: print("Joystick button pressed.") …
user10332166
3
votes
1 answer

Apple won't disappear when my snake is touching it

This is my first post! I am trying to make a snake clone in Pygame, but when my snake touches the apple, it won't teleport to another place. Here's my code: import pygame import time import random pygame.init() wh =…
Salmon
  • 31
  • 2
3
votes
1 answer

Python - Pygame - Class __init___ question/Not drawing

I'm learning OOP and I have a few questions. When the initiliazer is called, is the code automatically processed? Cause if that's the case, I don't understand why my game isn't drawing the rectangle i ask it to draw in the init part of the player…
Lol Lol
  • 155
  • 1
  • 9
3
votes
1 answer

Why are my print() commands showing doubles in the console?

Below is some code I'm working on that is printing doubles to the CMD window. It's not a huge issue that I'm seeing doubles, I'm just worried that sooner or later it may turn into a larger problem when this program grows. This is an example of what…
HDPZR
  • 73
  • 6
3
votes
1 answer

Getting the name of variables in a list

I want to get the name of the variable in a list with the index. For example: a = 1 b = 2 list = [a, b] print(list[0]) and the output is 1 Is there a way to get "a" as a String instead of 1? Also, the above code is just an example. I am coding…
Coco Liliace
  • 311
  • 5
  • 14
3
votes
2 answers

Getting rid of recursion in pygame

I made a game in pygame which involves main menu, game loop, victory screen and crash screen. My game works how I want it to work, but I know everytime I change a screen, I am just going deeper into the loop and game can crash when i reach 1000…
RaZiiiGG
  • 203
  • 1
  • 15
3
votes
2 answers

py2app built app displays `ERROR: pygame.macosx import FAILED` on other machines

Trying to build an app on the Mac using py2app. Got everything working fine on my machine, but when moving the app to another, it crashes and the console displays this error. ERROR: pygame.macosx import FAILED Anybody have a solution to this?
scum
  • 3,202
  • 1
  • 29
  • 27
3
votes
7 answers

How to fade from one colour to another in pygame?

How would I fade from one colour into another in pygame? I want to slowly change the colour of a circle from green to blue to purple to pink to red to orange to yellow to green. How would I do that? At the moment, I'm using def colour(): …
Jacques Amsel
  • 1,061
  • 2
  • 14
  • 30
3
votes
2 answers

Tab out of Pygame fullscreen window without crashing it

So I'm using Pygame to create a fancy display for a program I am writing. I chose Pygame because it's easy to get started and does a great job with animations. I want the display to be as big as I can make it so as much information can be shown as…
Conrad Selig
  • 361
  • 2
  • 11
3
votes
1 answer

How to implement sound in pygame?

I have a problem with programming the sound effects in Space Invaders wrote in python. Entire game is divided into modules like the main loop, game functions, settings etc. This is a part of the code that create new bullet and then adds it into the…
ca.ribou
  • 39
  • 10
3
votes
1 answer

Switching menus in pygame

I changed the structure of my code, but I am still running into problems when I crash, and I want to restart the game. My idea is to build 3 "screens": main menu, game, restart. I am having no problem entering the main menu, when I run the program,…
RaZiiiGG
  • 203
  • 1
  • 15
3
votes
1 answer

How to simulate realistic speed in PyGame?

I want to define a realistic walking speed (meters per second) for all worker objects. How can I do it? Currently I have the parameter speed in the code. This parameter is initialised as randint(2, 4) - random integer between 2 and 4. But this value…
ScalaBoy
  • 3,254
  • 13
  • 46
  • 84
3
votes
1 answer

Delay between losing health

I've recently implemented a health system (albeit a very basic one) into my game and it works in the sense that if my player is colliding with the enemy, I lose health. However, the problem that I'm facing is that I lose health 60 times a second as…
Goose _
  • 267
  • 1
  • 9
3
votes
1 answer

ImportError for every third party library

I know there are similar questions, but I've looked at them and none of them are what I'm looking for I'm running Python 3.7.0 on Windows 10, and I installed pygame-1.9.4 a few weeks ago, and it's been working fine until yesterday. I have a file…
Reuben Z
  • 33
  • 3
3
votes
1 answer

pygame: screen wipes upon minimize and restore- turns blue upon next update

I'm writing this because, out of nowhere, my pygame program has started acting up. I'm no stranger to pygame and I'd say I know it better than most. I've been using it for years and out of nowhere this bug, or whatever it is, has me stumped. The…
Lucas Young
  • 119
  • 1
  • 9