I'm sorry for editing this question. I really have a hard time explaining my question because this thing is really nerve wracking. I started about 3 weeks ago and my mind is already exploding. To summarize what I want, this is the code right here:
import sys
import pygame
pygame.init()
# Setting up a window
screen = pygame.display.set_mode((1200, 800))
screen_rect = screen.get_rect()
# Caption
pygame.display.set_caption("space shooter".title())
# Setting up the icon
icon = pygame.image.load("undertake.png").convert_alpha()
pygame.display.set_icon(icon)
# Identifying a Background
bg = pygame.image.load("bg.png").convert_alpha()
# Setting up the jet
jet = pygame.image.load("jet.png").convert_alpha()
jet_rect = jet.get_rect()
jet_rect.centerx = screen_rect.centerx
jet_rect.bottom = screen_rect.bottom
# Setting up 2 bullets
bullet = pygame.image.load("pixel_laser_red.png").convert_alpha()
bullet_rect = bullet.get_rect()
bullet_state = "ready"
# Moving the jet
def move_jet(x):
jet_rect.centerx += x
# Changing the bullet state
def fire_bullet():
global bullet_state
bullet_state = "fire"
screen.blit(bullet , (bullet_x - 28 , bullet_y +7) )
# Adding Boundaries
def boundaries():
if jet_rect.left >= 1200:
jet_rect.right = 0
elif jet_rect.right <= 0:
jet_rect.left = 1200
# Game Loop
while True:
screen.blit(bg, (0, 0))
screen.blit(jet, jet_rect)
# EVENTS
for event in pygame.event.get():
# Quitting
if event.type == pygame.QUIT:
sys.exit()
# KeyStrokes
pressed = pygame.key.get_pressed()
jet_xincrement = 0
if pressed[pygame.K_RIGHT]:
jet_xincrement += 3
if pressed[pygame.K_LEFT]:
jet_xincrement -= 3
if pressed[pygame.K_SPACE]:
if bullet_state == "ready":
bullet_x = jet_rect.centerx
bullet_y = jet_rect.top
fire_bullet()
if bullet_state == "fire":
bullet_y -= 3
screen.blit(bullet, (bullet_x - 28, bullet_y + 7))
if bullet_y < 400:
bullet_state = "ready"
boundaries()
move_jet(jet_xincrement)
pygame.display.flip()
My question: When I hold the space bar the fire_bullet function is called which changes the bullet_state to "fire" and prints it in my required position, when the bullet state is "fire" the bullet is printed each time in the loop incremented by -3 in the y direction until it reaches 400 where the bullet_state is then changed to ready, but the same bullet object is reseted I want a new bullet to shoot when the previous bullet reaches 400. I hope that makes my point clear and I'm really sorry for any confusion