pygame

Python sin and cosine giving incorrect values

人走茶凉 提交于 2019-12-24 07:38:16
问题 I have code that draws a line from 2 points; One on the middle bottom of the screen, and the other to the mouse pointer. I am trying to constrain the point by not exceeding a length parameter that I set. Heres the code: import pygame import Resources as r import math as m pygame.init() class Segment(): def __init__(self, _screen, _id, _start_pos, _length): self.screen = _screen self.id = _id self.start_pos = _start_pos self.length = _length def update(self): if self.id == 1: mouse_pos =

Pygame - smpeg does not find Python headers

家住魔仙堡 提交于 2019-12-24 07:37:25
问题 I've been trying to install Pygame for days now, and the only dependency missing is smpeg . I get the following output: brew install --HEAD smpeg ==> Installing dependencies for smpeg: gobject-introspection, gdk-pixbuf, ==> Installing smpeg dependency: gobject-introspection ==> Building source; bottle blocked by python requirement ==> Downloading http://ftp.gnome.org/pub/GNOME/sources/gobject-introspection/1.4 Already downloaded: /Library/Caches/Homebrew/gobject-introspection-1.40.0.tar.xz ==

How to display GAME OVER screen and YOU WIN screen in pygame [duplicate]

旧街凉风 提交于 2019-12-24 07:36:19
问题 This question already has answers here : Pygame level/menu states (2 answers) Closed 11 months ago . I have a GAME OVER screen that is functioning when your health is depleted. This GAME OVER screen is executed with the show_go_screen. I tried to just duplicate the method for the show_go_screen into my show_winning() function for the other screen. I rigged this show winning function by setting your health back to normal when going back to the game. However once you have gone to the YOU WIN

When trying to install pygame on Anaconda Python 3.x is downgraded to Python 2.7

房东的猫 提交于 2019-12-24 07:24:02
问题 I'm working with Anaconda Python 3. I'm trying to install pyOpenGL, Vpython and pygame. Installing pyOpenGL and Vpython is fine using conda install . When I try to install Pygame, using conda install it shows: conda install -c https://conda.binstar.org/kne pygame #same for conda install pygame ... The following NEW packages will be INSTALLED: . . . The following packages will be REMOVED: backports.os-0.1.1-py37_0 importlib_metadata-0.8-py37_0 jeepney-0.4-py37_0 jupyterlab_server-0.2.0-py37_0

Can I use the .format feature when using screen.blit in Pygame?

*爱你&永不变心* 提交于 2019-12-24 07:19:49
问题 Heys, I recently couldnt figure out how to blit lists onto my pygame screen using certain x and y values, allowing the text to blit say x += 20, moving every other string in my list over 20 units everytime it blits. I recently did some .format stuff with printing just in the console, is there a feature like this for screen.blit so I can use the same formatting in a pygame window? Included my code underneath. Thanks in advance :D import pygame NAMES = ['Deanerys T.', 'Jon S.', 'Gregor C.',

Pygame Playlist without while True loop

冷暖自知 提交于 2019-12-24 07:10:38
问题 Here is a short snippet from my code: import pygame class Player(): playlist= ["track1.mp3","track2.mp3",...] def __init__(self): pygame.init() pygame.mixer.music.load(self.playlist[0]) pygame.mixer.music.play() def playnext(self): self.playlist = self.playlist[1:] + [self.playlist[0]] pygame.mixer.music.load(self.playlist[0]) pygame.mixer.music.play() My problem is that I want to play the next track after the first finished, but without a while true loop. This class is not the only one in my

Pygame program stops responding, giving no error

…衆ロ難τιáo~ 提交于 2019-12-24 07:01:38
问题 so my program is meant to display buttons in rows, then wait for the user to click one, however what would happen is that the it would return to the main menu. I was unsure of how to make the program wait ( I tried time.sleep() and os.system("pause"), however both of these would just wait for a certain amount of time and then also return to the main menu - so I resorted to using a console input, just to see if the boxes were being correctly displayed. However now with the console input,

How to make arrow shoot in direction of mouse?

女生的网名这么多〃 提交于 2019-12-24 06:50:04
问题 I am attempting to shoot an arrow on mouse click, however in the direction of the mouse. I've accomplished the shooting part, however I am not able to have it shoot towards the mouse. I've listed my code below and I really appreciate all help! The portion of the code which is relevant to the arrow shooting is: for shot in daggers: index = 0 shotx = math.cos(shot[0])*35 shoty = math.sin(shot[0])*35 shot[1] += shotx shot[1] += shoty if shot[1] < -40 or shot[1] > 900 or shot[1] < -40 or shot[1]>

Moviepy fullscreen

微笑、不失礼 提交于 2019-12-24 05:55:19
问题 I'm creating a simple pygame, and cannot find out how to make Moviepy preview clip in full screen. Using Moviepy for my opening cinematic. Here is my code: import moviepy import os from moviepy.editor import * import pygame pygame.display.set_caption('Game title') os.environ["SDL_VIDEO_CENTERED"] = "1" clip = VideoFileClip('qq.mp4') clip.preview() execfile("startGame.py") I'm not sure if this is the best practice in pygame to use for an opening full-screen cinematic... 回答1: I changed in

Pygame: Collision With tiles not working

强颜欢笑 提交于 2019-12-24 05:51:58
问题 I am currently working on an abstraction layer for pygame, and have come across a problem when trying to check collisions with the maps. I am able to load and display the map, as well as store rectangles which are collidable. When I print the list of rectangles, I see that everything is in place, but when I iterate over every rect and try to check collision with another rect, it always returns true even when the rects do not collide. Also, when I try to debug all the rects by drawing a red