When I run this, my charactor won't move, i don't get any errors, he just doesn't move. I've been trying to fix this for ages to no avail, heres my code:
import pygame
pygame.init()
class Player:
def __init__(self, speed, image):
self.move_speed = speed
##self.x = 640/2
##self.y = 480/2
self.speed = [640/2,480/2]
self.image = pygame.image.load(image)
def update(self):
self.x = self.speed[0]
self.y = self.speed[1]
def walk_left(self):
self.speed[0] -= self.move_speed
def walk_right(self):
self.speed[0] += self.move_speed
def walk_up(self):
self.speed[1] += self.move_speed
def walk_down(self):
self.speed[1] -= self.move_speed
def main():
clock = pygame.time.Clock()
p = Player(2, "rifleman_blu.png")
screen = pygame.display.set_mode((640,480))
while True:
clock.tick(60)
p.update()
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
return
elif event.type == pygame.K_LEFT:
p.walk_left()
elif event.type == pygame.K_RIGHT:
p.walk_right()
elif event.type == pygame.K_UP:
p.walk_up()
elif event.type == pygame.K_DOWN:
p.walk_down()
screen.blit(p.image, (p.speed[0], p.speed[1]))
pygame.display.flip()
if __name__ == '__main__': main()
Any help would be greatly appreciated, thanks in advance!