The first thing we want to do is uncomment the line in Pacman's update method. We commented this out previously to show the previous movement. We also want to comment out the setPosition call in the updateDirection method. This is what made Pacman jump from one node to the next. Instead, we'll take that node and set it as Pacman's node. This node is always either the node Pacman is on or moving towards. So now instead of telling him to jump to that node directly, we're telling him to simply move to that node.
If you were to run the game after making these changes, then press a valid direction key, you'd see pacman moving smoothly. But the issue is that he pypasses the next node. We need him to be able to detect when he's reached the next node.
pacman.py
def updateDirection(self, direction):
if self.checkValidDirection(direction):
self.direction = direction
# self.setPosition(self.node.getNeighborByDirection(direction))
self.node = self.node.getNeighborByDirection(direction)
def update(self, dt):
self.position += self.direction * self.speed * dt
