Half repaired map-generating

This commit is contained in:
Anna Nowak 2019-03-25 13:44:16 +01:00
parent dd6a57c701
commit 7d13d98757
3 changed files with 17 additions and 10 deletions

View File

@ -22,5 +22,5 @@ def set_home_amount():
home_amount = set_home_amount() home_amount = set_home_amount()
PLAY_WIDTH = home_amount*CELL_SIZE PLAY_WIDTH = (home_amount+2)*CELL_SIZE
PLAY_HEIGHT = PLAY_WIDTH PLAY_HEIGHT = PLAY_WIDTH

View File

@ -27,8 +27,8 @@ display.set_caption('Smieciarz WMI')
## ##
# Generate level # Generate level
utils.generate_grass(all_sprites) utils.generate_grass(all_sprites)
utils.generate_houses(all_sprites, obstacles_coords)
utils.generate_landfills(all_sprites, obstacles_coords) utils.generate_landfills(all_sprites, obstacles_coords)
utils.generate_houses(all_sprites, obstacles_coords)
utils.add_frame_as_obstacles(obstacles_coords) utils.add_frame_as_obstacles(obstacles_coords)
gc = utils.generate_garbage_collector(all_sprites, obstacles_coords) gc = utils.generate_garbage_collector(all_sprites, obstacles_coords)
## ##

View File

@ -40,7 +40,7 @@ def generate_houses(all_sprites, obstacles_coords):
while(home_counter != 0): while(home_counter != 0):
x, y = generate_rand_coordinates( x, y = generate_rand_coordinates(
(PLAY_WIDTH//CELL_SIZE)-1, (PLAY_HEIGHT//CELL_SIZE)-1) (PLAY_WIDTH//CELL_SIZE)-1, (PLAY_HEIGHT//CELL_SIZE)-1)
if((x, y) not in obstacles_coords): if(((x, y) or (x,y-1)) not in obstacles_coords):
houses.append(House(x, y, 10, 10, 10)) houses.append(House(x, y, 10, 10, 10))
obstacles_coords.append((x, y)) obstacles_coords.append((x, y))
home_counter = home_counter - 1 home_counter = home_counter - 1
@ -55,13 +55,20 @@ def generate_houses(all_sprites, obstacles_coords):
def generate_landfills(all_sprites, obstacles_coords): def generate_landfills(all_sprites, obstacles_coords):
landfills = [] landfills = []
landfill_counter = 3 landfill_counter = 3
while(landfill_counter != 0):
x, y = generate_rand_coordinates( # while(landfill_counter != 0):
(PLAY_WIDTH//CELL_SIZE)-1, (PLAY_HEIGHT//CELL_SIZE)-1) # x, y = generate_rand_coordinates(
if((x, y) not in obstacles_coords): # (PLAY_WIDTH//CELL_SIZE)-1, (PLAY_HEIGHT//CELL_SIZE)-1)
landfills.append(Landfill(x, y, landfill_counter-1)) # if((x, y) not in obstacles_coords):
obstacles_coords.append((x, y)) # landfills.append(Landfill(x, y, landfill_counter-1))
landfill_counter = landfill_counter - 1 # obstacles_coords.append((x, y))
# landfill_counter = landfill_counter - 1
y=0
for x in range(landfill_counter):
landfills.append(Landfill(x,y,x))
obstacles_coords.append((x,y))
for item in landfills: for item in landfills:
all_sprites.add(item) all_sprites.add(item)