2021-09-13 10:34:34 +02:00
|
|
|
from gamedata.objects.base import BaseObject
|
|
|
|
from gamedata.objects.ingame.lemmings import Lemming
|
|
|
|
|
|
|
|
import random
|
|
|
|
|
|
|
|
class Spawner(BaseObject):
|
2021-09-13 10:46:09 +02:00
|
|
|
def __init__(self,game,tiles,speedmargin=5):
|
2021-09-13 10:34:34 +02:00
|
|
|
spawnpoint = random.choice(tiles.spawns)
|
|
|
|
super().__init__(spawnpoint[0],spawnpoint[1],game)
|
|
|
|
self.sprite = game.sprite_lib["lemmings/shadow.png"]
|
2021-09-13 10:46:09 +02:00
|
|
|
self.speedmargin = speedmargin
|
2021-09-14 16:50:27 +02:00
|
|
|
self.fallsprite = game.sprite_lib["lemmings/Right/0.png"]
|
|
|
|
self.distance = game.DISPLAY_HEIGHT
|
2021-09-13 10:34:34 +02:00
|
|
|
self.timer = game.lib.Timer(3) # Seconds of telegraph before spawning the lemming
|
|
|
|
|
|
|
|
def step(self):
|
|
|
|
if self.timer.tick(self.game.dt):
|
2021-09-13 10:46:09 +02:00
|
|
|
lemming = Lemming(self.rect[0],self.rect[1],self.game,speedmargin=self.speedmargin)
|
2021-09-13 10:34:34 +02:00
|
|
|
lemming.move(-lemming.rect[2]/2,-lemming.rect[3]/2)
|
|
|
|
self.game.gameloop.summon(lemming)
|
|
|
|
self.game.gameloop.delid(self.id)
|
2021-09-14 17:01:58 +02:00
|
|
|
self.game.globals["scamerax"]+=3
|
|
|
|
self.game.globals["scameray"]+=3
|
2021-09-13 10:34:34 +02:00
|
|
|
|
|
|
|
def draw(self):
|
2021-09-14 16:50:27 +02:00
|
|
|
# Display the lemming falling
|
|
|
|
currentdistance = self.distance*self.timer.getratio()**2
|
2021-09-14 17:01:58 +02:00
|
|
|
self.game.lib.drawcenter(self.game,self.fallsprite,self.rect[0]-self.game.globals["camerax"],self.rect[1]-currentdistance-self.game.globals["cameray"])
|
2021-09-14 16:50:27 +02:00
|
|
|
|
|
|
|
# Draw the shadow
|
2021-09-14 17:01:58 +02:00
|
|
|
self.game.lib.drawcenter(self.game,self.sprite,self.rect[0]-self.game.globals["camerax"],self.rect[1]-self.game.globals["cameray"])
|
2021-09-13 10:34:34 +02:00
|
|
|
|