pygame

pygame how to check mouse coordinates

亡梦爱人 提交于 2019-12-20 01:46:44
问题 I am making a multiple choice quiz game with python and pygame. I have circles and what a want is when you click on the circle it will change the width and make the circle full. But I don't know of a python function that can do that Heres my code so far: # Controls the width of the circles width_1 = 2 width_2 = 2 width_3 = 2 width_4 = 2 # Circles pygame.draw.circle(screen, BLACK, [250, 230], 7, width_1) pygame.draw.circle(screen, BLACK, [250, 260], 7, width_2) pygame.draw.circle(screen, BLACK

pygame how to check mouse coordinates

旧时模样 提交于 2019-12-20 01:46:30
问题 I am making a multiple choice quiz game with python and pygame. I have circles and what a want is when you click on the circle it will change the width and make the circle full. But I don't know of a python function that can do that Heres my code so far: # Controls the width of the circles width_1 = 2 width_2 = 2 width_3 = 2 width_4 = 2 # Circles pygame.draw.circle(screen, BLACK, [250, 230], 7, width_1) pygame.draw.circle(screen, BLACK, [250, 260], 7, width_2) pygame.draw.circle(screen, BLACK

Pygame, best way to implement buttons?

家住魔仙堡 提交于 2019-12-19 12:22:07
问题 I am working on a pygame project with a group where we need to be able to click a button to select a class of objects, and then have that object be placed down on to a grid. It is essentially a tower defense style game where enemies spawn in rows and I need to be able to place objects to block/remove them. The issue We're coming across is that we can't get our buttons to draw on screen and how to then spawn a troop to the screen after the click. I assume it would be done in a way if the

Windows/Python pygame.error: video system not initialized after adding Mp3 file

拥有回忆 提交于 2019-12-19 10:52:34
问题 I just added some music to my pygame game but I think the code is so messy that nothing is in the right place. As a result of this addition, I'm now getting this error: Traceback (most recent call last): File "C:\Users\1234\AppData\Local\Programs\Python\Python36-32\My First game ERROR.py", line 31, in for event in pygame.event.get(): pygame.error: video system not initialized Here is the code that I have written: import pygame, sys pygame.mixer.init(44100, -16,2,2048) class Game(object): def

Using pygame.time.wait() between display updates

别等时光非礼了梦想. 提交于 2019-12-19 10:48:13
问题 I am currently developing a simple Tower of Hanoi animation in Pygame, that should show the correct solution of Tower of Hanoi, moving one piece per second. However, in my hanoi solving algorithm, I'm trying to update the display and use pygame.time.wait() after each movement; and instead of updating one movement and waiting one second, the program waits the total number of movements amount of seconds and then displays the tower with all the movements done at once. What I would like to know

Using pygame.time.wait() between display updates

↘锁芯ラ 提交于 2019-12-19 10:47:01
问题 I am currently developing a simple Tower of Hanoi animation in Pygame, that should show the correct solution of Tower of Hanoi, moving one piece per second. However, in my hanoi solving algorithm, I'm trying to update the display and use pygame.time.wait() after each movement; and instead of updating one movement and waiting one second, the program waits the total number of movements amount of seconds and then displays the tower with all the movements done at once. What I would like to know

Continuous movement of a box in pygame

亡梦爱人 提交于 2019-12-19 10:16:29
问题 I have written the following code that creates a simple game where when you click an arrow on the keyboard a box moves a unit over in the game. I am trying to make it so that if i push any of the arrow buttons the box will continue to move in that direction until another arrow is pushed. So if i push the right arrow once instead of scooting +50 pixels it will move continuously across the screen untill a different arrow is clicked and then it will go that way import pygame #importing the

Pygame Erasing Images on Backgrounds

ε祈祈猫儿з 提交于 2019-12-19 10:02:21
问题 You blit an image onto your surface to use as your background. Then you press button X to blit an image on the same surface, how do you erase the image? I have this so far, but then I end up with a white rectangle in the middle of my background. screen = pygame.display.set_mode(1280, 512) screen.blit(background, (0,0)) while True: pygame.display.flip() #flip is same as update for event in pygame.event.get(): if (event.type == pygame.KEYDOWN): if event.key == pygame.K_SPACE: screen.blit(player

How to install pygame on Mac with python 2.7 installed?

那年仲夏 提交于 2019-12-19 09:22:30
问题 I want to install pygame on Mac 10.6.8. I managed to install python 2.7.9 and to make it stable. I tried to install different versions of pygame but none worked: for example with the 1.9.1 it gives me this error: Output: Traceback (most recent call last): File "/.../Desktop/example.py", line 1, in <module> import pygame File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/__init__.py", line 95, in <module> from pygame.base import * ImportError: dlopen(

compiling a python program that uses pygame into an executable

雨燕双飞 提交于 2019-12-19 08:13:20
问题 I wanted to compile my python program that uses pygame into an executable using py2exe but I'm experiencing some problems. I run the script in the windows command line and it seems to work. It creates a dist directory but when I try to open the .exe file, it briefly opens a command line window and then doesn't do anything. Could this possibly be because I've used pygame and py2exe doesn't support it? Or do I need to put a copy of the pygame library into the same directory as my program? 回答1: