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-18 18:27:52 +02:00
|
|
|
def __init__(self,game,tiles,speedmargin=5,skins={"normal":["base"],"specials":[]}):
|
2021-09-13 10:34:34 +02:00
|
|
|
spawnpoint = random.choice(tiles.spawns)
|
|
|
|
super().__init__(spawnpoint[0],spawnpoint[1],game)
|
2021-09-17 15:46:00 +02:00
|
|
|
self.sprite = game.sprite_lib["lemmings/shadow.png"].copy()
|
2021-09-13 10:46:09 +02:00
|
|
|
self.speedmargin = speedmargin
|
2021-09-14 16:50:27 +02:00
|
|
|
self.distance = game.DISPLAY_HEIGHT
|
2021-09-17 15:09:01 +02:00
|
|
|
self.timer = game.lib.Timer(2.5+random.random()) # Seconds of telegraph before spawning the lemming
|
2021-09-13 10:34:34 +02:00
|
|
|
|
2021-09-19 12:20:43 +02:00
|
|
|
self.handlepause = True
|
|
|
|
|
2021-09-18 18:03:04 +02:00
|
|
|
# Skin choosing
|
|
|
|
self.skin = random.choice(skins["normal"])
|
2021-09-19 22:14:18 +02:00
|
|
|
if random.randint(1,6)==1: # Chance to have a special one
|
2021-09-18 18:03:04 +02:00
|
|
|
if len(skins["specials"])>0:
|
|
|
|
self.skin = random.choice(skins["specials"])
|
|
|
|
self.fallsprite = game.sprite_lib["lemmings/"+self.skin+"/falling.png"]
|
|
|
|
|
2021-09-18 18:56:49 +02:00
|
|
|
# Depth updating based on position
|
|
|
|
self.depth = 1+self.rect[1]/100
|
|
|
|
|
2021-09-19 21:32:42 +02:00
|
|
|
game.sound_lib["sfx/fall.wav"].play()
|
|
|
|
|
2021-09-13 10:34:34 +02:00
|
|
|
def step(self):
|
|
|
|
if self.timer.tick(self.game.dt):
|
2021-09-18 18:03:04 +02:00
|
|
|
lemming = Lemming(self.rect[0],self.rect[1],self.game,speedmargin=self.speedmargin,skin=self.skin)
|
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-19 15:50:36 +02:00
|
|
|
self.game.globals["scamerax"]+=2
|
|
|
|
self.game.globals["scameray"]+=2
|
2021-09-13 10:34:34 +02:00
|
|
|
|
2021-09-15 19:22:38 +02:00
|
|
|
# Spawn dust particles
|
|
|
|
sprites = self.game.getSpriteDir("particles/dust/")
|
|
|
|
self.game.addParticle(sprites,self.rect[0],self.rect[1]+20,velx=-1,vely=-0.5)
|
|
|
|
self.game.addParticle(sprites,self.rect[0],self.rect[1]+20,velx=1,vely=-0.5)
|
|
|
|
|
2021-09-19 21:32:42 +02:00
|
|
|
self.game.sound_lib["sfx/land.wav"].play()
|
|
|
|
|
2021-09-15 19:22:38 +02:00
|
|
|
|
2021-09-13 10:34:34 +02:00
|
|
|
def draw(self):
|
2021-09-15 16:11:18 +02:00
|
|
|
# Draw the shadow
|
2021-09-17 15:22:26 +02:00
|
|
|
alphavalue = 1-self.timer.getratio()
|
|
|
|
alphavalue = min(1,alphavalue)*255
|
|
|
|
self.sprite.set_alpha(alphavalue)
|
2021-09-15 16:11:18 +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-14 16:50:27 +02:00
|
|
|
# Display the lemming falling
|
2021-09-15 16:11:18 +02:00
|
|
|
currentdistance = self.distance*self.timer.getratio()**0.9
|
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
|
|
|
|
2021-09-13 10:34:34 +02:00
|
|
|
|