pygame

Collision detection in pygame

一世执手 提交于 2019-12-24 04:29:10
问题 I wrote a little test to get a feeling for collision detection in pygame. My players moves properly and stop at the rock, where the collision shall happen, but when I reach the rock I can't move away again. Do you guys know why this is the case? This is my test code: import pygame import sys white = (255, 255, 255) black = ( 0, 0, 0) # Player class class Player(pygame.sprite.Sprite): def __init__(self): super().__init__() self.image = pygame.image.load('../foo.png') self.rect = self.image.get

Error when loading audio file from zip in python

不羁的心 提交于 2019-12-24 04:08:13
问题 I am making a game, and I need to load some password protected audio files from a .zip file, but I get this error: io.UnsupportedOperation: seek io.UnsupportedOperation: seek io.UnsupportedOperation: seek b'hey you did it!' #THIS IS FROM THE PROGRAM Traceback (most recent call last): File "C:\Python36\lib\zipfile.py", line 849, in read data = self._read1(n) File "C:\Python36\lib\zipfile.py", line 917, in _read1 data += self._read2(n - len(data)) File "C:\Python36\lib\zipfile.py", line 949, in

How can I limit pygame.draw.circle?

你说的曾经没有我的故事 提交于 2019-12-24 03:39:26
问题 I have a draw area that I want to draw to and borders that I would not like to draw over. Currently, if the mouse positions (m_x & m_y) are within the circles radius of the border I have the program draw the circle and then redraw rectangles which cut off the part of the circle which crossed. There must be a smarter and more efficient way to draw only the parts of the circle which are within the border. if event.type == pygame.MOUSEBUTTONDOWN or pygame.MOUSEMOTION and mouse_pressed[0] == 1:

pygame elements with different “speed”

徘徊边缘 提交于 2019-12-24 03:39:20
问题 I just made a space-invadish game, where things fall to the ground and you have to avoid crashing, etc. I succeeded in creating 2 objects falling down simultaneously but I cannot make them doing this with different speed. This the first object's attributes. thing_startx = random.randrange(0, display_width-100) thing_starty = -700 thing_speed = 4 Now it falls by thing_starty += thing_speed in each while loop iteration. For the next object I just added random numbers to the original X and Y

How do you create rect variables in python pygame

匆匆过客 提交于 2019-12-24 03:37:48
问题 I am programming in Python with the pygame library. I want to know how to make a rectangle variable, something like: import ... rect1 = #RECT VARIABLE rect2 = #RECT VARIABLE 回答1: Just do pygame.Rect(left, top, width, height) this will return you a Rect object in pygame 回答2: Perhaps something like this will work? import pygame # your whole code until you need a rectangle rect1 = pygame.draw.rect( (x_coordinate, y_coordinate), (#a rgb color), (#size of rect in pixels) ) If you want a red

Pygame: Graphical Input + Text Input

こ雲淡風輕ζ 提交于 2019-12-24 03:34:08
问题 In Pygame, how can I get graphical input(e.g. clicking exit button) and also get input from the a terminal window simultaneously? To give you context, my game has a GUI but gets its game commands from a "input()" command. How can I look for input from the command line while also handling graphics? I'm not sure if this is possible, but if not, what other options do I have for getting text input from the user? Thanks in advance. 回答1: You can't do that, unless you use the input command in a

Pygame - Recolor pixes of a certain color to another using SurfArray (Array slicing issue)

依然范特西╮ 提交于 2019-12-24 02:42:39
问题 I'm trying to make a palette swap functionality for a game, and I'm trying to find a way to change the color of pixels of a certain color to another. I've been able to make all of the pixels the same color with this function I found in a tutorial: def color_surface(self,surface, red, green, blue): arr = pygame.surfarray.pixels3d(surface) arr[:,:,0] = red arr[:,:,1] = green arr[:,:,2] = blue As far as I can tell, the first two indices are the location of the pixel, and the third is the color

Creating a Group to add my Class to in Pygame

蓝咒 提交于 2019-12-24 02:22:11
问题 I am currently making a game in Pygame, and would like to generate several platforms randomly throughout my screen. However, I can't seem to figure out how to create a group so that I can draw several sprites at once. I have tried using super.__init__(self) and also replacing self with (*Group) , yet it isn't working. I also have just tried to add it to a group. How should I make my group and how do I correctly add my sprite to it? Here is the code (the sprite I want to add in is created here

Pygame: Couldn't open file. Same directory

℡╲_俬逩灬. 提交于 2019-12-24 02:16:28
问题 I loaded 150 .tif images to a glob module and am currently unable to load them. I'm very new to programming so I imagine it's a dumb mistake I'm missing but I cant seem to figure it out. The is the code: import pygame, glob types= ('*.tif') artfile_names= [] for files in types: artfile_names.extend(glob.glob(files)) print(artfile_names) for artworks in artfile_names: pygame.image.load(str(artfile_names)) Thank you for any help! 回答1: The mistake is that your types variable is just a string

pygame fullscreen mode exit

浪尽此生 提交于 2019-12-24 01:55:25
问题 I'm running this little program that loads images to the screen in fullscreen mode but once it loads the program will not exit by any key combination and I end up having to reset the computer to complete whatever else I was doing. import pygame pygame.init() WIDTH=1366; HEIGHT=768 screen = pygame.display.set_mode((WIDTH, HEIGHT), pygame.FULLSCREEN) pygame.display.set_caption('Katso') PENGUIN = pygame.image.load("assets/download.png") MICKEY = pygame.image.load("assets/mickey.jpg") ADV =