pygame

How do I blit an image on a keypressed event in pygame

旧街凉风 提交于 2020-06-18 08:40:34
问题 I'm trying to blit an image to the screen when the event K_SPACE is triggered. However, when I press space nothing happens. I've tried moving where the screen is updated or flipped, but i've hit a brick wall. Here is my code: def Play(): background = pygame.image.load(bifPlay).convert() char = pygame.image.load(mif).convert_alpha() bullet = pygame.image.load(bulletLoad).convert() zombie = pygame.image.load(zombieLoad).convert_alpha() #converting images needed so pygame can use them x,y = 115

How do I blit an image on a keypressed event in pygame

旧巷老猫 提交于 2020-06-18 08:40:11
问题 I'm trying to blit an image to the screen when the event K_SPACE is triggered. However, when I press space nothing happens. I've tried moving where the screen is updated or flipped, but i've hit a brick wall. Here is my code: def Play(): background = pygame.image.load(bifPlay).convert() char = pygame.image.load(mif).convert_alpha() bullet = pygame.image.load(bulletLoad).convert() zombie = pygame.image.load(zombieLoad).convert_alpha() #converting images needed so pygame can use them x,y = 115

Sin and Cos function incorrect in python [duplicate]

﹥>﹥吖頭↗ 提交于 2020-06-17 15:42:09
问题 This question already has answers here : Unusual Math with incorrect results? [duplicate] (3 answers) Closed 5 years ago . I am trying to make a top down shooter in pygame. I when I added the code to make the player move in the direction they are facing. The player would move in weird directions. This is the code I am using: if pygame.key.get_pressed()[K_UP]: playerX = playerX - math.cos(playerFacing) playerY = playerY - math.sin(playerFacing) if pygame.key.get_pressed()[K_DOWN]: playerX =

How Can I Make My Enemys Projectile Attack The Player Where Ever The Player Moves?

不问归期 提交于 2020-06-17 13:15:48
问题 I have an enemy that shoots projectiles but only shoots to the right I want it to shoot at the player with any position I don't know how to do that heres a vid what I have done so fare if you could walk me throw the steps on how to do it that would be great Thank You this is what I have done so fare it only shoots to the right I want it to shoot at the player within any position the player is at for shootss in shootsright: if shootss.x < 500 and shootss.x > 0: shootss.x += 7 else: shootsright

How Can I Make My Enemys Projectile Attack The Player Where Ever The Player Moves?

核能气质少年 提交于 2020-06-17 13:15:07
问题 I have an enemy that shoots projectiles but only shoots to the right I want it to shoot at the player with any position I don't know how to do that heres a vid what I have done so fare if you could walk me throw the steps on how to do it that would be great Thank You this is what I have done so fare it only shoots to the right I want it to shoot at the player within any position the player is at for shootss in shootsright: if shootss.x < 500 and shootss.x > 0: shootss.x += 7 else: shootsright

Enemys Wont Move Left And Right How Do I Fix This?

风格不统一 提交于 2020-06-17 09:20:15
问题 I made my enemy class and underneath it I made a funtion that lets my enemy move left and right but for some reason it blits more then 1 enemy and stay at one position VIDEO # enemys class class enemy: def __init__(self,x,y,height,width,color): self.x = x self.y =y self.esright = [pygame.image.load("esright1.png"), pygame.image.load("esright1.png"), pygame.image.load("esright2.png"), pygame.image.load("esright3.png"), pygame.image.load("esright4.png"), pygame.image.load("esright5.png"),

Character moves slowly when grid is displayed in pygame

送分小仙女□ 提交于 2020-06-16 20:49:10
问题 I am making a snake game in pygame and I noticed a wierd thing. Whenever I am displaying a grid my character runs slowly. Here is the main function of my program. I have just started learning pygame! def main(): global SCREEN, CLOCK pygame.init() CLOCK = pygame.time.Clock() SCREEN.fill(BLACK) x = 0 y = 0 velocity = 20 x_change = 0 y_change = 0 while True: drawGrid() for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() if event.type == pygame.KEYDOWN: if

Creating simple python game - button functions

我是研究僧i 提交于 2020-06-16 17:27:38
问题 I am creating a simple python game and in it, a character moves around to collect items. I have created the character moving around and when they go over an item (an image), text pops up asking if they want to pick up the item as well as buttons which say 'yes' and 'no'. If they click yes, the item should disappear and then they return to the game. If they click no, the item will stay there and they should return to the game. To get rid of the item, I have tried to redraw the screen without

Creating simple python game - button functions

倖福魔咒の 提交于 2020-06-16 17:27:03
问题 I am creating a simple python game and in it, a character moves around to collect items. I have created the character moving around and when they go over an item (an image), text pops up asking if they want to pick up the item as well as buttons which say 'yes' and 'no'. If they click yes, the item should disappear and then they return to the game. If they click no, the item will stay there and they should return to the game. To get rid of the item, I have tried to redraw the screen without

Module 'pygame' has no 'QUIT' member

a 夏天 提交于 2020-06-16 04:49:12
问题 I'm trying to create a sidescroller game in pygame and it just makes a black screen when it should make a player sprite walking across a screen which increases speed as time goes along. When I debug in vscode it comes up with E1101:Module 'pygame' has no 'QUIT' member . QUIT seems to be in the event.get module so I don't know why this is happening I'm following the code from https://www.youtube.com/watch?v=PjgLeP0G5Yw&index=1&list=PLzMcBGfZo4-nh5Txa7ypUiv_4EVq4dgKc import pygame from pygame