pygame

Python Crash Course - Alien Invasion - Error

那年仲夏 提交于 2021-02-20 19:14:20
问题 I am doing the Alien Invasion project in the Python Crash Course book. When I test the code to see if the ship comes on screen the screen starts then shuts down. I have been looking through the code for hours now without finding out why. The game: import sys import pygame from settings import Settings from ship import Ship def run_game(): # Initialize pygame, settings, and screen object pygame.init() ai_settings = Settings() screen = pygame.display.set_mode( (ai_settings.screen_width, ai

Python Crash Course - Alien Invasion - Error

妖精的绣舞 提交于 2021-02-20 19:13:48
问题 I am doing the Alien Invasion project in the Python Crash Course book. When I test the code to see if the ship comes on screen the screen starts then shuts down. I have been looking through the code for hours now without finding out why. The game: import sys import pygame from settings import Settings from ship import Ship def run_game(): # Initialize pygame, settings, and screen object pygame.init() ai_settings = Settings() screen = pygame.display.set_mode( (ai_settings.screen_width, ai

Python Crash Course - Alien Invasion - Error

巧了我就是萌 提交于 2021-02-20 19:13:03
问题 I am doing the Alien Invasion project in the Python Crash Course book. When I test the code to see if the ship comes on screen the screen starts then shuts down. I have been looking through the code for hours now without finding out why. The game: import sys import pygame from settings import Settings from ship import Ship def run_game(): # Initialize pygame, settings, and screen object pygame.init() ai_settings = Settings() screen = pygame.display.set_mode( (ai_settings.screen_width, ai

Using gluLookAt() causes the objects to spin

醉酒当歌 提交于 2021-02-19 07:54:18
问题 I am making a game using OpenGL with Pygame. So far I was able to make cubes appear and make a cross hair. When I tried to implement looking around, things got... weird. I would run it and without even moving my mouse it would start spinning the screen everywhere when I used the gluLookAt() function. When I took that out, it worked but I couldn't look around. I was doing some testing and I even put in set data values to the function just to make sure that they were not changing and it still

Pygame moving an object

纵饮孤独 提交于 2021-02-19 06:29:10
问题 So I am trying to simply move an object in pygame. I have been looking up tutorials but all I can find is how to make it look like it is snowing, lol. I have been trying to implement that method into moving an object but I am having no luck. All I want to do is move an object across the screen and when it reaches the end of the screen it resets and goes again. So I am trying to move the object that I put in my code (the two polygons, line, and circle) across the screen, horizonally or

PyInstaller .exe file not working

跟風遠走 提交于 2021-02-19 06:29:06
问题 EDIT: I found out that the error is that the resources couldn't be opened. Copying the directory into the folder where the .exe is didn't fix it. I tried removing the resources from the .spec file and the size of the .exe file is now 9 MB as opposed to 52 MB so I'm pretty sure the resources are included, but somehow they can't seem to be opened by the .exe. In case anything is wrong with it, This is my .spec file - I only modified the Tree thing to include the resources, the .exe filename and

pygame: drawing order for sprite group with sprite.RenderPlain

孤者浪人 提交于 2021-02-19 02:38:24
问题 I've got a sprite group which needs to be drawn in a certain order so its sprites overlap as they should. However even when sorting the group using operator module function (sorted(self.sprites, key=attrgetter('y','x')) the order is wrong. How can I fix this behaviour? 回答1: Straightforwardly, you can't: The Group does not keep sprites in any order, so the draw order is arbitrary. Use an OrderedUpdates group instead: This class derives from pygame.sprite.RenderUpdates - Group class that tracks

drawing a diagonal ellipse with pygame

烂漫一生 提交于 2021-02-18 13:44:33
问题 Does anyone know of an easy way to draw ellipses that are not aligned to the x & y axis. I am very new to pygame so please forgive my ignorance, but I cannot find anything related to it. If no easy method exists, can someone help me in how I might draw this besides generating many many points on the ellipse and plotting all of them? 回答1: You can do that. Create a surface, draw the ellipse onto that surface and then rotate the entire surface (with the ellipse on it). Here's my test code:

drawing a diagonal ellipse with pygame

此生再无相见时 提交于 2021-02-18 13:40:31
问题 Does anyone know of an easy way to draw ellipses that are not aligned to the x & y axis. I am very new to pygame so please forgive my ignorance, but I cannot find anything related to it. If no easy method exists, can someone help me in how I might draw this besides generating many many points on the ellipse and plotting all of them? 回答1: You can do that. Create a surface, draw the ellipse onto that surface and then rotate the entire surface (with the ellipse on it). Here's my test code:

python pygame pause function

醉酒当歌 提交于 2021-02-17 06:10:27
问题 I am beginner and have a problem with my code. Here you can see a short excerpt of my code. It's a simple snake game I created but I was trying to add a pause. I got it but when I start the pause I am not able to close it. Possibly there is a basic mistake in my code so I couldn't advance. I hope you can help me. Thank you in advance! def checkquit(e): running = True pause = False for ev in e: if ev.type == pygame.QUIT: exit(0) running = True if ev.type == pygame.KEYDOWN and ev.key == pygame