forked from ayte/PinmikPanik
49 lines
2.2 KiB
Python
49 lines
2.2 KiB
Python
from gamedata.objects.base import BaseObject
|
|
from gamedata.objects.ingame.lemmings import Lemming
|
|
|
|
import random
|
|
|
|
class Spawner(BaseObject):
|
|
def __init__(self,game,tiles,speedmargin=5,skins={"normal":["base"],"specials":[]}):
|
|
spawnpoint = random.choice(tiles.spawns)
|
|
super().__init__(spawnpoint[0],spawnpoint[1],game)
|
|
self.sprite = game.sprite_lib["lemmings/shadow.png"].copy()
|
|
self.speedmargin = speedmargin
|
|
self.distance = game.DISPLAY_HEIGHT
|
|
self.timer = game.lib.Timer(2.5+random.random()) # Seconds of telegraph before spawning the lemming
|
|
|
|
# Skin choosing
|
|
self.skin = random.choice(skins["normal"])
|
|
if random.randint(1,10)==1: # 1/10 chance to have a special
|
|
if len(skins["specials"])>0:
|
|
self.skin = random.choice(skins["specials"])
|
|
self.fallsprite = game.sprite_lib["lemmings/"+self.skin+"/falling.png"]
|
|
|
|
def step(self):
|
|
if self.timer.tick(self.game.dt):
|
|
lemming = Lemming(self.rect[0],self.rect[1],self.game,speedmargin=self.speedmargin,skin=self.skin)
|
|
lemming.move(-lemming.rect[2]/2,-lemming.rect[3]/2)
|
|
self.game.gameloop.summon(lemming)
|
|
self.game.gameloop.delid(self.id)
|
|
self.game.globals["scamerax"]+=3
|
|
self.game.globals["scameray"]+=3
|
|
|
|
# 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)
|
|
|
|
|
|
def draw(self):
|
|
# Draw the shadow
|
|
alphavalue = 1-self.timer.getratio()
|
|
alphavalue = min(1,alphavalue)*255
|
|
self.sprite.set_alpha(alphavalue)
|
|
self.game.lib.drawcenter(self.game,self.sprite,self.rect[0]-self.game.globals["camerax"],self.rect[1]-self.game.globals["cameray"])
|
|
|
|
# Display the lemming falling
|
|
currentdistance = self.distance*self.timer.getratio()**0.9
|
|
self.game.lib.drawcenter(self.game,self.fallsprite,self.rect[0]-self.game.globals["camerax"],self.rect[1]-currentdistance-self.game.globals["cameray"])
|
|
|
|
|