Monsters kill other pinmiks

This commit is contained in:
theo@manjaro 2021-09-19 15:07:59 +02:00
parent eca2323d1a
commit 693e4a49e8

View File

@ -20,11 +20,17 @@ class Lemming(BaseObject):
self.basespeed*=1.2
self.scoreratio*=3
if skin=="platinum":
self.basespeed*=1.3
self.basespeed*=1.4
self.scoreratio*=5
if skin=="monster":
self.scoreratio*=3
self.skin = skin
self.maxhealth = 2 # Pinmiks can be attacked by the monsters
self.health = self.maxhealth
self.regen = 0.1
self.selected = False # If beeing redirected
self.anglemargin = 25
@ -64,6 +70,17 @@ class Lemming(BaseObject):
self.move(diffx*self.game.dt,diffy*self.game.dt)
self.health = min(self.maxhealth,self.health+self.regen*self.game.dt) # Regen live
# Attacking other pinmiks
if self.skin=="monster":
for pinmik in self.game.gameloop.findname("Lemming"):
if pinmik.skin!="monster":
if self.rect.collidepoint(pinmik.rect.center):
pinmik.health-=self.game.dt
if self.holdrect.collidepoint(pinmik.rect.center):
pinmik.health-=self.game.dt
# Spawning dust particles if being launched
if self.speed > self.basespeed*1.5:
if self.dusttimer.tick(self.game.dt*(self.speed/self.basespeed)**2):
@ -97,8 +114,9 @@ class Lemming(BaseObject):
if 0<=gridx<len(self.tiles.grid[gridy]):
if self.tiles.grid[gridy][gridx]==1:
dead = False
if dead:
self.manager.death()
if dead or self.health<0:
if self.skin!="monster": # Monsters die without removing lives
self.manager.death()
if self.game.globals["scamerax"]*self.game.globals["scameray"]>5: # Avoiding shaking to much
self.game.globals["scamerax"]+=1
self.game.globals["scamerax"]+=1
@ -140,12 +158,18 @@ class Lemming(BaseObject):
self.holdrect[1]+=int(vely)
def draw(self):
# Shaking based on life
offx,offy = 0,0
if self.health<self.maxhealth:
shake = (1-(self.health/self.maxhealth))*4
offx = random.random()*shake*2-shake
offy = random.random()*shake*2-shake
orientation = self.orientations[int(self.direction%360/361*4)]
sprites = self.sprites[orientation]
self.game.lib.drawcenter(self.game,self.game.sprite_lib["lemmings/shadow.png"],self.rect.center[0]-self.game.globals["camerax"],self.rect.center[1]-self.game.globals["cameray"])
self.game.lib.drawcenter(self.game,sprites[int(self.spriteindex)%len(sprites)],self.rect.center[0]-self.game.globals["camerax"],self.rect.center[1]-self.game.globals["cameray"])
self.game.lib.drawcenter(self.game,self.game.sprite_lib["lemmings/shadow.png"],self.rect.center[0]-self.game.globals["camerax"]+offx,self.rect.center[1]-self.game.globals["cameray"]+offy)
self.game.lib.drawcenter(self.game,sprites[int(self.spriteindex)%len(sprites)],self.rect.center[0]-self.game.globals["camerax"]+offx,self.rect.center[1]-self.game.globals["cameray"]+offy)
if self.selected:
self.game.lib.drawcenter(self.game,self.game.sprite_lib["lemmings/selected.png"],self.rect.center[0]-self.game.globals["camerax"],self.rect.center[1]-self.game.globals["cameray"])
self.game.lib.drawcenter(self.game,self.game.sprite_lib["lemmings/selected.png"],self.rect.center[0]-self.game.globals["camerax"]+offx,self.rect.center[1]-self.game.globals["cameray"]+offy)
if self.game.globals["debug"]:
s = self.game.pygame.Surface(self.rect.size)
s.fill([255,0,0])