Lemmings die if not on ground
This commit is contained in:
parent
e6d1d9c9dd
commit
0edc8cb3ac
@ -30,6 +30,9 @@ class Lemming(BaseObject):
|
|||||||
self.spriteindex = 0
|
self.spriteindex = 0
|
||||||
self.animspeed = 0.2
|
self.animspeed = 0.2
|
||||||
|
|
||||||
|
self.tiles = game.gameloop.findname("Tiles")[0]
|
||||||
|
self.manager = game.gameloop.findname("Manager")[0]
|
||||||
|
|
||||||
def step(self):
|
def step(self):
|
||||||
|
|
||||||
# Depth updating based on position
|
# Depth updating based on position
|
||||||
@ -69,6 +72,19 @@ class Lemming(BaseObject):
|
|||||||
|
|
||||||
# Animation
|
# Animation
|
||||||
self.spriteindex+=self.game.dt*self.animspeed*self.speed
|
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<=gridy<len(self.tiles.grid):
|
||||||
|
if 0<=gridx<len(self.tiles.grid[gridy]):
|
||||||
|
if self.tiles.grid[gridy][gridx]==1:
|
||||||
|
dead = False
|
||||||
|
if dead:
|
||||||
|
self.manager.death()
|
||||||
|
self.game.gameloop.delid(self.id)
|
||||||
|
|
||||||
def launch(self):
|
def launch(self):
|
||||||
# Launch itself in the mouse direction
|
# Launch itself in the mouse direction
|
||||||
if len(self.cachedrel)>self.mincachedsize:
|
if len(self.cachedrel)>self.mincachedsize:
|
||||||
|
@ -12,6 +12,8 @@ class Manager(BaseObject):
|
|||||||
self.speedmargin = 6
|
self.speedmargin = 6
|
||||||
self.stepmargin = 0.4
|
self.stepmargin = 0.4
|
||||||
self.spawntimer = game.lib.Timer(self.basetime) # Time elapsing each lemming spawn
|
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
|
self.scoreratio = 0.4 # Points earned per seconds and per lemming
|
||||||
|
|
||||||
# Summon the tiles
|
# Summon the tiles
|
||||||
@ -22,14 +24,27 @@ class Manager(BaseObject):
|
|||||||
self.game.gameloop.summon(Spawner(self.game,self.tiles))
|
self.game.gameloop.summon(Spawner(self.game,self.tiles))
|
||||||
|
|
||||||
def step(self):
|
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
|
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.game.gameloop.summon(Spawner(self.game,self.tiles,speedmargin=int(self.speedmargin+0.5)))
|
||||||
self.basetime+=self.steptime
|
self.basetime+=self.steptime
|
||||||
self.spawntimer = self.game.lib.Timer(self.basetime)
|
self.spawntimer = self.game.lib.Timer(self.basetime)
|
||||||
self.speedmargin+=self.stepmargin
|
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):
|
def draw(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user