pygame

Spawning multiple instances of the same object concurrently in python

走远了吗. 提交于 2021-02-12 09:24:37
问题 Hey I'm a beginner programmer who is starting with python and am starting out by making a game in pygames. The game basically spawns in circles at random positions, and when clicked give you points. Recently i've hit a roadblock when I want to spawn in multiple instances of the same object(in this case circles) at the same time. I've tried stuff like sleep() and some other code related to counters, but it always results in the next circle spawned overriding the previous one(i.e the program

How to move the background image with keys in pygame?

我与影子孤独终老i 提交于 2021-02-12 09:23:08
问题 I am making a game in pygame. In this game, the background image is large. On the screen, player only sees about 1/20th of the background image. I want, when player presses the left, right, up or down arrow keys, the background image moves respectively, but, it stops moving when player reaches the end of the image. I have no idea how to do this. My code up to this point :- import pygame FPS = 60 screen = pygame.display.set_mode((1000, 1000)) bg = pygame.image.load('map.png') clock = pygame

How do I make the screen ignore the background color of some image?

馋奶兔 提交于 2021-02-12 09:22:31
问题 I'm using python 2.7, and I am currently working on a basic game in pyagme for my school work. I downloaded an image from google, and it has a background color and I know it's RGB. I remember that there is a method that makes the screen ignore this RGB for the picture (the picture will appear without the background color) but I don't remember it. import pygame WINDOW_WIDTH = 1200 WINDOW_LENGTH = 675 IMAGE = r'C:\Users\omero\Downloads\BattleField.jpg' PISTOL_IMAGE = r'C:\Users\omero\Downloads

Spawning multiple instances of the same object concurrently in python

此生再无相见时 提交于 2021-02-12 09:21:33
问题 Hey I'm a beginner programmer who is starting with python and am starting out by making a game in pygames. The game basically spawns in circles at random positions, and when clicked give you points. Recently i've hit a roadblock when I want to spawn in multiple instances of the same object(in this case circles) at the same time. I've tried stuff like sleep() and some other code related to counters, but it always results in the next circle spawned overriding the previous one(i.e the program

How to move the background image with keys in pygame?

江枫思渺然 提交于 2021-02-12 09:20:20
问题 I am making a game in pygame. In this game, the background image is large. On the screen, player only sees about 1/20th of the background image. I want, when player presses the left, right, up or down arrow keys, the background image moves respectively, but, it stops moving when player reaches the end of the image. I have no idea how to do this. My code up to this point :- import pygame FPS = 60 screen = pygame.display.set_mode((1000, 1000)) bg = pygame.image.load('map.png') clock = pygame

pygame midi read PC (program change) messages

◇◆丶佛笑我妖孽 提交于 2021-02-11 17:11:48
问题 My goal is to listen to a MIDI to USB adapter that is connected to my guitar pedalboard switcher. When a program change, (PC) message is received, play the appropriate mp2 file. I've tried a number of different Python MIDI modules and pygame has got me the closest. Below is the code I have been tinkering with and it is printing messages when I send program messages for the pedal switcher. I just do not know how to extract and interpret what I need. For instance, the pedal switcher sends a PC

How to determine why objects pass through each other in Colliderect

喜夏-厌秋 提交于 2021-02-11 15:53:33
问题 For some reason the Colliderect won't work and the rain passes through pavement. This is really annoying because all of those unused sprites create tons of lag. import pygame import random class Square(pygame.sprite.Sprite): def __init__(self, x, y, size1, size2, speedx, speedy, colour): super().__init__() self.image = pygame.Surface([size1, size2]) self.image.fill(colour) self.speedx = speedx self.speedy = speedy self.rect=self.image.get_rect() self.rect.x=x self.rect.y=y def update(self):

How to determine why objects pass through each other in Colliderect

不打扰是莪最后的温柔 提交于 2021-02-11 15:52:48
问题 For some reason the Colliderect won't work and the rain passes through pavement. This is really annoying because all of those unused sprites create tons of lag. import pygame import random class Square(pygame.sprite.Sprite): def __init__(self, x, y, size1, size2, speedx, speedy, colour): super().__init__() self.image = pygame.Surface([size1, size2]) self.image.fill(colour) self.speedx = speedx self.speedy = speedy self.rect=self.image.get_rect() self.rect.x=x self.rect.y=y def update(self):

Pygame choose which display to use in fullscreen [duplicate]

喜你入骨 提交于 2021-02-11 15:40:23
问题 This question already has answers here : pygame dual monitors and fullscreen (2 answers) Closed last month . This is the code: #!/usr/bin/python import pygame, sys from pygame.locals import * import Tkinter as tk root = tk.Tk() pygame.init() w = 640 h = 400 RED = (255, 0, 0) GREEN = (0, 255, 0) BLUE = (0, 0, 255) YELLOW = (255, 255, 0) PINK = (255, 0, 255) CYAN = (0, 255, 255) WHITE = (255, 255, 255) screen = pygame.display.set_mode((w,h), RESIZABLE) clock = pygame.time.Clock() x = y = 100

Install Pygame with Anaconda

余生颓废 提交于 2021-02-11 15:37:37
问题 I'm trying to install pygame on my Mac and get a ton of errors. I'm not 100% sure what this is telling me, except that it's telling me a lot. Is it saying that Pygame is only compatible with Python 3.5? Because there was another ticket on StackOverflow (Install pygame with anaconda on mac) that said there was a problem with Python 3.5. I'd be surprised if it was incompatible with 3.7. And if it's not incompatible, what's the problem? Everything I find seems to be quite Windows-centric with