pygame

Threading issue with Pygame

笑着哭i 提交于 2019-12-25 00:23:11
问题 I am developing a small game for learning purposes. I have created a simple animation for the title screen. Since there is also a function for full screen in the code, I wanted to create a title screen that: Displayed the animation Turned into full screen when the key was activated Continued the animation at the point it was before activating full screen In order to do this, I resorted to threading . However, this is the first time I tried to do any multi-threading, and I don´t know what did

Pygame list collision

纵饮孤独 提交于 2019-12-24 21:59:58
问题 I have a map im creating in python using pygame with a player and walls: import pygame x = 25 y = 19 collision = [ [0,0,0,37],#vertical [4,23,4,27], [12,18,12,25], [13,0,13,1], [13,4,13,7], [13,10,13,11], [15,13,15,18], [15,23,15,37], [19,0,19,13], [29,25,29,26], [29,29,29,37], [35,0,35,9], [35,12,35,17], [35,21,35,26], [35,29,35,37], [36,17,36,21], [44,0,44,6], [44,10,44,17], [54,0,54,17], [0,0,19,0],#horizontal [35,0,46,0], [52,0,54,0], [13,5,19,5], [19,6,24,6], [30,6,35,6], [0,13,10,13],

Falling mechanics (gravity) in pygame

故事扮演 提交于 2019-12-24 21:34:37
问题 How would I get some mechanics for falling when in an empty space, many answers on the internet said to add gravity but I couldn't understand how they did that they just showed me a bunch of equations. Also, how would I set an image as my background? Here's my source code: import pygame pygame.init() display_width = 2560 display_height = 1440 white = (255,255,255) gameDisplay = pygame.display.set_mode((display_width,display_height)) pygame.display.set_caption('RGB') clock = pygame.time.Clock(

Pygame Key Press

[亡魂溺海] 提交于 2019-12-24 19:05:20
问题 I'm writing a basic drawing program to practice Pygame, but I have a problem I'm using key press events to change the drawing color but when you let go of the key it goes back to the default color black. I'm sure there is a easy way to fix this I just don't know how! Here is my code: import pygame from pygame.locals import * import sys RED = (255,0,0) GREEN = (0,255,0) BLUE = (0,0,255) WHITE = (255,255,255) class Draw(object): def update(self, screen): color = (0,0,0) key = pygame.key.get

I cant move my image in pygame with arrow keys

风格不统一 提交于 2019-12-24 17:25:57
问题 Can someone show me why the up down arrow keys won't move my image? I'm using Python 3 and Pygame 1.91. No errors. Just disappointment. The pertinent section are lines 65-115 (Beginning of Display function to end of Move_Paddle function). import pygame import time import sys from pygame.locals import * pygame.init() display_width = 800 display_height = 600 black = (0, 0, 0) #Colors white = (255, 255, 255) pygame.display.set_caption('Pong') #Title clock = pygame.time.Clock() #Clock gameDisplay

Pygame - rect disappears before I reach it

随声附和 提交于 2019-12-24 16:32:04
问题 I am trying to make a rectangle pop up when middle click is pressed, and stay popped up until I press left click in pygame. Here is my code: button1, button2, button3 = pygame.mouse.get_pressed() if button2 == True: pygame.draw.rect(screen, ((255, 0, 0)), (0, int(h/2), int(w/6), int(h/2)-40), 0) pygame.display.update() The thing is, when I press middle click, the rectangle appears, then disappears instantly. I have tried putting it as while button2 == 2: , but the program hangs. Thank you!!

Pygame - RuntimeError: maximum recursion depth exceeded while calling a Python object

纵饮孤独 提交于 2019-12-24 16:21:43
问题 When ever I try to run my code I constantly get this error: RuntimeError: maximum recursion depth exceeded while calling a Python object I am quite confused to why this happens, I am trying to make a picture blit and constantly move down the screen, as an object that the player has to dodge and if hits gets "killed" (Still to add collisions in). When I start to get the error is spams the shell with this: File "C:\Users\John\Desktop\Michael\V'Room External\GAME_MAIN_.py", line 195, in movement

Error with pymunk space.remove method

走远了吗. 提交于 2019-12-24 16:15:30
问题 I have a ball generator, that "generates" and adds balls(circles) to the simulation. The ball is to be removed when it hits a static poly in list s_boxes . This is done by a collision handler ball_wall_collision . The Error: The following pop-up window does what it's name says, it pops-up My code: Ball Generator class BallGenerator: def __init__(self, min_y, max_y, x): self.min = min_y self.max = max_y self.x = x self.counter = 0 def bowl(self, balls): global ball_bowled y = random.randint

Collision detection not working in pygame

▼魔方 西西 提交于 2019-12-24 15:53:30
问题 I am making a game at the moment and I am experiencing problems with collision detection. I am making an end of level block but it can not detect if the player is standing on it to change to level 2. The collision detection for the block is found in player.updater(). As well as this the block is a class and in a group called endPlatform to allow the collision detection to work. The game runs perfectly fine however it can not detect when the Player hits Endplatform. I get no errors which show

How do I blit an image to a surface in pygame that's the same size as a Rectangle

旧街凉风 提交于 2019-12-24 15:39:34
问题 I'm making a game with pygame and each Sprite has a rectangle and an image. How would I blit this image to a surface so that it's the same size as the rectangle? pygame.init() screen = pygame.display.set_mode((720, 480)) pygame.display.set_caption('My game') background = pygame.Surface(screen.get_size()) background = background.convert() background.fill((250, 250, 250)) charRect = pygame.Rect((0,0),(10, 10)) print os.path.abspath("airbender.png") charImage = pygame.image.load(os.path.abspath(