pygame

Pygame.key.get_pressed - how to add interval?

我只是一个虾纸丫 提交于 2019-12-25 06:27:21
问题 I have made a simple grid and a simple sprite which works as "player". but when i use arrow keys to move, the character moves too fast as shown in the picture below: and my question is: How do I set delay or Interval after each keypress event to prevent this problem? player.py #!/usr/bin/python import os, sys, pygame, random from os import path from pt import WIDTH,HEIGHT from pygame.locals import * img_dir = path.join(path.dirname(__file__), 'img') class Player(pygame.sprite.Sprite): def _

Slowly turning a rectangle in pygame

对着背影说爱祢 提交于 2019-12-25 05:27:27
问题 I have some code: mouseX, mouseY = pygame.mouse.get_pos() angle = math.degrees(math.atan2(mouseY - self.rect.centery, mouseX - self.rect.centerx)) rotated = pygame.transform.rotate(self.rect, -angle) self.rect = lol.get_rect() How should I modify this code to slowly turn the rectangle depending on the mouse angle (10deg/s etc.)? Edit: I want to rotate CLASS object (based on pygame.sprite.Sprite class) 回答1: Just don't rotate your image to the target angle, but only a little bit until you reach

Python select.select, select.poll: Corrupted Double-linked List

人盡茶涼 提交于 2019-12-25 05:23:22
问题 I have a rather large client-server network application, written in Python. I'm using select.poll to provide asynchronous capabilities. For the past six months, everything has worked fine. However, recently I changed some things and allowed the client to reliably log-off from the server. It appeared at first glance that the client was never receiving the request, and furthermore, it was blocking. When I killed the process with , I received the following output: *** glibc detected *** /usr/bin

Python select.select, select.poll: Corrupted Double-linked List

℡╲_俬逩灬. 提交于 2019-12-25 05:23:06
问题 I have a rather large client-server network application, written in Python. I'm using select.poll to provide asynchronous capabilities. For the past six months, everything has worked fine. However, recently I changed some things and allowed the client to reliably log-off from the server. It appeared at first glance that the client was never receiving the request, and furthermore, it was blocking. When I killed the process with , I received the following output: *** glibc detected *** /usr/bin

Rescale pixel's size pygame [duplicate]

核能气质少年 提交于 2019-12-25 04:48:47
问题 This question already has an answer here : Pygame: Rescale pixel size (1 answer) Closed 12 months ago . I'm using pygame 1.9. How to make window bigger, than it's size definite by pixel's size. For example, I create display with 100x100 pixel. And fill it by numpy array. screenarray=np.zeros((100, 100)) screenarray.fill(10) screen = pygame.display.set_mode((100,100)) surface = pygame.surfarray.make_surface(screenarray) screen.blit(surface, (0, 0)) pygame.display.flip() And it's too small, I

Python + Pygame + PygButton detecting

感情迁移 提交于 2019-12-25 04:25:15
问题 I'm using Python 3.3 with Pygame and PygButton (low rep don't allow me more than two links) My files at the moment are [ int.py http://pastebin.com/sDRhieCG ] and [ scene.py http://pastebin.com/Y2Mgsgmr ]. The idea is making a mainloop in int.py the smaller as possible. The code has a commented-out example of the start_screen buttons at the mainloop. It works, but with every new screen the mainloop would be bloated. So I created a Scene class to apply background, texts and buttons. It works,

how to manipulate an image very fast in accordance to an own math function in python

試著忘記壹切 提交于 2019-12-25 04:25:02
问题 I'm trying to create a 360 degree camera just like google street cameras (This is my whole code if you are interested) I have a individual kind of perspective equation that map pixel [xold,yold] to [xnew,ynew] in accordance to Alpha and Beta angles as inputs. To simplify that equation and my question, i assume i'm just trying to rotate an image. Now my question is how to rotate an image by using rotation equation on each pixel very fast on pygame or anyother intractive shell: xnew = xold *

Using pygame.sprite.spritecollideany Python

眉间皱痕 提交于 2019-12-25 04:24:50
问题 I am new to python programming, and I am practicing by making a Alien Invasion game. This is a classic game configuration, there are rows of aliens you have to shot down before they make it to the bottom and collide with your ship. Here is my game_functions code: import sys import pygame from bullet import Bullet from alien import Alien def check_keydown_events(event, ai_settings, screen, ship, bullets): """Respond to keypresses.""" if event.key == pygame.K_RIGHT: ship.moving_right = True

Displaying platforms using strings (Pygame)

末鹿安然 提交于 2019-12-25 04:03:46
问题 I'm having troubling getting a platform to display in areas that I have 'P' string in. I'm trying to create a level in pygame using strings instead of set coordinates for every platform. Here's a sample... class Level_01(Level): def __init__(self, player): self.background = forest_bg Level.__init__(self, player) platforms = [] x = y = 0 level = [' ', 'P ', ' ', ' P ', ' ', 'PPPPPPPPPPPP',] # build the level for row in level: for col in row: if col == 'P': P = Platform(x, y) platforms.append(P

Can't get pygame.Surface.get_at() to work properly

馋奶兔 提交于 2019-12-25 03:58:14
问题 I am trying to retrieve the color I have drawn onto my display using pygame, but I can't seem to get it to work. I took out some irrelevant code for easier reading, but here is what I have. import pygame import sys from pygame.locals import * pygame.init() blue = (0,0,255) #sets up screen setDisplay = pygame.display.set_mode((400,400)) pygame.display.set_caption('Connections') pygame.draw.circle(setDisplay, blue, (20,20), 10, 10) while True: for event in pygame.event.get(): if event.type ==