-1

I added some images to my shooter game but i coudnt find how to position them correctly to shoot them from center of spaceships

RED_BULLET_IMG = pygame.image.load(os.path.join("Assets", "02.png"))
RED_BULLET_RECT = RED_BULLET_IMG.get_rect(center = (350, 350))

YELLOW_BULLET_IMG = pygame.image.load(os.path.join("Assets", "10.png"))
YELLOW_BULLET_RECT = YELLOW_BULLET_IMG.get_rect()

I added theese images

    for bullet in red_bullets:
        WIN.blit(RED_BULLET_IMG, RED_BULLET_RECT)
    for bullet in yellow_bullets:
        WIN.blit(YELLOW_BULLET_IMG, YELLOW_BULLET_RECT)

And i replace them with bullets its actually working, but it doesnt move on screen

1 Answers1

-1

Ah, the classic struggle of positioning images in Pygame.

RED_BULLET_IMG = pygame.image.load(os.path.join("Assets", "02.png"))
RED_BULLET_RECT = RED_BULLET_IMG.get_rect(center=(spaceship_x + spaceship_width / 2, spaceship_y + spaceship_height / 2))

YELLOW_BULLET_IMG = pygame.image.load(os.path.join("Assets", "10.png"))
YELLOW_BULLET_RECT = YELLOW_BULLET_IMG.get_rect(center=(spaceship_x + spaceship_width / 2, spaceship_y + spaceship_height / 2))



for bullet in red_bullets:
    bullet.y -= bullet_speed  # Adjust the y-coordinate to move the bullet up (or down, depending on your coordinate system)
    WIN.blit(RED_BULLET_IMG, bullet)

for bullet in yellow_bullets:
    bullet.y += bullet_speed  # Adjust the y-coordinate to move the bullet down (or up, depending on your coordinate system)
    WIN.blit(YELLOW_BULLET_IMG, bullet)

Happy Codding. Remember, attention to detail is key in programming!