Animated lemming

This commit is contained in:
theo@manjaro 2021-09-11 13:29:02 +02:00
parent 5249782d6b
commit a3a70e9b9a
9 changed files with 16 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 825 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 831 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 813 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 859 B

View File

@ -20,6 +20,14 @@ class Lemming(BaseObject):
self.restx = 0
self.resty = 0
# Sprites
self.orientations = ["Right","Left","Left","Right"]
self.sprites = {}
for i in self.orientations:
self.sprites[i] = game.getSpriteDir("lemmings/"+i+"/")
self.spriteindex = 0
self.animspeed = 0.2
def step(self):
# Lean towards the normal speed
@ -50,6 +58,9 @@ class Lemming(BaseObject):
if distance<=self.radius:
self.selected = True
# Animation
self.spriteindex+=self.game.dt*self.animspeed*self.speed
def launch(self):
# Launch itself in the mouse direction
if len(self.cachedrel)>self.mincachedsize:
@ -68,3 +79,8 @@ class Lemming(BaseObject):
self.resty = vely-int(vely)
self.rect[0]+=int(velx)
self.rect[1]+=int(vely)
def draw(self):
orientation = self.orientations[int(self.direction%360/361*4)]
sprites = self.sprites[orientation]
self.game.lib.drawcenter(self.game,sprites[int(self.spriteindex)%len(sprites)],self.rect.center[0],self.rect.center[1])