Dodano podzial projektu na pliki + plik configuracyjnu
This commit is contained in:
parent
ebab21363d
commit
ee58257d54
23
config.py
Normal file
23
config.py
Normal file
@ -0,0 +1,23 @@
|
||||
import sys, getopt
|
||||
from sprites.cell import CELL_SIZE
|
||||
|
||||
def set_home_amount():
|
||||
arguments = sys.argv[1:]
|
||||
try:
|
||||
optlist, args = getopt.getopt(arguments, '', ['home-count='])
|
||||
for o, amount in optlist:
|
||||
if o == '--home-count':
|
||||
if int(amount) < 2:
|
||||
print('Home count too low - must be higher than 2')
|
||||
sys.exit(2)
|
||||
return int(amount)
|
||||
print('Missing argument: --home-count <amount>')
|
||||
sys.exit(2)
|
||||
except getopt.GetoptError as err:
|
||||
print(err)
|
||||
sys.exit(2)
|
||||
|
||||
home_amount = set_home_amount()
|
||||
|
||||
PLAY_WIDTH = home_amount*CELL_SIZE
|
||||
PLAY_HEIGHT = PLAY_WIDTH
|
70
game.py
70
game.py
@ -1,10 +1,7 @@
|
||||
from pygame import *
|
||||
import sys, random
|
||||
from sprites.cell import CELL_SIZE
|
||||
from sprites.grass import Grass
|
||||
from config import PLAY_WIDTH,PLAY_HEIGHT,home_amount
|
||||
from sprites.house import House
|
||||
from sprites.landfill import Landfill
|
||||
from sprites.garbage_collector import Garbage_collector
|
||||
from pygame.locals import *
|
||||
import utils
|
||||
|
||||
@ -16,68 +13,23 @@ fps_clock = time.Clock()
|
||||
######################################
|
||||
|
||||
##INITIALIZE DYNAMIC VARIABLES########
|
||||
home_amount = utils.set_home_amount()
|
||||
obstacles_coords = []
|
||||
|
||||
PLAY_WIDTH = home_amount*CELL_SIZE
|
||||
PLAY_HEIGHT = PLAY_WIDTH
|
||||
|
||||
WINDOW_WIDTH = PLAY_WIDTH
|
||||
WINDOW_HEIGHT = PLAY_HEIGHT
|
||||
######################################
|
||||
|
||||
##GAMEWINDOW##########################
|
||||
WINDOW_WIDTH = PLAY_WIDTH
|
||||
WINDOW_HEIGHT = PLAY_HEIGHT
|
||||
GAMEWINDOW = display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT), 0, 32)
|
||||
display.set_caption('Śmieciarz WMI')
|
||||
display.set_caption('Smieciarz WMI')
|
||||
######################################
|
||||
|
||||
##GENERATE GRASS##################################################################
|
||||
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)
|
||||
|
||||
##################################################################################
|
||||
|
||||
##GENERATE HOUSES#################################################################
|
||||
houses = []
|
||||
home_counter = home_amount
|
||||
while( home_counter != 0 ):
|
||||
x,y = utils.generate_rand_coordinates((PLAY_WIDTH//CELL_SIZE)-1,(PLAY_HEIGHT//CELL_SIZE)-1)
|
||||
if( (x,y) not in obstacles_coords ):
|
||||
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)
|
||||
##################################################################################
|
||||
|
||||
##GENERATE LANDFILLS##############################################################
|
||||
landfills = []
|
||||
landfill_counter = 3
|
||||
while( landfill_counter != 0):
|
||||
x,y = utils.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
|
||||
|
||||
for item in landfills:
|
||||
all_sprites.add(item)
|
||||
##################################################################################
|
||||
|
||||
##GENERATE GARBAGE COLLECTOR######################################################
|
||||
while( True ):
|
||||
x,y = utils.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)
|
||||
##################################################################################
|
||||
##
|
||||
#Generate level
|
||||
utils.generate_grass( all_sprites )
|
||||
utils.generate_houses( all_sprites, obstacles_coords )
|
||||
utils.generate_landfills( all_sprites, obstacles_coords )
|
||||
gc = utils.generate_garbage_collector( all_sprites, obstacles_coords )
|
||||
##
|
||||
|
||||
##GAME LOOP#######################################################################
|
||||
while(1):
|
||||
|
74
utils.py
74
utils.py
@ -1,21 +1,63 @@
|
||||
import sys, getopt, random
|
||||
|
||||
def set_home_amount():
|
||||
arguments = sys.argv[1:]
|
||||
try:
|
||||
optlist, args = getopt.getopt(arguments, '', ['home-count='])
|
||||
for o, amount in optlist:
|
||||
if o == '--home-count':
|
||||
if int(amount) < 2:
|
||||
print('Home count too low - must be higher than 2')
|
||||
sys.exit(2)
|
||||
return int(amount)
|
||||
print('Missing argument: --home-count <amount>')
|
||||
sys.exit(2)
|
||||
except getopt.GetoptError as err:
|
||||
print(err)
|
||||
sys.exit(2)
|
||||
from config import PLAY_WIDTH,PLAY_HEIGHT,home_amount
|
||||
from sprites.cell import CELL_SIZE
|
||||
from sprites.grass import Grass
|
||||
from sprites.house import House
|
||||
from sprites.landfill import Landfill
|
||||
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)))
|
||||
|
||||
|
||||
##GENERATE GRASS##################################################################
|
||||
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)
|
||||
##################################################################################
|
||||
|
||||
##GENERATE HOUSES#################################################################
|
||||
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)
|
||||
if( (x,y) not in obstacles_coords ):
|
||||
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)
|
||||
##################################################################################
|
||||
|
||||
##GENERATE LANDFILLS##############################################################
|
||||
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) )
|
||||
obstacles_coords.append((x,y))
|
||||
landfill_counter = landfill_counter - 1
|
||||
|
||||
for item in landfills:
|
||||
all_sprites.add(item)
|
||||
##################################################################################
|
||||
|
||||
##GENERATE GARBAGE COLLECTOR######################################################
|
||||
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
|
||||
##################################################################################
|
Loading…
Reference in New Issue
Block a user