diff --git a/gamedata/objects/ingame/manager.py b/gamedata/objects/ingame/manager.py index 409a264..d111c0a 100644 --- a/gamedata/objects/ingame/manager.py +++ b/gamedata/objects/ingame/manager.py @@ -1,17 +1,28 @@ from gamedata.objects.base import BaseObject +from gamedata.objects.ingame.lemmings import Lemming +from gamedata.objects.ingame.tiles import Tiles class Manager(BaseObject): def __init__(self,game): super().__init__(0,0,game) - self.score = 0 - self.spawntimer = game.lib.Timer(30) # Time elapsing each lemming spawn - self.scoreratio = 1 # Points earned per seconds and per lemming + self.lives = 5 + self.basetime = 10 + self.steptime = 2 + self.spawntimer = game.lib.Timer(self.basetime) # Time elapsing each lemming spawn + self.scoreratio = 0.4 # Points earned per seconds and per lemming + + # Summon the tiles + self.tiles = Tiles(50,50,game) + game.gameloop.summon(self.tiles) def step(self): for i in self.game.gameloop.findname("Lemming"): self.score+=self.scoreratio*self.game.dt - print(int(self.score)) + if self.spawntimer.tick(self.game.dt): + self.game.gameloop.summon(Lemming(100,100,self.game)) + self.basetime+=self.steptime + self.spawntimer = self.game.lib.Timer(self.basetime) def draw(self): pass diff --git a/gamedata/objects/ingame/tiles.py b/gamedata/objects/ingame/tiles.py new file mode 100644 index 0000000..306e0e8 --- /dev/null +++ b/gamedata/objects/ingame/tiles.py @@ -0,0 +1,41 @@ +from gamedata.objects.base import BaseObject +from math import sqrt +import random + +# Tiles object, displaying and managing the play grid + +class Tiles(BaseObject): + + def __init__(self,x,y,game,nbcells=20,cellsize=30): + + super().__init__(x,y,game,nbcells*cellsize,nbcells*cellsize) + + self.nbcells = nbcells + self.cellsize = cellsize + + self.grid = self.gengrid(nbcells,nbcells) + + def gengrid(self,w,h): + # Generating various rectangles on a map + grid = [ [0 for x in range(w)] for y in range(h) ] + nb_rects = int(sqrt(w*h)/1.5+0.5) + + for i in range(nb_rects): + # Generating the rects + rectw = random.randint(3,7) + recth = random.randint(3,7) + rectx = random.randint(0,w-rectw) + recty = random.randint(0,h-recth) + + for offx in range(rectw): + for offy in range(recth): + grid[offy+recty][offx+rectx]=1 + + return grid + + def draw(self): + # Drawing the grid + for y in range(len(self.grid)): + for x in range(len(self.grid[y])): + if self.grid[y][x]==1: + 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])