diff --git a/DataModels/Cell.py b/DataModels/Cell.py new file mode 100644 index 0000000..3884a11 --- /dev/null +++ b/DataModels/Cell.py @@ -0,0 +1,26 @@ +import pygame, random + +from DataModels.Container import Container + +from PIL import Image,ImageDraw +from config import CELL_SIZE + +class Cell( pygame.sprite.Sprite ): + def __init__( self, x, y, max_rubbish, yellow = 0, green = 0, blue = 0, image_name = None): + pygame.sprite.Sprite.__init__( self ) + self.image_name = image_name or type(self).__name__ + self.update_rect( x,y ) + self.container = Container( max_rubbish, yellow, green, blue ) + self.update_image() + + def update_rect( self, x, y ): + self.x, self.y = x,y + self.rect = pygame.Rect( x * CELL_SIZE, y * CELL_SIZE, CELL_SIZE, CELL_SIZE ) + + def update_image( self ): + image = Image.open("Resources/Images/Image_" + self.image_name + ".png" ) + draw = ImageDraw.Draw(image) + draw.text( (5,5), str( self.container.status() ) ) + mode, size, data = image.mode, image.size, image.tobytes() + + self.image = pygame.image.frombuffer( data, size, mode ) diff --git a/DataModels/Container.py b/DataModels/Container.py new file mode 100644 index 0000000..4918a31 --- /dev/null +++ b/DataModels/Container.py @@ -0,0 +1,10 @@ + +class Container(): + def __init__( self, max, y = 0, g = 0, b = 0 ): + self.y, self.g, self.b = y, g, b + + def empty( self ): + self.y, self.g, self.b = 0,0,0 + + def status( self ): + return [self.y, self.g, self.b] \ No newline at end of file diff --git a/DataModels/Dump.py b/DataModels/Dump.py new file mode 100644 index 0000000..712aed9 --- /dev/null +++ b/DataModels/Dump.py @@ -0,0 +1,7 @@ +import pygame +from DataModels.Cell import Cell + +class Dump( Cell ): + def __init__( self, x, y, max_rubbish, dump_type, yellow = 0, green = 0, blue = 0 ): + Cell.__init__( self, x, y, max_rubbish, yellow, green, blue, dump_type ) + diff --git a/DataModels/Grass.py b/DataModels/Grass.py new file mode 100644 index 0000000..9cf974a --- /dev/null +++ b/DataModels/Grass.py @@ -0,0 +1,8 @@ +import pygame +from config import CELL_SIZE + +class Grass( pygame.sprite.Sprite ): + def __init__( self, x, y ): + pygame.sprite.Sprite.__init__( self ) + self.rect = pygame.Rect( x * CELL_SIZE, y * CELL_SIZE, CELL_SIZE, CELL_SIZE ) + self.image = pygame.image.load("Resources/Images/Image_Grass.png") \ No newline at end of file diff --git a/DataModels/House.py b/DataModels/House.py new file mode 100644 index 0000000..3e29543 --- /dev/null +++ b/DataModels/House.py @@ -0,0 +1,6 @@ +from DataModels.Cell import Cell + +class House( Cell ): + def __init__( self, x, y, max_rubbish, yellow = 0, green = 0, blue = 0 ): + Cell.__init__( self, x, y, max_rubbish, yellow, green, blue ) + diff --git a/DataModels/Road.py b/DataModels/Road.py new file mode 100644 index 0000000..16805b8 --- /dev/null +++ b/DataModels/Road.py @@ -0,0 +1,8 @@ +import pygame +from config import CELL_SIZE + +class Road( pygame.sprite.Sprite ): + def __init__( self, x, y ): + pygame.sprite.Sprite.__init__( self ) + self.rect = pygame.Rect( x * CELL_SIZE, y * CELL_SIZE, CELL_SIZE, CELL_SIZE ) + self.image = pygame.image.load("Resources/Images/Image_Road.png") \ No newline at end of file diff --git a/DataModels/__pycache__/Cell.cpython-36.pyc b/DataModels/__pycache__/Cell.cpython-36.pyc new file mode 100644 index 0000000..1cf07f1 Binary files /dev/null and b/DataModels/__pycache__/Cell.cpython-36.pyc differ diff --git a/DataModels/__pycache__/Container.cpython-36.pyc b/DataModels/__pycache__/Container.cpython-36.pyc new file mode 100644 index 0000000..391e59b Binary files /dev/null and b/DataModels/__pycache__/Container.cpython-36.pyc differ diff --git a/DataModels/__pycache__/Dump.cpython-36.pyc b/DataModels/__pycache__/Dump.cpython-36.pyc new file mode 100644 index 0000000..ed8d52a Binary files /dev/null and b/DataModels/__pycache__/Dump.cpython-36.pyc differ diff --git a/DataModels/__pycache__/Grass.cpython-36.pyc b/DataModels/__pycache__/Grass.cpython-36.pyc new file mode 100644 index 0000000..e0e9c67 Binary files /dev/null and b/DataModels/__pycache__/Grass.cpython-36.pyc differ diff --git a/DataModels/__pycache__/House.cpython-36.pyc b/DataModels/__pycache__/House.cpython-36.pyc new file mode 100644 index 0000000..c33f300 Binary files /dev/null and b/DataModels/__pycache__/House.cpython-36.pyc differ diff --git a/Resources/Maps/map_000.txt b/Resources/Maps/map_000.txt new file mode 100644 index 0000000..0cf75ee --- /dev/null +++ b/Resources/Maps/map_000.txt @@ -0,0 +1,3 @@ +2 2 +E H +H B diff --git a/__pycache__/config.cpython-36.pyc b/__pycache__/config.cpython-36.pyc new file mode 100644 index 0000000..b9af045 Binary files /dev/null and b/__pycache__/config.cpython-36.pyc differ diff --git a/c b/c new file mode 100755 index 0000000..2723b45 Binary files /dev/null and b/c differ diff --git a/c.c b/c.c new file mode 100644 index 0000000..8b3d58a --- /dev/null +++ b/c.c @@ -0,0 +1,11 @@ +#include + +int main( void ) { + + char c = NULL; + int b = c || 5; + + printf("%d\r\n", b); + + return 0; +} diff --git a/config.py b/config.py index d398027..d34b059 100644 --- a/config.py +++ b/config.py @@ -1,12 +1,12 @@ +import sys, random CELL_SIZE = 64 - FPS = 60 -HOME_AMOUNT = 7 - -GRID_HEIGHT = HOME_AMOUNT -GRID_WIDTH = GRID_HEIGHT +map = open( sys.argv[1], 'r' ) +GRID_WIDTH, GRID_HEIGHT = [int(x) for x in map.readline().split()] WINDOW_HEIGHT = GRID_HEIGHT * CELL_SIZE -WINDOW_WIDTH = GRID_WIDTH * CELL_SIZE \ No newline at end of file +WINDOW_WIDTH = GRID_WIDTH * CELL_SIZE + +HOUSE_CAPACITY = random.randint(1, 11) \ No newline at end of file diff --git a/main.py b/main.py index 68fafb0..b279024 100644 --- a/main.py +++ b/main.py @@ -1,10 +1,57 @@ -import pygame +import pygame, sys -from config import WINDOW_HEIGHT, WINDOW_WIDTH +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 = display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT), 0, 32) +GAME_WINDOW = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT), 0, 32) -grid = [ [] for x in range(0)] +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) \ No newline at end of file