SZI2019SmieciarzWmi/main.py

99 lines
2.9 KiB
Python
Raw Normal View History

import pygame
import sys
2019-04-01 10:33:32 +02:00
from random import randint
from config import WINDOW_HEIGHT, WINDOW_WIDTH, GRID_HEIGHT, GRID_WIDTH, HOUSE_CAPACITY, FPS, GC_X, GC_Y
from DataModels.Grass import Grass
from DataModels.House import House
from DataModels.Dump import Dump
2019-04-01 13:29:13 +02:00
from DataModels.Road import Road
from DataModels.GC import GC
2019-04-01 10:33:32 +02:00
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.readline()
map_objects = [[None for y in range(0, GRID_WIDTH)]
for x in range(0, GRID_HEIGHT)]
def generate(letter):
key = 'D' if letter in ['B', 'G', 'Y'] else 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),
'D': lambda x, y, max_rubbish, dump_type: Dump(x, y, max_rubbish, dump_type),
'R': lambda x, y: Road(x, y)
}
2019-04-01 13:29:13 +02:00
return letter_mapping[key]
i = 0
for y in map.readlines():
for x in y.split():
2019-04-01 14:39:08 +02:00
x_coord = i % GRID_WIDTH
2019-04-01 14:32:24 +02:00
y_coord = (i-x_coord)//GRID_WIDTH
2019-04-01 13:29:13 +02:00
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")
2019-04-01 13:29:13 +02:00
elif x is 'G':
map_objects[x_coord][y_coord] = generate(
x)(x_coord, y_coord, 100, "Dump_Green")
2019-04-01 13:29:13 +02:00
elif x is 'Y':
map_objects[x_coord][y_coord] = generate(
x)(x_coord, y_coord, 100, "Dump_Yellow")
2019-04-01 13:29:13 +02:00
elif x is 'R':
map_objects[x_coord][y_coord] = generate(x)(x_coord, y_coord)
i += 1
2019-04-01 13:29:13 +02:00
print(GRID_WIDTH, GRID_HEIGHT)
print(map_objects)
2019-04-01 13:29:13 +02:00
for line in map_objects:
for item in line:
pygame_sprites.add(item)
2019-04-01 14:36:27 +02:00
gc = GC(GC_X, GC_Y, 2)
print("GC: " + str(GC_X) + str(GC_Y))
pygame_sprites.add(gc)
2019-04-01 13:29:13 +02:00
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
elif event.type == pygame.KEYUP:
if event.key == pygame.K_UP:
gc.move("up", map_objects)
elif event.key == pygame.K_DOWN:
gc.move("down", map_objects)
elif event.key == pygame.K_LEFT:
gc.move("left", map_objects)
elif event.key == pygame.K_RIGHT:
gc.move("right", map_objects)
pygame_sprites.update()
pygame_sprites.draw(GAME_WINDOW)
2019-04-01 10:33:32 +02:00
pygame.display.flip()
FPS_CLOCK.tick(FPS)