CoilBrew / sidescroller

0 stars 0 forks source link

Update Player position #2

Closed chrisgrounds closed 7 years ago

chrisgrounds commented 7 years ago

We want the Player to move the correct way when you hit "ASDW". We will represent this movement as a property on the Player object. For example:

class Player(object):
    def __init__(self):
        self.position = x

You will want to use the move() method on the Player to update this value. For example, when the move() method gets "A" as an input, it moves the player to the left by updating the self.position value:

def move(self, direction):
    if direction == "A":
        self.position = self.position - 10

This would move the player to the left by a value of 10, by updating the position property by taking away 10 from it.

Lee has implemented something in main.py, from lines 42-67. So you could delete all of that and essentially move it into the Player class.

Let me know if any of that is not clear.

chrisgrounds commented 7 years ago

@README1ST

So, one extra thing I would say is for you to move the key_pressed logic into the Event class. So the event class would register a key input (say, left arrow), then call player.move() and pass in some value that represents the left arrow.

So the flow of logic would be:

Game loop -> You press the left arrow -> Event class detects it ("if key_pressed...") -> player.move("left") is called.