Added environnement
This commit is contained in:
parent
d11e4b9f4d
commit
df215051f7
BIN
gamedata/assets/collisionmap.png
Normal file
BIN
gamedata/assets/collisionmap.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 602 B |
BIN
gamedata/assets/ingame.png
Normal file
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 |
@ -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()
|
||||
|
||||
|
@ -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))
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user