[Solved] How to execute event repeatedly in Python?

Here’s a simple example using a timer. The screen is filled with a color that changes every 0.4 seconds. import pygame import itertools CUSTOM_TIMER_EVENT = pygame.USEREVENT + 1 my_colors = [“red”, “orange”, “yellow”, “green”, “blue”, “purple”] # create an iterator that will repeat these colours forever color_cycler = itertools.cycle([pygame.color.Color(c) for c in my_colors]) pygame.init() pygame.font.init() … Read more

[Solved] How to allow caps in this input box program for pygame?

If you change the corresponding code to: elif inkey <= 127: if pygame.key.get_mods() & KMOD_SHIFT or pygame.key.get_mods() & KMOD_CAPS: # if shift is pressed or caps is on current_string.append(chr(inkey).upper()) # make string uppercase else: current_string.append(chr(inkey)) # else input is lower That should work. If you want more info on keyboard modifier states look here 1 … Read more

[Solved] What type of animation file should I add to a pygame game? [closed]

Most games use images (for example .png) to create animation frame by frame. Often all frames are in the one file like this: http://www.ucigame.org/Gallery/images/char9.png You (as game developer) have to draw appropriate frame every 1/25 second (to get 25 FPS). Game libraries (like PyGame) are there to help you with that – mostly they use … Read more

[Solved] Why do I get a black screen?

1. Your WHITE Variable is wrong. That is Black in RGB Format. White is (255,255,255) 2. You are filling the screen and immediately after that you update it. First fill the screen and THEN you can draw your players on top. windowSurface.fill(WHITE) #Do drawing here pygame.display.update() solved Why do I get a black screen?

[Solved] What’s the error in this pygame program? [closed]

for event in pygame.event.get(): if event.type==QUIT: pygame.quit() sys.exit() pygame.event.get() gives you all the events that occurred since the last time you called it. This loop uses all the events that are currently available. Therefore, when interface() is called, and it tries to pygame.event.get() again, there are no more events left to check for key presses … Read more

[Solved] The if statement is not registering variables changing

You have functions such as def car1 (x1,y1): gameDisplay.blit(car1IMG,(x1,y1)) which will blit the global image car1IMG. Then in your game_loop function you write car1IMG = pygame.image.load(‘textures\car1.png’) which creates a local variable with the same name. So everything in your game_loop function will always use the local variable instead of the global, unless you specify that … Read more

[Solved] Identation Error

Your code, properly indented, should look like this: def update_bullets(bullets): “””Update position of bullets and gets rid of old bullets””” #Update bullet position bullets.update() # Get rid of bullets that had dissapeared for bullet in bullets.copy(): if bullet.rect.bottom <= 1: bullets.remove(bullet) print(len(bullets)) Python code requires proper indentation at all times. Whitespace matters (unlike C)! I … Read more

[Solved] Simple pygame program to fix [closed]

After your # Add new baddies_type_1 at the top of the screen, if needed. code, it looks like you actually add the baddie with this line: baddies_type_1.append(newbaddie_type_1) You don’t appear to be doing that with your goodies code. Try adding: goddies_type_1.append(newgoddie_type_1) after your # Add new goddies_type_1 at the top of the screen, if needed. … Read more

[Solved] what program should i use to code using the Python PyGame module [closed]

You can install pygame with following this; open cmd(console) and write this codes: pip install pygame Easiest way for this. For mac; sudo pip install pygame And yes you have to write this in terminal Or download from here http://www.pygame.org/download.shtml manually. But my little advice is, pygame is not so simple, first improve yourself in … Read more