2019-03-21 01:25:19 +01:00
|
|
|
import sys
|
|
|
|
import getopt
|
|
|
|
import random
|
|
|
|
from config import PLAY_WIDTH, PLAY_HEIGHT, home_amount
|
2019-03-20 23:33:22 +01:00
|
|
|
from sprites.cell import CELL_SIZE
|
|
|
|
from sprites.grass import Grass
|
|
|
|
from sprites.house import House
|
|
|
|
from sprites.landfill import Landfill
|
2019-03-21 01:25:19 +01:00
|
|
|
from sprites.garbage_collector import Garbage_collector
|
|
|
|
|
2019-03-20 11:20:10 +01:00
|
|
|
|
2019-03-20 22:36:40 +01:00
|
|
|
def generate_rand_coordinates(max_x, max_y):
|
2019-03-21 01:25:19 +01:00
|
|
|
return (random.randint(0, max_x), random.randint(0, (max_y)))
|
|
|
|
|
2019-03-25 12:58:06 +01:00
|
|
|
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))
|
2019-03-20 23:33:22 +01:00
|
|
|
|
|
|
|
##GENERATE GRASS##################################################################
|
2019-03-21 01:25:19 +01:00
|
|
|
def generate_grass(all_sprites):
|
|
|
|
grass = []
|
|
|
|
for k in range(0, (PLAY_WIDTH//CELL_SIZE)*(PLAY_HEIGHT//CELL_SIZE)):
|
|
|
|
x, y = (int(k % (PLAY_WIDTH//CELL_SIZE)),
|
|
|
|
int(k/(PLAY_WIDTH//CELL_SIZE)))
|
|
|
|
grass.append(Grass(x, y))
|
|
|
|
|
|
|
|
for item in grass:
|
|
|
|
all_sprites.add(item)
|
2019-03-20 23:33:22 +01:00
|
|
|
##################################################################################
|
|
|
|
|
|
|
|
##GENERATE HOUSES#################################################################
|
2019-03-21 01:25:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
def generate_houses(all_sprites, obstacles_coords):
|
|
|
|
houses = []
|
|
|
|
home_counter = home_amount
|
|
|
|
while(home_counter != 0):
|
|
|
|
x, y = generate_rand_coordinates(
|
|
|
|
(PLAY_WIDTH//CELL_SIZE)-1, (PLAY_HEIGHT//CELL_SIZE)-1)
|
2019-03-25 13:44:16 +01:00
|
|
|
if(((x, y) or (x,y-1)) not in obstacles_coords):
|
2019-03-21 01:25:19 +01:00
|
|
|
houses.append(House(x, y, 10, 10, 10))
|
|
|
|
obstacles_coords.append((x, y))
|
|
|
|
home_counter = home_counter - 1
|
|
|
|
|
|
|
|
for item in houses:
|
|
|
|
all_sprites.add(item)
|
2019-03-20 23:33:22 +01:00
|
|
|
##################################################################################
|
|
|
|
|
|
|
|
##GENERATE LANDFILLS##############################################################
|
2019-03-21 01:25:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
def generate_landfills(all_sprites, obstacles_coords):
|
|
|
|
landfills = []
|
|
|
|
landfill_counter = 3
|
2019-03-25 13:44:16 +01:00
|
|
|
|
|
|
|
# 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))
|
|
|
|
|
|
|
|
|
2019-03-21 01:25:19 +01:00
|
|
|
|
|
|
|
for item in landfills:
|
|
|
|
all_sprites.add(item)
|
2019-03-20 23:33:22 +01:00
|
|
|
##################################################################################
|
|
|
|
|
|
|
|
##GENERATE GARBAGE COLLECTOR######################################################
|
2019-03-21 01:25:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
def generate_garbage_collector(all_sprites, obstacles_coords):
|
|
|
|
while(True):
|
|
|
|
x, y = generate_rand_coordinates(
|
|
|
|
(PLAY_WIDTH//CELL_SIZE)-1, (PLAY_HEIGHT//CELL_SIZE)-1)
|
|
|
|
if((x, y) not in obstacles_coords):
|
|
|
|
gc = Garbage_collector(x, y)
|
|
|
|
break
|
|
|
|
all_sprites.add(gc)
|
|
|
|
return gc
|
|
|
|
##################################################################################
|