samedi 9 juillet 2016

How to make collisions in tkinter?

I am making a python game and I am not exactly sure how to make the enemy's and the player have collisions. Could someone show me a easy way to add collisions to multiple things efficiently. I want the enemy in my python game to collide with the player. Here is the code I use to move the enemy to the player. This code moves the enemy but the enemy does not collide with the player.

if self.canvas.coords(self.man)[0] > self.canvas.coords(Man1.man)[0]:
    self.canvas.move(self.man,-1,0)
if self.canvas.coords(self.man)[0] < self.canvas.coords(Man1.man)[0]:
    self.canvas.move(self.man,1,0)
if self.canvas.coords(self.man)[1] < self.canvas.coords(Man1.man)[1]:
    self.canvas.move(self.man,0,1)
if self.canvas.coords(self.man)[1] > self.canvas.coords(Man1.man)[1]:
    self.canvas.move(self.man,0,-1)

Aucun commentaire:

Enregistrer un commentaire