So Im really new to pygame and trying to recreate space invaders. This is just the code for the enemy, can anyone tell me why it keep messing up whenever it hits a boundary? Im using pycharm to code this btw.
import pygame
screen = pygame.display.set_mode((800, 600))
pygame.init()
enemyIMG = pygame.image.load("ufo (2).png")
enemyX = 360
enemyY = 50
enemyY_change = 40
enemyX_change = 0.3
def enemy(x, y):
screen.blit(enemyIMG, (x, y))
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
enemyX += enemyX_change
if enemyX <= 0:
enemyY += enemyY_change
enemyX_change = 0.3
elif enemyX >= 736:
enemyY += enemyY_change
enemyX_change = -0.3
enemy(enemyX, enemyY)
pygame.display.update()
I was trying to make the alien hit a boundary then go down 40 pixels, then go the other way. But instead, it created a clone of its self and stayed there while the other clone continued as normal.