diff --git a/gamedata/objects/ingame/lemmings.py b/gamedata/objects/ingame/lemmings.py index b66fd28..fb8d97b 100644 --- a/gamedata/objects/ingame/lemmings.py +++ b/gamedata/objects/ingame/lemmings.py @@ -30,6 +30,9 @@ class Lemming(BaseObject): self.spriteindex = 0 self.animspeed = 0.2 + self.tiles = game.gameloop.findname("Tiles")[0] + self.manager = game.gameloop.findname("Manager")[0] + def step(self): # Depth updating based on position @@ -69,6 +72,19 @@ class Lemming(BaseObject): # Animation self.spriteindex+=self.game.dt*self.animspeed*self.speed + + # Check if still on ground + gridx = int((self.rect.center[0]-self.tiles.rect[0])/self.tiles.cellsize) + gridy = int((self.rect.center[1]-self.tiles.rect[1])/self.tiles.cellsize) + dead = True + if 0<=gridyself.mincachedsize: diff --git a/gamedata/objects/ingame/manager.py b/gamedata/objects/ingame/manager.py index 53a9399..3609526 100644 --- a/gamedata/objects/ingame/manager.py +++ b/gamedata/objects/ingame/manager.py @@ -12,6 +12,8 @@ class Manager(BaseObject): self.speedmargin = 6 self.stepmargin = 0.4 self.spawntimer = game.lib.Timer(self.basetime) # Time elapsing each lemming spawn + self.deathtimer = game.lib.Timer(1) # Time betwin each life loss + self.invincible = False self.scoreratio = 0.4 # Points earned per seconds and per lemming # Summon the tiles @@ -22,14 +24,27 @@ class Manager(BaseObject): self.game.gameloop.summon(Spawner(self.game,self.tiles)) def step(self): - for i in self.game.gameloop.findname("Lemming"): + nblemmings = len(self.game.gameloop.findname("Lemming")) + # Updating score + for i in range(nblemmings): self.score+=self.scoreratio*self.game.dt - if self.spawntimer.tick(self.game.dt): + # Spawning more lemmings + if self.lives>0 and nblemmings>0 and self.spawntimer.tick(self.game.dt): self.game.gameloop.summon(Spawner(self.game,self.tiles,speedmargin=int(self.speedmargin+0.5))) self.basetime+=self.steptime self.spawntimer = self.game.lib.Timer(self.basetime) self.speedmargin+=self.stepmargin + if self.invincible: + if self.deathtimer.tick(self.game.dt): + self.invincible = False + print(self.lives) + + def death(self): + if not self.invincible: + self.lives-=1 + self.invincible = True + def draw(self): pass