pygame

How to add a background image in python-pygame

谁都会走 提交于 2021-01-28 11:31:51
问题 I'm making a game, brickbreaker. I'm tring to add an image on the background, but it doesn't show up. I tried some other ways: Class background(pygame.sprite.Sprite) - I can see image, but it hides game import pygame from pygame.locals import * import sys class Brickbreaker: def __init__(self): self.screen = pygame.display.set_mode((600, 600)) self.image = pygame.image.load("bg.png") self.blocks = [] self.paddle = [[pygame.Rect(300, 500, 20, 10), 120], [pygame.Rect(320, 500, 20, 10),100],

Pygame sprite not moving while jumping

空扰寡人 提交于 2021-01-28 11:26:46
问题 I'm confused why my sprite is not moving while jumping. I've checked several times and changed my code over and over with no luck. My code is below and contains 3 pages, first contain the main loop, second contain the player class and third contain some game functions. Main import pygame from player import Player import game_functions as gf import sys import time def run_game(): # Intialise the game and start the screen pygame.init() screen = pygame.display.set_mode((800, 600)) pygame.display

How do I change the volume of the sound or music in PyGame?

北慕城南 提交于 2021-01-28 11:22:49
问题 How to change volume in PyGame like changing the volume by going to the settings. I made the UI elements, just need to know how to change the volume. I know I am not clear, but you can understand me. Please help 回答1: Changing the volume depends on whether you are playing a pygame.mixer.Sound object or playing the music via the pygame.mixer.music module. The volume of a Sound can be changed by set_volume(). The volume argument is a value in range [0.0, 1.0]: pygame.mixer.init() my_sound =

How Can I Improve This Jump?

吃可爱长大的小学妹 提交于 2021-01-28 10:47:25
问题 VIDEO < this is my problem my jump is jumping way to fast and I dont event have time to move beaten where I Jumped from Is there a way I can improve this jump without slowing down my sprite fps? if I tried to slow down my sprite fps that would cause my sprite to play its animation way to many times when I jump. I am trying to make this jump smooth as possibale but right now its jumping way to fast and also the animation plays to fast where my jump is # our main loop run = True while run: for

Ship moves up and left faster than down and right when rotating in pygame

被刻印的时光 ゝ 提交于 2021-01-28 09:55:35
问题 I am working on a simple game. I created a pygame sprite which and tested it by making it move forward and rotating at a consistent speed. However, it seams to be moving left and up (where sin and cos are negative) quicker than right and down (where sin and cos are positive). I tested it without moving and just rotating and it works. Here is the code: import pygame import sys from math import cos, sin, pi from time import sleep SCREEN_WIDTH = 800 SCREEN_HEIGHT = 800 FPS = 60 pygame.init()

Ship moves up and left faster than down and right when rotating in pygame

安稳与你 提交于 2021-01-28 09:55:32
问题 I am working on a simple game. I created a pygame sprite which and tested it by making it move forward and rotating at a consistent speed. However, it seams to be moving left and up (where sin and cos are negative) quicker than right and down (where sin and cos are positive). I tested it without moving and just rotating and it works. Here is the code: import pygame import sys from math import cos, sin, pi from time import sleep SCREEN_WIDTH = 800 SCREEN_HEIGHT = 800 FPS = 60 pygame.init()

Creating collision in pygame [closed]

做~自己de王妃 提交于 2021-01-28 08:05:17
问题 Closed. This question needs debugging details. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . Improve this question i'm having a problem with my code. So, I want to create a game, in Pygame, where the bananas fall from the sky, and the monkey have to grab them. I'm having quite a hard time creating a collision between those two (spent hours trying already). So, this is my code: import pygame,

How to import all images from a user specified folder in python using pygame

对着背影说爱祢 提交于 2021-01-28 07:55:14
问题 I m new to python, and I'm working on pygame. For my project, i need to import all the images from a user specified folder. Is there any function in pygame to import only the image files from the folder? or guide me to filter only the image files among all files from the imported folder. Sorry, if the question is too basic. 回答1: I don't know about pygame but you with plain python is fairly simple to get all image files within a folder: import imghdr import os for dirpath, dirnames, filenames

Why do group lists in pygame have to have “update” functions, and not any other?

大兔子大兔子 提交于 2021-01-28 07:16:21
问题 I made a small particles application, but I was testing it and the function at the bottom has to be called "update". I thought the function name, just like variables, was just a name. I thought it didn't matter what it was named, as long as it's the same when you call it. Apparently I was wrong. It will only recognize "update". If I change the function to "move", it will throw an error. Could someone explain why it's like this? import pygame import random pygame.init() win_height=600 win

Pygame make a circle rotate around another

被刻印的时光 ゝ 提交于 2021-01-28 07:05:51
问题 I would like to make some kind of solar system in pygame. I've managed to do a fixed one but I thought it would be more interesting to do one with planets moving around the sun and moons around planets etc. Is there a way I could do that (using pygame if possible)? What I would like is : Sun = pygame.draw.circle(...) planet1 = pygame.draw.circle(...) etc. a = [planet1, planet2, ...] for p in a: move p[2] to pos(x, y) That is what I think would work but I'm not sure how to do it. Also, I've