pygame

Why do I get blank grey background instead of animations in PyGame?

谁都会走 提交于 2019-12-24 01:38:34
问题 I am creating the Environment class. The function init should build the simulated environment, while the function run should execute different events in this environment during 10 seconds. Below I share some major parts of my code. When I run env = Environment("TEST") env.run() (see below), the window with grey screen appears. Then it closes in 10 seconds. Nothing is visible in this screen. It's just a grey background. However, I do not get any error message. What am I doing wrong in the

Sequential image presentation in Pygame

£可爱£侵袭症+ 提交于 2019-12-24 01:24:10
问题 A simple problem, but i am new to Python/Pygame. I want to blit an image (old.png) and then have that image be replaced by another image (new.png) upon a keypress (spacebar): sequential presentation. Currently, the old.png remains on the surface, with new.png ending up on top of it. Here is my code: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() screen.blit(old, (display_width/2, display_height/2)) if event.type == pygame.KEYDOWN: if event.key == pygame.K

How do I collide and reduce player health in pygame?

霸气de小男生 提交于 2019-12-24 01:09:18
问题 I am coding a 2D game in python with the modules pygame and random, and I am having some problems with the code. One problem, is that neither of the players are taking any damage, which should be 10 damage for every bullet that hits out of 100 health for each of the players(The bullets and the players are sprites). The second problem, is that instead of a stabbed function, I want a way for the two players to collide, and not overlap each other, maybe using pygame.sprite.collide_rect(), so if

Python - Shoot a bullet in the direction (angle in degrees) my spaceship is facing

为君一笑 提交于 2019-12-24 00:52:21
问题 There are a lot of questions about this. But none of them have answers that solve my problem in specific, I've tried to google this all day. My problem is simple. I have this space ship that I can move and rotate around and I'm already tracking it's heading, the direction it's facing. For example in the image below the ship is heading approximately 45 degrees It goes from 0° (starting top and going clockwise) to 359° I just need to make a bullet go straight forward the direction (heading) my

How do I repeat music using pygame.mixer?

大城市里の小女人 提交于 2019-12-24 00:38:58
问题 I have created the following code that plays mp3 music using pygame.mixer. However, the music does not repeat. Any idea's on how I would make it so that the music does repeat? Here is the code: playlist = list() playlist.append ( "put music here.mp3" ) playlist.append ( "put music here.mp3" ) pygame.mixer.music.load ( playlist.pop() ) pygame.mixer.music.queue ( playlist.pop() ) pygame.mixer.music.set_endevent ( pygame.USEREVENT ) pygame.mixer.music.play() a = 0 running = True while a == 0:

pip install pygame - SDL.h file not found

匆匆过客 提交于 2019-12-24 00:34:29
问题 MacOS Sierra ➜ fun_python $ pip --version pip 9.0.1 from /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages (python 3.5) pip install pygame is giving me the following error: src/scrap.c:27:10: fatal error: 'SDL.h' file not found , error: command '/usr/bin/clang' failed with exit status 1 , #include "SDL.h" . I don't see this SDL/SDL.h file under /usr/include/... folder tree. gave me the following error. ➜ fun_python $ pip install pygame Collecting pygame Downloading

Making an .exe for pygame with cx-freeze

混江龙づ霸主 提交于 2019-12-24 00:31:02
问题 I've created a game in Python 3.2 and tried to turn it into a .exe with cx-freeze but when I try to run the .exe, I get an error. The Game import pygame, sys, random from pygame.locals import * pygame.init() mainClock = pygame.time.Clock() windowSurface = pygame.display.set_mode((800, 800)) pygame.display.set_caption("Dodger") def game(): WIDTH = 800 HEIGHT = 800 PLAYERSIZE = 20 PLAYERSPEED = 4 ENEMYSIZE = 10 ENEMYSPEED = 3 score = 0 BLACK = (0, 0, 0) WHITE = (255, 255, 255) GREEN = (0, 255,

Pygame the rectangle is not moving?

本小妞迷上赌 提交于 2019-12-24 00:20:12
问题 Hello I am new to pygame. When I am trying to move my rect right or left. The rectangle does not move from one position to other rather it expands/extends towards right or left. Why? import pygame, sys, time pygame.init() red = (255, 0, 0) gameDisplay = pygame.display.set_mode((800, 600)) pygame.display.set_caption('MyGame') move_x = 200 move_y = 200 while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() sys.exit() if event.type == pygame.KEYDOWN: if

Globals vs Parameters for Functions with the Same Parameters

£可爱£侵袭症+ 提交于 2019-12-24 00:13:56
问题 I am reading through "Making games with Python & Pygame" and I have noticed that because the author uses lots of functions with drawing in to break his code up, he uses lots of globals such as GRIDSIZE or BACKGROUNDCOLOR . I was always told that globals were generally bad, but without them, every drawing function would have ten more, repeating parameters - and I have also been told that repetition is bad. I wondered, then, is the author is correct in using globals for parameters that appear

How to make a grid in pygame

时光总嘲笑我的痴心妄想 提交于 2019-12-24 00:12:59
问题 I am trying to create a basic snake game with Python and I am not familiar with Pygame. I have created a window and I am trying to split that window up into a grid based on the size of the window and a set square size. def get_initial_snake( snake_length, width, height, block_size ): window = pygame.display.set_mode((width,height)) background_colour = (0,0,0) window.fill(background_colour) return snake_list What should I add inside window.fill function to create a grid based on width, height,