pygame

Pygame: Making a sprite move along a predetermined path at a constant speed

折月煮酒 提交于 2019-12-20 07:28:58
问题 I'm working on a tower defense game in Pygame in which the enemies advance towards the base along a path that I have set for them; if you've played flash games like VR Defender Y3K and Canyon Defense my idea is the exact same concept. However, I am having trouble getting the sprites to move along a path that involves changes in direction such as the path turning left or right. So my question is what is an easy way to get a sprite to move along a predetermined path with changes in direction at

Countdown timer is delayed on pygame screen?

不想你离开。 提交于 2019-12-20 07:23:22
问题 I've created a game; in which one of the main components is a countdown timer- however this timer is delayed and I am not able to deduce why. This is how I have the timer set up: loops = 0 minute = 1 tens = 0 ones = 0 #Timer Calculation screen.blit(cloudSky, (0,0)) if go == True: loops = loops + 1 if (loops % 60)== 0: if ones == 0 and tens == 0 and minute != 0: tens = 6 ones = 0 minute = minute - 1 if ones == 0 and tens != 0: ones = 9 tens = tens - 1 elif ones != 0: ones = ones - 1 elif tens

Making rectangle move across screen with graphics file

半世苍凉 提交于 2019-12-20 07:06:30
问题 from graphics import * def main(): win = GraphWin("Polygon", 500, 500) r= Rectangle(Point(10,500),Point(150,450)) r.draw(win) while r.getP1()<=450 is False: rectMaker(r) time.sleep(1) def rectMaker(r): r.undraw(win) r=Rectange(Point(r.getP1()+1),(Point(r.getP2()+1))) r.draw(win) return r #win.getMouse() main() Why is my rectangle not moving anyone see anything? And I don't think I'm suppose to use sleep in case anyone was going to suggest that. Any help is appreciated please and thank you 回答1

Parachute Segmentation Fault Error - pygame to py2exe

可紊 提交于 2019-12-20 06:19:48
问题 I am using GUI2Exe to compile my python/pygame, game to a .exe I have a problem with the font module. using python 2.7 and the py2exe option in GUI2Exe I have updated python, pygame and py2exe with the 2.7 versions. My program runs fine but after I compile it with py2exe I get this. Here is the error I get: Fatal Python error: (pygame parachute) Segmentation Fault This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for

Why am I getting this AttributeError ? (python3 , pygame)

ぐ巨炮叔叔 提交于 2019-12-20 05:45:35
问题 Below is the error I am receiving and the code I have written. I know similar questions have been asked , but the solutions they are given do not relate to this case. And I can't seem to figure out why I am receiving this attribute error. I am running python 3.3 and pygame. The OS im on is ubuntu 12.10. I hope someone can find a solution to this problem so I can continue working on this physics simulation. Traceback (most recent call last): File "/media/lawton/D4B1-5B96/programming/Python

how to restrict rotation to a set amount of degrees in pygame?

你说的曾经没有我的故事 提交于 2019-12-20 05:19:17
问题 My question is related to the answer of the question below. rotating a rectangle. How do i restrict the rotation to the area marked in red as in this picture? I tried various ways but was unsuccesfull. The code always keeps the poiter in the other area. my modified code below. import pygame, math, base64 pygame.init() screen = pygame.display.set_mode((200, 200)) surf = pygame.image.load("D:\\PYTHON\\SoftwareDG\\Games\\Platform_Suvivor\\assets\\rg.png").convert_alpha() def rot_center(image,

Implementing a collision detect feature between a Rect object and a ball in pygame

旧街凉风 提交于 2019-12-20 05:01:14
问题 import pygame, random, time # main function where we call all other functions, start the game loop, quit pygame and clean up the window. Inside we create a game object, display surface, and start the game loop by calling the play method on the game object. There is also a set caption with the title of the game. def main(): pygame.init() size =(500,400) surface=pygame.display.set_mode(size) pygame.display.set_caption('Pong v2') game = Game(surface) game.play() pygame.quit() # This is where we

Move the player in the position of the mouse in pygame

六月ゝ 毕业季﹏ 提交于 2019-12-20 04:23:08
问题 I have a fixed player in center of the screen and for now I'm moving the background and the elements in the opposite direction to give the illusion of moving forward with the directional keys. But now, I want to detect the position of the mouse and deplace the player in the direction of the mouse (as in the game agar.io for example) and that the acceleration depends on the distance with the object (the further the mouse is, the faster the player moves forward and if the mouse is on the player

How to detect collision between objects in Pygame?

故事扮演 提交于 2019-12-20 04:15:21
问题 I'm making a sidescrolling game in Pygame, and if the fox sprite collides with the tree, it is supposed to print "COLLIDE". But it doesn't work. How can I fix this to detect collision between the fox and the tree? Here's the code: if foxsprite1 > xtree and foxsprite1 < xtree + treewidth or foxsprite1 + treewidth > xtree and foxsprite1 + treewidth < xtree + treewidth: print ("COLLIDE") xtree is the x coordinate of the tree, treewidth is the width of the tree, and foxsprite1 is the fox. 回答1:

Python - Pygame - Get if specific sound is playing

一世执手 提交于 2019-12-20 03:56:07
问题 Pygame's mixer module has pygame.mixer.get_busy which returns a simple boolean. My problem is that I have sound playing constantly, like explosions and gunshots, and need to know when a specific sound is playing to prevent game dialogue from overlapping. I considered making a list of currently playing dialogue, creating a timer that counts down as each sound is triggered,but that would require me to add an sound Effects (my module that handles sounds) update in the main game loop. This seems