Ok so im new to PyGame, and im making a space invader game, im currently building the movement script.
for some reason my character is infinitely moving to the right when i press the right key.. i know this must be a really simple solution i am just not seeing it lol i would appreciate an answer.
import pygame
pygame.init()
screen = pygame.display.set_mode((800, 600))
pygame.display.set_caption('Space Invader')
icon = pygame.image.load('pepper.png')
pygame.display.set_icon(icon)
#Player
playerImg = pygame.image.load('sombreroship.png')
playerX = 370
playerY = 480
playerX_Change = 0
def player (x, y): screen.blit(playerImg, (x, y) )
running = True
while running:
# RGB STANDS FOR RED, GREEN, BLUE THE NUMBERS GOES MAX TO 255 FOR EXAMPLE_:
screen.fill((0, 0, 30)) # this will display yellow
for event in pygame.event.get():
if event.type == pygame.QUIT: #if we click the X the program ends
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
playerX_Change = -0.1
if event.key == pygame.K_RIGHT:
playerX_Change = 0.1
if event.type == pygame.KEYUP:
if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT:
playerX_Change = 0.1
playerX += playerX_Change
player(playerX, playerY)
pygame.display.update()