pygame

Pygame making an object chase the cursor

耗尽温柔 提交于 2020-01-04 07:17:53
问题 Been at this for the past few hours, trying to make a small program where an image chases the cursor around. So far I've managed to make it so that the image is directly on top of the cursor and follows it around that way. However what I need is for the image to actually "chase" the cursor, so it would need to initially be away from it then run after it until it's then on top of the mouse. Basically hit a wall with whats going wrong and what to fix up, here's what I've gotten so far: from _

.OFF files on Python

℡╲_俬逩灬. 提交于 2020-01-04 05:47:08
问题 I've been practicing with Python and PyOpenGL, but I can't seem to open .OFF files (Object File Format) with Python. If you're wondering, .OFF files are files that contain positions of a 3D object. OFF 8 6 0 -0.500000 -0.500000 0.500000 0.500000 -0.500000 0.500000 -0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 -0.500000 0.500000 -0.500000 0.500000 0.500000 -0.500000 -0.500000 -0.500000 -0.500000 0.500000 -0.500000 -0.500000 4 0 1 3 2 4 2 3 5 4 4 4 5 7 6 4 6 7 1 0 4 1 7 5 3 4 6 0 2 4 I

Detecting the point of collision with Pygame

╄→гoц情女王★ 提交于 2020-01-04 05:14:17
问题 I am making a game with Pygame. For this game I need to be able to detect not only that two rectangles have collided, but also the point of collision between them. I looked at the documentation but couldn't seem to find any answers. Is something like this possible? 回答1: You can use Rect.clip: crops a rectangle inside another clip(Rect) -> Rect Returns a new rectangle that is cropped to be completely inside the argument Rect. If the two rectangles do not overlap to begin with, a Rect with 0

Using Python to verify the mouse position is within the circle, when clicking anywhere within the circle.

喜你入骨 提交于 2020-01-04 03:16:13
问题 I am working on a project within Python that is to determine the multi-tasking efficiency of a person. Part of the project is to have a user respond to an event on screen using the mouse. I have decided to have the user click within a ball. However I am having issues with my code on verifying that the mouse cursor is actually within the confines of the circle. The code for the methods in question are below. Radius of the circle is 10. #boolean method to determine if the cursor is within the

Pygame - Collision detection with two CIRCLES

99封情书 提交于 2020-01-03 17:24:13
问题 I'm making a collision detection program where my cursor is a circle with a radius of 20 and should change a value to TRUE when it hits another circle. For testing purposes, I have a stationary circle in the centre of my screen with a radius of 50. I'm able to test whether the cursor circle has hit the stationary circle but it doesn't quite work properly because it's actually testing if it's hitting a square rather than a circle. I'm not very good with maths and I haven't been able to find

How to present numpy array into pygame surface?

北慕城南 提交于 2020-01-03 08:55:10
问题 I'm writing a code that part of it is reading an image source and displaying it on the screen for the user to interact with. I also need the sharpened image data. I use the following to read the data and display it in pyGame def image_and_sharpen_array(file_name): #read the image data and return it, with the sharpened image image = misc.imread(file_name) blurred = ndimage.gaussian_filter(image,3) edge = ndimage.gaussian_filter(blurred,1) alpha = 20 out = blurred + alpha*(blurred - edge)

wxPython or pygame for a simple card game?

 ̄綄美尐妖づ 提交于 2020-01-03 08:41:41
问题 I have been playing around with writing some simple card games in Python for fun and I would like to add a graphical user interface (GUI) to the games. Which library would you recommend for writing the GUI for a simple card game? 回答1: If all you want is a GUI, wxPython should do the trick. If you're looking to add sound, controller input, and take it beyond a simple card game, then you may want to use pygame. 回答2: I haven't used wxPython, but Pygame by itself is rather low-level. It allows

Weird shifting when using pygame.transform.rotate()

寵の児 提交于 2020-01-03 05:50:12
问题 def rotate(self): #Save the original rect center self.saved_center=self.rect.center #Rotates a saved image every time to maintain quality self.image=pygame.transform.rotate(self.saved_image, self.angle) #Make new rect center the old one self.rect.center=self.saved_center self.angle+=10 When I rotate the image, there is a weird shifting of it despite the fact that I'm saving the old rect center and making the rotated rect center the old one. I want it to rotate right at the center of the

How to make rect from the intersection of two?

血红的双手。 提交于 2020-01-03 03:40:21
问题 I'm working on a breakout clone and I've been trying to figure out how to get the intersection rect of two colliding rects so I can measure how deep the ball entered the block in both x and y axis and decide which component of the velocity I'll reverse. I figured I could calculate the depth for each case like this: But if I had the intersection rect than I woudn't have to worry if the ball hits the block from the left/right or top/bottom (since I would be only reversing the x and y axis

Syntax Error When Following Pygame/Python Tutorial on youtube

不羁岁月 提交于 2020-01-03 00:22:12
问题 I've just downloaded python 3.3.2 and pygame-1.9.2a0.win32-py3.3.msi . I have decided to try a few tutorials on youtube and see if they work. I have tried thenewboston's 'Game Development Tutorial - 2 - Basic Pygame Program' to see if it works. It is supposed to produce a black background and a ball that is the mouse (or so i think). It comes up with a syntax error when i try to run it, if i delete it it just produces a black pygame window. Here is the code: bgg="bg.jpg" ball="ball.png"