pygame

how rotate the images with keyboards? [duplicate]

一笑奈何 提交于 2021-02-05 09:12:54
问题 This question already has answers here : How can I make a sprite move when key is held down [duplicate] (3 answers) How do I rotate an image around its center using Pygame? (6 answers) Closed 3 months ago . img1 = pygame.image.load(r"C:\Users\ga-sa\Downloads\As.png") img2 = pygame.image.load(r"C:\Users\ga-sa\Downloads\AssetsXOR.png") img3 = pygame.image.load(r"C:\Users\ga-sa\Downloads\AssetsNOT.png") img4 = pygame.image.load(r"C:\Users\ga-sa\Downloads\AssetsAND.png") background = pygame.image

Do not display removed sprites, Pygame

孤人 提交于 2021-02-05 09:12:46
问题 I am experiencing an issue with pygame. I am making a little game and if I die I would like to delete enemies sprites and reload them later when I respawn. I successfully delete them from their group but they still on the screen when I respawn. But the collide doesn't work anymore. I would like to remove the olds from the screen. Here's a minimal code for the example : from pygame import * import random import sys import pygame WIDTH = 600 HEIGHT = 750 FPS = 60 SPEEDX = 5 SPEEDY = 3 # define

How to make the path to songs in pygame relative

浪尽此生 提交于 2021-02-05 09:12:04
问题 Im working on a simple Snake game in python, and its working as intended here at home, but when I put the code on github, it doesn't find the path to the songs, I want to make this path relative, intead of absolute so it works on every computer. Here is the part of the code for the song files - def game_sound(s): """ Include the game sfx and music""" if s == 0: pygame.mixer.music.load("background.ogg") pygame.mixer.music.play(-1) elif s == 1: pygame.mixer.Sound("eating.wav").play() elif s ==

How to make the path to songs in pygame relative

守給你的承諾、 提交于 2021-02-05 09:07:11
问题 Im working on a simple Snake game in python, and its working as intended here at home, but when I put the code on github, it doesn't find the path to the songs, I want to make this path relative, intead of absolute so it works on every computer. Here is the part of the code for the song files - def game_sound(s): """ Include the game sfx and music""" if s == 0: pygame.mixer.music.load("background.ogg") pygame.mixer.music.play(-1) elif s == 1: pygame.mixer.Sound("eating.wav").play() elif s ==

How to make the path to songs in pygame relative

拈花ヽ惹草 提交于 2021-02-05 09:06:31
问题 Im working on a simple Snake game in python, and its working as intended here at home, but when I put the code on github, it doesn't find the path to the songs, I want to make this path relative, intead of absolute so it works on every computer. Here is the part of the code for the song files - def game_sound(s): """ Include the game sfx and music""" if s == 0: pygame.mixer.music.load("background.ogg") pygame.mixer.music.play(-1) elif s == 1: pygame.mixer.Sound("eating.wav").play() elif s ==

how to center image inside a rect pygame

笑着哭i 提交于 2021-02-05 09:01:33
问题 I want to centre an image inside a rect note that I am using the image rect but asseperate rect to mount the image on. rect_1 = pygame.Rect(1, 1, 178, 178) ... cross = pygame.image.load("cross.png").convert_alpha() cross_minified = pygame.transform.rotozoom(cross, 0, 0.25) ... screen.blit(cross_minified, rect_1) and after these codes I cannot find a way to center my x to the middle of the rect_1 it looks somewhat like this 回答1: Use the functionality of pygame.Rect. Get a rectangle with the

Game of Life - Overwriting the current generation instead of updating to the next

房东的猫 提交于 2021-02-05 08:54:06
问题 Below I have added my game of life code. The rules are defined correctly, and it runs smoothly. However, the game does not work as supposed. It is not updating to the next generation, but it seems to be overwriting the current generation. As an example: Three horizontal dots are supposed to turn into three vertical dots in the next generation, but this does not happen. The solution: I have two generations, the current and the next generation. It has to apply the rules to the current

how to control snake with only two keys i.e left and right

会有一股神秘感。 提交于 2021-02-05 08:36:25
问题 currently, i'm using all four keys to steer the snake left, right, up and down. I'm wondering how can i only use left and right key to move the snake around. if event.key == pygame.K_LEFT: snake.direction = 2 elif event.key == pygame.K_RIGHT: snake.direction = 3 elif event.key == pygame.K_UP: snake.direction = 0 elif event.key == pygame.K_DOWN: snake.direction = 1 def move(self): if self.direction is 0: self.dy = -self.block self.dx = 0 if self.direction is 1: self.dy = self.block self.dx = 0

Pygame wait for screen to update

試著忘記壹切 提交于 2021-02-05 08:33:09
问题 I just started with pygame, and I am just trying to move points across my screen. The problem is that it happens way to fast and my pygame screen freezes (Not Responding) while the loop runs and then only shows the last iterations position of dots. I am thinking the updating happens to fast. When I include pygame.event.wait() then as I give an input the loop progresses and I can follow live in the window how the dots are moving across the screen. However, I would like to have it that they

glDrawArrays only updates when i exit

♀尐吖头ヾ 提交于 2021-02-05 08:29:50
问题 I have this code in python3 which doesn't work on windows machines but it worked on a linux machine. I draw a green screen and a red triangle but the red triangle only appears when I exit. import pygame import numpy import OpenGL.GL as gl import OpenGL.GL.shaders as shaders from pygame.rect import Rect RED = (255, 0, 0) WHITE = (255, 255, 255) pygame.init() screen = pygame.display.set_mode((800, 600), pygame.OPENGL) vertes_shader = """ #version 330 in vec4 position; void main() { gl_Position