From 62888266756e4f09b44683bc3d8b64961c28ecd8 Mon Sep 17 00:00:00 2001 From: "theo@manjaro" Date: Mon, 13 Sep 2021 10:34:34 +0200 Subject: [PATCH] Added telegraph before spawning --- gamedata/objects/ingame/manager.py | 7 +++++-- gamedata/objects/ingame/spawner.py | 22 ++++++++++++++++++++++ gamedata/objects/ingame/tiles.py | 7 ++----- gamedata/scenes.py | 1 - 4 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 gamedata/objects/ingame/spawner.py diff --git a/gamedata/objects/ingame/manager.py b/gamedata/objects/ingame/manager.py index d111c0a..7f551b2 100644 --- a/gamedata/objects/ingame/manager.py +++ b/gamedata/objects/ingame/manager.py @@ -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) diff --git a/gamedata/objects/ingame/spawner.py b/gamedata/objects/ingame/spawner.py new file mode 100644 index 0000000..ed2ccbf --- /dev/null +++ b/gamedata/objects/ingame/spawner.py @@ -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]) + diff --git a/gamedata/objects/ingame/tiles.py b/gamedata/objects/ingame/tiles.py index 23e83ba..0afb00d 100644 --- a/gamedata/objects/ingame/tiles.py +++ b/gamedata/objects/ingame/tiles.py @@ -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) diff --git a/gamedata/scenes.py b/gamedata/scenes.py index ad694ba..66f2817 100644 --- a/gamedata/scenes.py +++ b/gamedata/scenes.py @@ -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()