Added environnement

This commit is contained in:
theo@manjaro 2021-09-13 22:16:02 +02:00
parent d11e4b9f4d
commit df215051f7
6 changed files with 27 additions and 24 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 602 B

BIN
gamedata/assets/ingame.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 36 KiB

View File

@ -48,7 +48,7 @@ class Game():
self.globals["cameray"] = 0 self.globals["cameray"] = 0
self.globals["scamerax"] = 3 self.globals["scamerax"] = 3
self.globals["scameray"] = 0 self.globals["scameray"] = 0
self.globals["debug"] = True self.globals["debug"] = False
self.globals["highscore"] = 0 self.globals["highscore"] = 0
self.scaleCamera() self.scaleCamera()

View File

@ -22,7 +22,7 @@ class Manager(BaseObject):
self.endrect.fill([0]*3) self.endrect.fill([0]*3)
# Summon the tiles # Summon the tiles
self.tiles = Tiles(50,50,game) self.tiles = Tiles(288,0,game)
game.gameloop.summon(self.tiles) game.gameloop.summon(self.tiles)
# Spawn the first one # Spawn the first one
self.game.gameloop.summon(Spawner(self.game,self.tiles)) self.game.gameloop.summon(Spawner(self.game,self.tiles))

View File

@ -6,7 +6,7 @@ import random
class Tiles(BaseObject): 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) super().__init__(x,y,game,nbcells*cellsize,nbcells*cellsize)
@ -15,24 +15,25 @@ class Tiles(BaseObject):
self.saferadius = 2 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) self.spawns = self.getspawnpoints(self.grid,saferadius=self.saferadius)
def gengrid(self,w,h,minsize=3,randrange=4): self.debugcell = game.pygame.Surface([cellsize]*2)
# Generating various rectangles on a map self.debugcell.fill([255]*3)
grid = [ [0 for x in range(w)] for y in range(h) ] self.debugcell.set_alpha(100)
nb_rects = int(sqrt(w*h)/1.5+0.5)
for i in range(nb_rects): def gengrid(self,sprite):
# Generating the rects # Generating a list of lists based on an image
rectw = random.randint(0,randrange)+minsize width,height = sprite.get_size()
recth = random.randint(0,randrange)+minsize grid = []
rectx = random.randint(0,w-rectw) for y in range(height):
recty = random.randint(0,h-recth) line = []
for x in range(width):
for offx in range(rectw): if sprite.get_at((x,y))!=(0,0,0,255):
for offy in range(recth): line.append(1)
grid[offy+recty][offx+rectx]=1 else:
line.append(0)
grid.append(line)
return grid return grid
@ -50,12 +51,14 @@ class Tiles(BaseObject):
return spawns return spawns
def draw(self): def draw(self):
# Drawing the grid # Drawing the ground
for y in range(len(self.grid)): self.game.window.blit(self.game.sprite_lib["ingame.png"],(0,0))
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
if self.game.globals["debug"]: 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: for point in self.spawns:
self.game.pygame.draw.circle(self.game.window,[100,100,0],point,radius=3) self.game.pygame.draw.circle(self.game.window,[100,100,0],point,radius=3)