Jul-04-2020, 10:15 AM
So I've been working on my space invaders but I can't figure out how I have to solve that the bullet would stay on the same x coordinate when I press spcae again. Sorry English is not my first language and there is a mix of both English and Estonian ( kuul is bullet in Estonian and kiirus is speed). I have removed "spaceship" at the moment to see what the bullet does exactly behind the spaceship.
import pygame
from pygame.locals import *
running = True
pygame.init()
screen = pygame.display.set_mode((1000, 800))
enemy_pos = [500, 70]
ship_pos = [700, 500]
speed = 0.4
red = (255, 0, 0)
white = (255, 255, 255)
blu = (0, 0, 255)
kuul_img = pygame.image.load('bullet.png')
kuul_x = 0
kuul_y = 700
kuul_kiirus = 1
kuul_state = "valmis"
def fire_bullet(x, y):
global bullet_state
kuul_state = "fire"
screen.blit(kuul_img, (x + 16, y + 10))
print("b")
while running:
screen.fill((0, 0, 0))
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_a:
ship_pos[1] -= speed
elif event.key == pygame.K_d:
ship_pos[1] += speed
elif event.key == pygame.K_SPACE:
if kuul_state is "valmis":
print("a")
kuul_x = ship_pos[1]
fire_bullet(kuul_x, kuul_y)
if kuul_state is "fire":
kuul_y - kuul_kiirus
if kuul_y is 0:
kuul_y = 700
kuul_state = "valmis"
#pygame.draw.rect(screen, white, [ship_pos[1], ship_pos[0], 50, 50])
pygame.draw.rect(screen, red, [enemy_pos[0], enemy_pos[1], 50, 50])
pygame.display.update()
