pygame

How would I fix my characters position after hitting a block?

可紊 提交于 2020-01-02 23:14:36
问题 After I hit a platform my character can't move along the x-axis anymore unless you press the left or right keys again. For example, if I jump and I clip the corner of the platform the character doesn't continue moving and I have to either do the jump again or react quickly and press the corresponding key. When I remove the player.friction() in the collision detecting system, if I stop pressing the right key it ends up clipping into the edge of the block, which causes the player to get

run a certain code while it detects something python

前提是你 提交于 2020-01-02 14:56:53
问题 This code is used to play an alarm if it detects the driver is drowsy if args["alarm"] != "": t = Thread(target=sound_alarm, args=(args["alarm"],)) t.daemon = False t.start() The whole code looks like this: if ear < EYE_AR_THRESH: COUNTER += 1 # if the eyes were closed for a sufficient number of # then sound the alarm if COUNTER >= EYE_AR_CONSEC_FRAMES: # if the alarm is not on, turn it on if not ALARM_ON: ALARM_ON = True # check to see if an alarm file was supplied, # and if so, start a

Issue with sys.exit() in pygame

风格不统一 提交于 2020-01-02 08:46:10
问题 I am learning to use Pygame, and when I use sys.exit() , I run into a problem. Here is the code: import pygame, sys,os from pygame.locals import * pygame.init() window = pygame.display.set_mode((468, 60)) pygame.display.set_caption('Game') screen = pygame.display.get_surface() file_name = os.path.join("data","image.bmp") surface = pygame.image.load(file_name) screen.blit(surface, (0,0)) pygame.display.flip() def input(events): for event in events: if event.type == QUIT: sys.exit(0) else:

Side scrolling with Pymunk and Pygame. How to move the camera / viewport to view only part of the world?

笑着哭i 提交于 2020-01-02 08:40:08
问题 From the pymunk examples I've seen that there's a difference between the pymunk coordinates and pygame coordinates. Also, that pymunk is meant just for the 2D physics, while pygame is for rendering objects/sprites on the screen. So when searching for how to build an environment where the camera follows the player, people (including me) end up getting confused. I've seen the examples here, here, here and here (even surprised that nobody answered this), but given the number of questions related

In pygame blit of subsurface cause error that the subsurface is locked

徘徊边缘 提交于 2020-01-02 05:21:10
问题 Here is a minimal script to reproduce that #!/usr/bin/env python import pygame screen = pygame.display.set_mode((640, 480)) screen.fill((255, 255, 255)) screen_half = screen.subsurface((0,0, 640/2.0, 480)) print screen.get_locks() print screen_half.get_locks() screen_half.blit(screen_half, (0, 0)) the output is () () Traceback (most recent call last): File "./blit_test.py", line 10, in <module> screen_half.blit(screen_half, (0, 0)) pygame.error: Surfaces must not be locked during blit As you

How can I play a mp4 movie using Moviepy and Pygame

北城以北 提交于 2020-01-02 05:05:14
问题 How do you play an mp4 video in Pygame? I have tried pygame.movie but this does not work... Theres also moviepy, but I am having trouble changing the title of the window that pops up. It says "MoviePy", not sure how to change that. import moviepy from moviepy.editor import * import os os.environ["SDL_VIDEO_CENTERED"] = "1" clip = VideoFileClip('qq.mp4') clip.preview() execfile("qq.py") # Execute my game right after the clip shows How would I change the title from "MoviePy" to my "my game name

How to fix 'No module named vidcap' in python 3.7

我怕爱的太早我们不能终老 提交于 2020-01-02 04:54:30
问题 I have camera set up, which works fine. The thing is, there is an ModuleNotFoundError when I am trying to import pygame. (Note:I am using windows) This is a test project, and I have to make a camera out of pygame. I've tried some youtube tutorials and I messed with pygame but it always causes an Error. This is what I have so far: import pygame.camera pygame.camera.init() camera = pygame.camera.list_cameras()[0] pyg = pygame.camera.Camera(camera (640, 480), 'HSV') --snip-- if pyg.query_image()

Reading piano notes on Python

£可爱£侵袭症+ 提交于 2020-01-02 04:34:30
问题 I'd like to listen to the port having my midi output device (a piano) with my RPi, running on Debian. I've looked into pygame.midi, I managed to listen to the port, but somehow can not extract all midi information. Please find code below [edited code snippet] EDIT: Fixed, thanks a lot! 回答1: First of all you need to find out which device-id your keyboard has inside pygame. I wrote this little function to find out: import pygame.midi def print_devices(): for n in range(pygame.midi.get_count()):

Python time counter in Pygame-mouse events

房东的猫 提交于 2020-01-02 04:16:05
问题 I want to calculate the time of user's mouse events in Pygame, if user doesn't move his mouse about 15 seconds, then I want to display a text to the screen. I tried time module for that, but it's not working. import pygame,time pygame.init() #codes ... ... font = pygame.font.SysFont(None,25) text = font.render("Move your mouse!", True, red) FPS = 30 while True: #codes ... ... start = time.time() cur = pygame.mouse.get_pos() #catching mouse event end = time.time() diff = end-start if 15 < diff

Python - Virtualenv , python 3?

五迷三道 提交于 2020-01-02 01:56:07
问题 Seems everyone recommends virtualenv for multiple python versions (on osx), but does it even work with python 3.0? I downloaded it, and it doesn't seem to.. And I don't really understand how it works, Can you 'turn on' on env at a time or something? What I want is to leave the system python 2.5 (obviously), and to have python 3.1.1 with subversion pygame to write my own stuff, and python 2.6 with normal stable pygame to use to run other things, like pygame games downloaded from pygame.org.