The problem I have is that I have imported my sprite into my game, Its a still image and I want to move it, however I am having issues although I have an idea something in the mainloop must be changed, I am clueless on what exactly to change. The variable avatar is the sprite.
import pygame
pygame.init()
window = pygame.display.set_mode((750, 750))
pygame.display.set_caption("PeaShooters")
avatar = pygame.image.load('Sprite 1 Red.png')
background = pygame.image.load('Bg.jpg')
x = 64
y =64
width = 40
height = 60
vel = 5
white = (255, 255, 255)
def drawGrid():
window.blit(background, (0,0))
window.blit(avatar, (300,500))
pygame.draw.line(window, white, [50,50], [50, 600], 5)
pygame.draw.line(window, white, [50,50], [600, 50], 5)
pygame.draw.line(window, white, [600,600], [600, 50], 5)
pygame.draw.line(window, white, [50,600], [600, 600], 5)
pygame.draw.line(window, white, [50,450], [600, 450], 5)
pygame.display.update()
running = True
while running:
pygame.time.delay(100)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
keys = pygame.key.get_pressed()
if keys[pygame.K_w] and y > 455:
y += vel
if keys[pygame.K_a] and x > 55:
x -= vel
if keys[pygame.K_s] and y < 565:
y -= vel
if keys[pygame.K_d] and x < 575 :
x += vel
*I gathered something needs to be changed around here.
drawGrid()
pygame.quit()