pygame

Recalling import in module

孤街浪徒 提交于 2020-01-15 01:49:12
问题 I'm still learning python and after playing around with pygame I noticed I'm re-importing things in modules I'm importing that I've already imported. import pygame For instance I have some classes in a separate file, but I must also import pygame into that file too for them to work. Does it actually import the code twice? Will it slow down my program? Or does it just pull the same import from cache, but if it does that, why would I need to import it again? Is there anything like (load) in

Pygame (A bit racey) game bug

[亡魂溺海] 提交于 2020-01-15 01:23:28
问题 in the game when you first start it there's the game start menu/intro, it has 2 buttons (Start Game) (Quit) Now when you start the game and you're actually playing, when you press P (Paused) there're 2 buttons (Continue) (Main Menu) if you click continue it completes the game normally. However when you click main menu it closes the game instead of returning to the intro, same problem is present when you crash with the car you have (Try Again) and (Main Menu) and also if you click Main Menu it

Why does pygame freeze at pygame.event.get() when you move/drag the window?

戏子无情 提交于 2020-01-14 13:06:46
问题 Basically I have a loop (tick, set_caption, screen_fill, event.get(), send_frame_event, flip, repeat) When I drag the window around on windows 7, the loop stops looping, I ended up stuck in pygame.event.get(), I have tried to define certain events only for get e.g. get([pygame.QUIT]) to no avail. Simply calling pygame.event.clear() has the same freeze effect when dragging/moving the window. Is there a workaround? Not full code, but should be enough: def start(self): self.running = True Clock

pygame: detect Joystick disconnect, and wait for it to be reconnected

旧时模样 提交于 2020-01-14 10:33:15
问题 I'm using a pygame.joystick.Joystick object and want to be able to print a message asking the user to reconnect a usb joystick once it's been unplugged. right now I have (roughly): js = pygame.joystick.Joystick(0) #... some game code and stuff pygame.joystick.quit() pygame.joystick.init() while pygame.joystick.get_count() == 0: print 'please reconnect joystick' pygame.joystick.quit() pygame.joystick.init() js = pygame.joystick.Joystick(0) js.init() but it doesn't reconnect properly, idk what

pygame.mixer.Sound.play is irregular although fired regularly

纵然是瞬间 提交于 2020-01-14 10:32:40
问题 I currently try to repeat a sound every x ms - where x is dependent on an UDP packet I receive via socket - and I decided to use pygame for that. I used this SO answer to repeat something every x ms: https://stackoverflow.com/a/18954902/3475778 But now I have the problem, that the sound is played very irregular and made a minimal-working example where the problem persists: import pygame from pygame.locals import * pygame.mixer.init() sound = pygame.mixer.Sound('sound.wav') def play_sound():

Anti-aliased Arc Pygame

我的梦境 提交于 2020-01-14 09:21:06
问题 I am trying to code a simple circle timer in Python using Pygame. At the moment it looks like this: As you can see, the blue line is very wavy and has white dots in it. I am achieving this blue line by using pygame.draw.arc() function, but it is not anti-aliased and looks bad. I would like it to be anti-aliased, but gfxdraw module which should let me achieve this, doesn't support arc width selection. Here's code snippet: pygame.draw.arc(screen, blue, [center[0] - 120, center[1] - 120, 240,

Pygame Keyup/Keydown

痴心易碎 提交于 2020-01-14 04:12:08
问题 I'm making a little Mario for my school's Computer Club. (well, as part of a team.) Anyway, I'm having some trouble with the "keyup/keydown" commands. Here's my code: # 1 - Import library import pygame from pygame.locals import * # 2 - Initialize the game pygame.init() width, height = 1280, 1000 screen=pygame.display.set_mode((width, height)) keys = [False, False, False, False] playerpos=[100,100] # 3 - Load images player = pygame.image.load("images/totallynotgodzilla.png") # 3.1 - Load Audio

How would I make a car move the direction it's pointing (After use of pygame.translation.rotate)

家住魔仙堡 提交于 2020-01-13 19:21:47
问题 Okay so I'm making a test for making a racing game... And I want the car to move in the direction it's pointing. Here is my code. import pygame, sys from pygame.locals import * pygame.init() mainClock = pygame.time.Clock() degree = 0 WHITE = 250,250,250 rect2 = pygame.rect = (100,100,50,50) WINDOWWIDTH = 1200 WINDOWHEIGHT = 750 thing = pygame.image.load('car.png') screen = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT), 0, 32) pygame.display.set_caption('Teh test') left = False right =

Python physics library? [closed]

╄→гoц情女王★ 提交于 2020-01-13 08:31:32
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . Are there any good up-to-date physics libraries for Python that are for Linux? I'm just getting into Python using PyGame, but PyGame's lack of a physics library isn't cool. I spent about two hours trying to find a good physics library but it's like trying to grab oil; I can't seem to do it. I barely need a

Python physics library? [closed]

和自甴很熟 提交于 2020-01-13 08:31:07
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . Are there any good up-to-date physics libraries for Python that are for Linux? I'm just getting into Python using PyGame, but PyGame's lack of a physics library isn't cool. I spent about two hours trying to find a good physics library but it's like trying to grab oil; I can't seem to do it. I barely need a