This commit is contained in:
Magdalena Wilczyńska 2019-03-25 14:12:50 +01:00
commit 0ffc5fa187
3 changed files with 25 additions and 10 deletions

View File

@ -22,5 +22,5 @@ def 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

View File

@ -28,8 +28,9 @@ display.set_caption('Smieciarz WMI')
##
# Generate level
utils.generate_grass(all_sprites)
utils.generate_houses(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)
gc = utils.generate_garbage_collector(all_sprites, obstacles_coords)
##

View File

@ -12,6 +12,12 @@ from sprites.garbage_collector import Garbage_collector
def generate_rand_coordinates(max_x, max_y):
return (random.randint(0, max_x), random.randint(0, (max_y)))
def add_frame_as_obstacles(obstacles_coords):
for x in range(0, home_amount + 1):
obstacles_coords.append((x,-1))
obstacles_coords.append((-1,x))
obstacles_coords.append((PLAY_WIDTH//CELL_SIZE,x))
obstacles_coords.append((x,PLAY_HEIGHT//CELL_SIZE))
##GENERATE GRASS##################################################################
def generate_grass(all_sprites):
@ -34,7 +40,8 @@ def generate_houses(all_sprites, obstacles_coords):
while(home_counter != 0):
x, y = generate_rand_coordinates(
(PLAY_WIDTH//CELL_SIZE)-1, (PLAY_HEIGHT//CELL_SIZE)-1)
if((x, y) not in obstacles_coords):
if(((x, y) or (x+1,y)) not in obstacles_coords):
print(x,y)
houses.append(House(x, y, 10, 10, 10))
obstacles_coords.append((x, y))
home_counter = home_counter - 1
@ -49,13 +56,20 @@ def generate_houses(all_sprites, obstacles_coords):
def generate_landfills(all_sprites, obstacles_coords):
landfills = []
landfill_counter = 3
while(landfill_counter != 0):
x, y = generate_rand_coordinates(
(PLAY_WIDTH//CELL_SIZE)-1, (PLAY_HEIGHT//CELL_SIZE)-1)
if((x, y) not in obstacles_coords):
landfills.append(Landfill(x, y, landfill_counter-1))
# while(landfill_counter != 0):
# x, y = generate_rand_coordinates(
# (PLAY_WIDTH//CELL_SIZE)-1, (PLAY_HEIGHT//CELL_SIZE)-1)
# if((x, y) not in obstacles_coords):
# landfills.append(Landfill(x, y, 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))
landfill_counter = landfill_counter - 1
for item in landfills:
all_sprites.add(item)