pygame

How could I optimise this simple python pygame code

为君一笑 提交于 2021-02-04 08:14:08
问题 I've been set a challenge to make a game using pygame ( I am making snake so it should be easy... but I've never used pygame) so using a more efficient language isn't an option.So my question is that I updating the snake grid is too slow and I'm not experienced enough in pygame to fix this, can anyone who is help.Also as a note if I only fill the grid it doesn't clear behind the Snake. Using python 3.8 import pygame import time import random pygame.init() display_width = 800 display_height =

Pygame : Two layered scrolling background, can you help me?

送分小仙女□ 提交于 2021-02-04 08:09:18
问题 I would like create a two layered scrolling background but everytime I run the programm below it make everything wrong, and I don't know why :/ Can you help me ? I've try the code below : 'bg scrolling try' import pygame as pg from pygame.locals import * pg.init() screen = pg.display.set_mode((1920, 1080), pg.NOFRAME) a = True land_0 = pg.image.load('sprites/land_0.png').convert_alpha() land_1 = pg.image.load('sprites/land_1.png').convert_alpha() bg = pg.image.load('sprites/bg.png').convert

Why my pygame game with a tiled map is lagging?

时光怂恿深爱的人放手 提交于 2021-02-04 08:07:33
问题 I just started pygame and I started coding a little game, but when I put the code for the tiled map my game lagged! I don't understand why so I ask you. my code: import pygame from player import Player from level import Level clock = pygame.time.Clock() from pygame.locals import * pygame.init() WIDHT = 1024 HEIGHT = 768 MAP_FILE = "niveau.txt" pygame.display.set_caption("TEST") screen = pygame.display.set_mode((WIDHT, HEIGHT)) player = Player() moving_right = False moving_left = False moving

Why my pygame game with a tiled map is lagging?

坚强是说给别人听的谎言 提交于 2021-02-04 08:06:53
问题 I just started pygame and I started coding a little game, but when I put the code for the tiled map my game lagged! I don't understand why so I ask you. my code: import pygame from player import Player from level import Level clock = pygame.time.Clock() from pygame.locals import * pygame.init() WIDHT = 1024 HEIGHT = 768 MAP_FILE = "niveau.txt" pygame.display.set_caption("TEST") screen = pygame.display.set_mode((WIDHT, HEIGHT)) player = Player() moving_right = False moving_left = False moving

Why does pygame.display.update() not work if an input is directly followed after it?

余生长醉 提交于 2021-02-04 08:01:10
问题 In my program, I'm trying to have an input right after the display screen is updated in pygame. I noticed for some reason the screen is only updated AFTER the user enters in an input, although the input function is after pygame.display.update(). Why does this happen, and how can the code be fixed? # python 3.6.5 # pygame 1.9.3 def main(): pygame.draw.rect(screen,[235,235,235],(200,200,200,200)) pygame.display.update() input('') # input is shown first instead of the rectangle I expected the

Pygame: colliding rectangles with other rectangles in the same list

风流意气都作罢 提交于 2021-02-04 07:58:28
问题 I have a list of 10 drawn rectangles (referenced as cubes in my script) that are affected by gravity. I made a simple collision system for them to stop when they hit the ground. How can I make it so when 2 cubes collide they stop falling like they do with the ground? import pygame import time import random pygame.init() clock = pygame.time.Clock() wnx = 800 wny = 600 black = (0,0,0) grey = (75,75,75) white = (255,255,255) orange = (255,100,30) wn = pygame.display.set_mode((wnx, wny)) wn.fill

Adding a particle effect to my clicker game

爷,独闯天下 提交于 2021-02-04 07:52:55
问题 I'm currently making a Python clicking game using Pygame. Right now, there is a coin in the center of the screen that you can click. What I want to add now, it a little green "+$10" icon that appears somewhere next to the coin whenever someone clicks it. This is what I want the game to look like whenever someone clicks the coin: Here is the code of my coin functions: def button_collide_mouse(element_x, element_y, x_to_remove, y_to_remove): mouse_x, mouse_y = pygame.mouse.get_pos() if mouse_x

Adding a particle effect to my clicker game

♀尐吖头ヾ 提交于 2021-02-04 07:52:19
问题 I'm currently making a Python clicking game using Pygame. Right now, there is a coin in the center of the screen that you can click. What I want to add now, it a little green "+$10" icon that appears somewhere next to the coin whenever someone clicks it. This is what I want the game to look like whenever someone clicks the coin: Here is the code of my coin functions: def button_collide_mouse(element_x, element_y, x_to_remove, y_to_remove): mouse_x, mouse_y = pygame.mouse.get_pos() if mouse_x

trying creating dropdown menu pygame, but got stuck

*爱你&永不变心* 提交于 2021-02-04 07:49:56
问题 So so far here's my code: import pygame as pg pg.init() clock = pg.time.Clock() # Generating screen w_scr = 640 h_scr = 480 size_scr = (w_scr, h_scr) screen = pg.display.set_mode(size_scr) # Define color COLOR_INACTIVE = (100, 80, 255) COLOR_ACTIVE = (100, 200, 255) COLOR_LIST_INACTIVE = (255, 100, 100) COLOR_LIST_ACTIVE = (255, 150, 150) class DropDown(): # Test List option_list = ["Calibration", "Test"] def __init__(self, color_menu, color_option, x, y, w, h): self.color_menu = color_menu

How to display some text in pygame?

人走茶凉 提交于 2021-02-04 07:49:50
问题 I am currently on a pygame project and wanted to display some text. I have done this before in another program and it works just fine but when I write the exact same thing in this project, it gives this error : Traceback (most recent call last): File "C:\Users\Fazelifar\Desktop\Dot Game.py", line 197, in <module> myfont = pygame.font.SysFont(None, 15) File "C:\Users\Fazelifar\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pygame\sysfont.py", line 362, in SysFont return