Dzień Dobry/Dobry Wieczór
Mam problem z strzelaniem w mojej prostej grze w bibliotece pygame. Nie widać pocisków na ekranie a gra nie pokazuje żadnych błędów (funkcja odpowiadająca za strzelanie to shoot()) po za tym po uruchomieniu jest brak odpowiedzi.
import pygame
pygame.font.init()
width = 500
height = 500
WIN = pygame.display.set_mode((width, height))
pygame.display.set_caption("Karp's Game for science")
def drawwindow(Player):
WIN.fill((255, 255, 255))
font = pygame.font.SysFont('comicsans', 100)
text = font.render("Karp's Game", 1, (255, 0, 0))
WIN.blit(text, (width - 460, height/3))
pygame.draw.rect(WIN, (0, 0, 0), Player)
pygame.display.update()
def movement(Player, bullet_up, bullet_down, bullet_left, bullet_right, bullets):
key_pressed = pygame.key.get_pressed()
if key_pressed[pygame.K_w] and Player.y - 5 > 0:
Player.y -= 1
if key_pressed[pygame.K_s] and Player.y + 5 < height - 50:
Player.y += 1
if key_pressed[pygame.K_a] and Player.x - 5 > 0:
Player.x -= 1
if key_pressed[pygame.K_d] and Player.x + 5 < width - 50:
Player.x += 1
if key_pressed[pygame.K_SPACE]:
bullets.append(bullet_up)
bullets.append(bullet_down)
bullets.append(bullet_left)
bullets.append(bullet_right)
pygame.draw.rect(WIN, (0, 0, 255), bullet_up)
pygame.draw.rect(WIN, (0, 0, 255), bullet_down)
pygame.draw.rect(WIN, (0, 0, 255), bullet_left)
pygame.draw.rect(WIN, (0, 0, 255), bullet_right)
shoot(bullet_up, bullet_down, bullet_left, bullet_right, bullets, Player)
def shoot(bullet_up, bullet_down, bullet_left, bullet_right, bullets, Player):
bullet_up.x, bullet_up.y = Player.x, Player.y
bullet_down.x, bullet_down.y = Player.x, Player.y
bullet_left.x, bullet_left.y = Player.x, Player.y
bullet_right.x, bullet_right.y = Player.x, Player.y
shoot = True
while shoot:
bullet_up.y -= 0.01
bullet_down.y += 0.01
bullet_left.x -= 0.01
bullet_right.x += 0.01
def main():
Player = pygame.Rect(250, 250, 50, 50)
bullet_up = pygame.Rect(10, 0, 5, 15)
bullet_down = pygame.Rect(10, 0, 5, 15)
bullet_left = pygame.Rect(10, 0, 15, 5)
bullet_right = pygame.Rect(10, 0, 15, 5)
bullets = []
run = True
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit
run = False
drawwindow(Player)
movement(Player, bullet_up, bullet_down, bullet_left, bullet_right, bullets)
main()