forked from ayte/PinmikPanik
Added telegraph before spawning
This commit is contained in:
parent
47da0e400e
commit
6288826675
@ -1,5 +1,5 @@
|
||||
from gamedata.objects.base import BaseObject
|
||||
from gamedata.objects.ingame.lemmings import Lemming
|
||||
from gamedata.objects.ingame.spawner import Spawner
|
||||
from gamedata.objects.ingame.tiles import Tiles
|
||||
|
||||
class Manager(BaseObject):
|
||||
@ -16,11 +16,14 @@ class Manager(BaseObject):
|
||||
self.tiles = Tiles(50,50,game)
|
||||
game.gameloop.summon(self.tiles)
|
||||
|
||||
# Spawn the first one
|
||||
self.game.gameloop.summon(Spawner(self.game,self.tiles))
|
||||
|
||||
def step(self):
|
||||
for i in self.game.gameloop.findname("Lemming"):
|
||||
self.score+=self.scoreratio*self.game.dt
|
||||
if self.spawntimer.tick(self.game.dt):
|
||||
self.game.gameloop.summon(Lemming(100,100,self.game))
|
||||
self.game.gameloop.summon(Spawner(self.game,self.tiles))
|
||||
self.basetime+=self.steptime
|
||||
self.spawntimer = self.game.lib.Timer(self.basetime)
|
||||
|
||||
|
22
gamedata/objects/ingame/spawner.py
Normal file
22
gamedata/objects/ingame/spawner.py
Normal file
@ -0,0 +1,22 @@
|
||||
from gamedata.objects.base import BaseObject
|
||||
from gamedata.objects.ingame.lemmings import Lemming
|
||||
|
||||
import random
|
||||
|
||||
class Spawner(BaseObject):
|
||||
def __init__(self,game,tiles):
|
||||
spawnpoint = random.choice(tiles.spawns)
|
||||
super().__init__(spawnpoint[0],spawnpoint[1],game)
|
||||
self.sprite = game.sprite_lib["lemmings/shadow.png"]
|
||||
self.timer = game.lib.Timer(3) # Seconds of telegraph before spawning the lemming
|
||||
|
||||
def step(self):
|
||||
if self.timer.tick(self.game.dt):
|
||||
lemming = Lemming(self.rect[0],self.rect[1],self.game)
|
||||
lemming.move(-lemming.rect[2]/2,-lemming.rect[3]/2)
|
||||
self.game.gameloop.summon(lemming)
|
||||
self.game.gameloop.delid(self.id)
|
||||
|
||||
def draw(self):
|
||||
self.game.lib.drawcenter(self.game,self.sprite,self.rect[0],self.rect[1])
|
||||
|
@ -44,7 +44,7 @@ class Tiles(BaseObject):
|
||||
if grid[y+safey][x+safex]==0: # If a pit is inside the radius, can't spawn here
|
||||
canspawn = False
|
||||
if canspawn:
|
||||
spawns.append([x,y])
|
||||
spawns.append([self.rect[0]+(x+0.5)*self.cellsize,self.rect[1]+(y+0.5)*self.cellsize])
|
||||
return spawns
|
||||
|
||||
def draw(self):
|
||||
@ -55,8 +55,5 @@ class Tiles(BaseObject):
|
||||
self.game.pygame.draw.rect(self.game.window,[255]*3,[self.rect[0]+x*self.cellsize,self.rect[1]+y*self.cellsize,self.cellsize,self.cellsize])
|
||||
# Draw spawn points
|
||||
if self.game.globals["debug"]:
|
||||
for x,y in self.spawns:
|
||||
screenx = self.rect[0]+(x+0.5)*self.cellsize
|
||||
screeny = self.rect[1]+(y+0.5)*self.cellsize
|
||||
point = (screenx,screeny)
|
||||
for point in self.spawns:
|
||||
self.game.pygame.draw.circle(self.game.window,[100,100,0],point,radius=3)
|
||||
|
@ -18,7 +18,6 @@ def main(game):
|
||||
def ingame(game):
|
||||
game.gameloop.reinit()
|
||||
game.gameloop.summon(Manager(game))
|
||||
game.gameloop.summon(Lemming(200,200,game))
|
||||
|
||||
def options(game):
|
||||
game.gameloop.reinit()
|
||||
|
Loading…
Reference in New Issue
Block a user