57 lines
1.7 KiB
Python
57 lines
1.7 KiB
Python
import pygame, sys
|
|
|
|
from random import randint
|
|
from config import WINDOW_HEIGHT, WINDOW_WIDTH, GRID_HEIGHT, GRID_WIDTH, HOUSE_CAPACITY, FPS
|
|
|
|
from DataModels.Grass import Grass
|
|
from DataModels.House import House
|
|
from DataModels.Dump import Dump
|
|
|
|
pygame_sprites = pygame.sprite.Group()
|
|
|
|
FPS_CLOCK = pygame.time.Clock()
|
|
GAME_WINDOW = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT), 0, 32)
|
|
|
|
map = open(sys.argv[1], 'r')
|
|
map.readline()
|
|
|
|
map_objects = [ [ None for y in range(0,GRID_WIDTH)] for x in range(0, GRID_HEIGHT)]
|
|
|
|
def generate( letter ):
|
|
letter_mapping = {
|
|
'E': lambda x, y: Grass(x,y),
|
|
'H': lambda x, y, max_rubbish, yellow, green, blue: House( x, y, max_rubbish, yellow, green, blue ),
|
|
'B': lambda x, y, max_rubbish, dump_type: Dump( x, y, max_rubbish, dump_type )
|
|
}
|
|
return letter_mapping[letter]
|
|
|
|
i = 0
|
|
for y in map.readlines():
|
|
for x in y.split():
|
|
x_coord = i%GRID_WIDTH
|
|
y_coord = i //GRID_HEIGHT
|
|
yellow, green, blue = [randint(0, HOUSE_CAPACITY //2),randint(0, HOUSE_CAPACITY //2),randint(0, HOUSE_CAPACITY //2)]
|
|
if x is 'E':
|
|
map_objects[x_coord][y_coord] = generate(x)(x_coord, y_coord)
|
|
elif x is 'H':
|
|
map_objects[x_coord][y_coord] = generate(x)(x_coord, y_coord, HOUSE_CAPACITY, yellow, green, blue)
|
|
elif x is 'B':
|
|
map_objects[x_coord][y_coord] = generate(x)(x_coord, y_coord, 100, "Dump_Blue")
|
|
i += 1
|
|
|
|
for line in map_objects:
|
|
for item in line:
|
|
pygame_sprites.add(item)
|
|
|
|
while True:
|
|
|
|
for event in pygame.event.get():
|
|
if event.type == pygame.QUIT:
|
|
pygame.quit()
|
|
sys.exit()
|
|
|
|
pygame_sprites.update()
|
|
pygame_sprites.draw(GAME_WINDOW)
|
|
|
|
pygame.display.flip()
|
|
FPS_CLOCK.tick(FPS) |