I am making a game in python pygame and I am on setting up the keyinput and have came across a part where I don't know what to do at all.
All of the variables are defined as there are no errors, but no key detections are being made at all so I don't know what to do.
I have had a look at other questions and tried there answers but haven't solved the problem yet
class Player(object):
def __init__(self, x, y, velocity):
self.x = x
self.y = y
self.width = 32
self.height = 32
self.velocity = velocity
self.render()
self.tick()
def movement(self):
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
print("done")
if event.key == pygame.K_w:
self.y -= self.velocity
elif event.key == pygame.K_s:
self.y += self.velocity
elif event.key == pygame.K_d:
self.x += self.velocity
elif event.key == pygame.K_a:
self.x -= self.velocity
elif event.key == pygame.K_ESCAPE:
pygame.quit()
elif event.type == pygame.QUIT:
pygame.quit()
def tick(self):
self.movement()
def render(self):
pygame.draw.rect(window.WINDOW, (255, 0, 0), (self.x, self.y,
self.width, self.height))
pygame.display.update()
There are no errors but when it is supposed to print out "done" it doesn't so I think it has something to do with the KEYDOWN at the start or before that.
for
is being executed. – martineauPlayer.movement()
method being called from a main event processing loop somewhere, as pygame apps typically have? – martineau