diff --git a/gamedata/assets/collisionmap.png b/gamedata/assets/collisionmap.png new file mode 100644 index 0000000..fa8c318 Binary files /dev/null and b/gamedata/assets/collisionmap.png differ diff --git a/gamedata/assets/ingame.png b/gamedata/assets/ingame.png new file mode 100644 index 0000000..cbd26f1 Binary files /dev/null and b/gamedata/assets/ingame.png differ diff --git a/gamedata/assets/tiles_packed.png b/gamedata/assets/tiles_packed.png index e21fc50..4c989b6 100644 Binary files a/gamedata/assets/tiles_packed.png and b/gamedata/assets/tiles_packed.png differ diff --git a/gamedata/game.py b/gamedata/game.py index d26d1cd..5e910c7 100644 --- a/gamedata/game.py +++ b/gamedata/game.py @@ -48,7 +48,7 @@ class Game(): self.globals["cameray"] = 0 self.globals["scamerax"] = 3 self.globals["scameray"] = 0 - self.globals["debug"] = True + self.globals["debug"] = False self.globals["highscore"] = 0 self.scaleCamera() diff --git a/gamedata/objects/ingame/manager.py b/gamedata/objects/ingame/manager.py index f7c8fb7..ca22a28 100644 --- a/gamedata/objects/ingame/manager.py +++ b/gamedata/objects/ingame/manager.py @@ -22,7 +22,7 @@ class Manager(BaseObject): self.endrect.fill([0]*3) # Summon the tiles - self.tiles = Tiles(50,50,game) + self.tiles = Tiles(288,0,game) game.gameloop.summon(self.tiles) # Spawn the first one self.game.gameloop.summon(Spawner(self.game,self.tiles)) diff --git a/gamedata/objects/ingame/tiles.py b/gamedata/objects/ingame/tiles.py index 51591e7..39c9afc 100644 --- a/gamedata/objects/ingame/tiles.py +++ b/gamedata/objects/ingame/tiles.py @@ -6,7 +6,7 @@ import random class Tiles(BaseObject): - def __init__(self,x,y,game,nbcells=20,cellsize=30): + def __init__(self,x,y,game,nbcells=22,cellsize=32): super().__init__(x,y,game,nbcells*cellsize,nbcells*cellsize) @@ -15,24 +15,25 @@ class Tiles(BaseObject): self.saferadius = 2 - self.grid = self.gengrid(nbcells,nbcells,minsize=self.saferadius*2+1) + self.grid = self.gengrid(game.sprite_lib["collisionmap.png"]) self.spawns = self.getspawnpoints(self.grid,saferadius=self.saferadius) - def gengrid(self,w,h,minsize=3,randrange=4): - # 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) + self.debugcell = game.pygame.Surface([cellsize]*2) + self.debugcell.fill([255]*3) + self.debugcell.set_alpha(100) - for i in range(nb_rects): - # Generating the rects - rectw = random.randint(0,randrange)+minsize - recth = random.randint(0,randrange)+minsize - 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 + def gengrid(self,sprite): + # Generating a list of lists based on an image + width,height = sprite.get_size() + grid = [] + for y in range(height): + line = [] + for x in range(width): + if sprite.get_at((x,y))!=(0,0,0,255): + line.append(1) + else: + line.append(0) + grid.append(line) return grid @@ -50,12 +51,14 @@ class Tiles(BaseObject): return spawns 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]) - # Draw spawn points + # Drawing the ground + self.game.window.blit(self.game.sprite_lib["ingame.png"],(0,0)) if self.game.globals["debug"]: + # 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.window.blit(self.debugcell,[self.rect[0]+x*self.cellsize,self.rect[1]+y*self.cellsize]) + # Draw spawn points for point in self.spawns: self.game.pygame.draw.circle(self.game.window,[100,100,0],point,radius=3)