pygame

Pygame: How do I make my image fall?

自古美人都是妖i 提交于 2019-12-23 23:26:06
问题 I am trying to make objects fall like they would on earth. I already got them to blit where I wanted them to but I can't seem to animate them. This is the object that I want to fall import pygame class circle(): def __init__(self, screen): planet_color = (255,0,0) planet_radius = 20 self.screen = screen ev = pygame.event.get() self.image = pygame.image.load('../images/jupiter.bmp') self.image = pygame.transform.scale(self.image, (80, 80)) def blitme(self): self.x = pygame.mouse.get_pos() self

How do I add a line as a sprite in pygame?

拟墨画扇 提交于 2019-12-23 20:18:47
问题 I want to add a grid to my level that stays with the terrain and not the screen. The way I thought of doing it is to add all the lines that form the grid as sprites and move them with the terrain, but I can't figure out how to represent the line as an image. I tried to do this myself, but had no success. EDIT: Here's what I've tried class Grid(): def __init__(self): self.grid = pygame.Surface(size) self.grid.set_colorkey((0,0,0)) def draw(self): # DRAW TILE LINES -----------------------------

pygame.image.load not working

时光毁灭记忆、已成空白 提交于 2019-12-23 20:08:15
问题 I'm trying to create a world map for a game, but when I try to load the world map to the screen, the command line tells me I'm unable to do so. Here is the code: import sys import pygame from pygame.locals import * pygame.init () Surface = pygame.display.set_mode ((1000, 775), 0, 32) pygame.display.set_caption('World Map') WorldMap = pygame.image.load('WorldMap.jpg') white = (255, 255, 255) while True: Surface.fill (white) Surface.blit (WorldMap, (900, 675)) for event in pygame.event.get():

Pygame program that can get keyboard input with caps [duplicate]

最后都变了- 提交于 2019-12-23 20:00:26
问题 This question already has answers here : Pygame: Is there any easy way to find the letter/number of ANY alphanumeric pressed? (2 answers) Closed last year . I have a Pygame program that needs text input. The way it does this is to get keyboard input and when a key is pressed it renders that key so it is added to the screen. Essentially it acts like a text field. The problem is, when you hold shift it doesn't do anything. I realize this is because the program ignores shift input and instead

How to measure time in Python?

空扰寡人 提交于 2019-12-23 19:55:54
问题 I want to start my program, measure the time when the program starts and then wait some seconds, push a button (K_RIGHT) and messure the time when I push the button. I am using Pygame to registrate the Keydown. But in my code below it does not registrate my Keydown. What I am doing wrong here? start = time.time() for e in pygame.event.get(): if e.type == pygame.KEYDOWN: if e.key == pygame.K_RIGHT: end= time.time() diff = end-start 回答1: Here's a minimal, complete example that prints the

Why is my basic PyGame module so slow?

半世苍凉 提交于 2019-12-23 19:14:20
问题 I've planning on writing a code in Pygame and I was just getting started with the basics and found that the executing code was really slow. When I press a key it takes a while for it to print it in the terminal (there doesn't seem to be any pattern to it). I'm running Python 2.6, I downgraded after coming across this problem. With further testing I've found that the whole system slows down . Has anyone come across this or got a solution so it runs faster or/and prevents the system from

Storing unpicklabe pygame.Surface objects in external files

倖福魔咒の 提交于 2019-12-23 19:05:32
问题 So I've got a problem - I'm writing a game prototype in Python, using Pygame, and I want to save my games. All of the game-related data is in three instances of certain classes, and I want to save these three instances to a file. However, I've tried pickling these instances, and it doesn't work. Instead, I get "TypeError: can't pickle Surface objects". This is a problem, because I want to store Surface objects. I'm open to any alternatives to pickling that there may be, using any other kind

Failure on import pygame.font

时光怂恿深爱的人放手 提交于 2019-12-23 18:59:20
问题 import pygame works fine for me, but import pygame.font fails with the error: ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/font.so, 2): Library not loaded: /usr/local/lib/libpng15.15.dylib Referenced from: /usr/local/lib/libfreetype.6.dylib Reason: Incompatible library version: libfreetype.6.dylib requires version 30.0.0 or later, but libpng15.15.dylib provides version 20.0.0 This is in Python 2.7 (not the system version), Mac OS 10

Make a 8*8 chessboard in pygame with python

馋奶兔 提交于 2019-12-23 17:59:18
问题 I want to make a chessboard in pygame with python. Just only the chessboard with for loops. I tried in several ways to do this but i didn't figured out what exactly it will be. Here is my code: import pygame pygame.init() #set color with rgb white,black,red = (255,255,255),(0,0,0),(255,0,0) #set display gameDisplay = pygame.display.set_mode((800,600)) #caption pygame.display.set_caption("ChessBoard") #beginning of logic gameExit = False lead_x = 20 lead_y = 20 while not gameExit: for event in

dynamic overlay for video using python

余生长醉 提交于 2019-12-23 17:33:38
问题 I'm trying to write a program in python to be used by people with a disability while they use something as a hometrainer (or MotoMed). To do so I have to be able to show a video and write additional info/images to the screen if need be. This info is dependant on other sensors (including a Hall Effect sensor and sensors that can detect a spasm for instance). Using the Pygame Movie feature you can update the screen frame by frame using the pygame.update() function. See: How to load and play a