I am making a very simple game that has coins on a surface, a player that is a black block (for now) and a computer AI that is, for now, a penguin. Last night I got everything I implemented to work. I say implemented because I haven't even started implementing an endgame scenario/condition. I was so happy last night that I got the AI to work.... too good. In this small paradigm it is impossible to win. I decided to take away the AI's ability to make diagonal turns. I did this by making a single if statement into an elif:
# Uncomment if you want the AI to be able to go diagonal
'''def hunt(self, player_xy):
if player_xy[0] > self.get_x():
self.set_x(self.get_x() + 3)
elif player_xy[0] < self.get_x():
self.set_x(self.get_x() - 3)
if player_xy[1] > self.get_y():
self.set_y(self.get_y() + 3)
elif player_xy[1] < self.get_y():
self.set_y(self.get_y() - 3) '''
def hunt(self, player_xy):
if player_xy[0] > self.get_x():
self.set_x(self.get_x() + 3)
elif player_xy[0] < self.get_x():
self.set_x(self.get_x() - 3)
elif player_xy[1] > self.get_y():
self.set_y(self.get_y() + 3)
elif player_xy[1] < self.get_y():
self.set_y(self.get_y() - 3)
I have a label on the background that tells me where the AI is, so I can track it. When the if statement is still an if statement, I can see the label move and I can see the sprite move. When I change the one line to an elif, I still see the label move (therefore the sprite is moving) but I don't see the sprite anywhere. Seriously, 1 line.
Any thoughts on why this is happening or what I should do about it? I can post more of my code, but since I have it isolated to 1 line, I didn't think it would help.