simple map
This commit is contained in:
parent
92742554e9
commit
5a9a985bce
23
config.py
23
config.py
@ -3,3 +3,26 @@ WINDOW_HEIGHT = 10 * CELL_SIZE
|
||||
WINDOW_WIDTH = 16 * CELL_SIZE
|
||||
MAP_HEIGHT = 10
|
||||
MAP_WIDTH = 16
|
||||
|
||||
MAP = {
|
||||
0: {0: "House", 1: "Road", 2: "Road", 3: "Road", 4: "House", 5: "House", 6: "Road", 7: "Road",
|
||||
8: "Road", 9: "House", 10: "Grass", 11: "House", 12: "Road", 13: "Road", 14: "Road", 15: "House"},
|
||||
1: {0: "House", 1: "Road", 2: "Grass", 3: "Road", 4: "House", 5: "House", 6: "Road", 7: "Grass",
|
||||
8: "Road", 9: "House", 10: "Grass", 11: "House", 12: "Road", 13: "Grass", 14: "Road", 15: "House"},
|
||||
2: {0: "House", 1: "Road", 2: "Grass", 3: "Road", 4: "Road", 5: "Road", 6: "Road", 7: "Grass",
|
||||
8: "Road", 9: "House", 10: "Grass", 11: "House", 12: "Road", 13: "Grass", 14: "Road", 15: "House"},
|
||||
3: {0: "House", 1: "Road", 2: "Grass", 3: "Road", 4: "House", 5: "House", 6: "Road", 7: "Grass",
|
||||
8: "Road", 9: "House", 10: "House", 11: "House", 12: "Road", 13: "Grass", 14: "Road", 15: "House"},
|
||||
4: {0: "House", 1: "Road", 2: "Grass", 3: "Road", 4: "House", 5: "House", 6: "Road", 7: "Grass",
|
||||
8: "Road", 9: "Road", 10: "Road", 11: "Road", 12: "Road", 13: "Grass", 14: "Road", 15: "House"},
|
||||
5: {0: "House", 1: "Road", 2: "Grass", 3: "Road", 4: "House", 5: "House", 6: "Road", 7: "Grass",
|
||||
8: "Road", 9: "Road", 10: "Road", 11: "Road", 12: "Road", 13: "Grass", 14: "Road", 15: "House"},
|
||||
6: {0: "House", 1: "Road", 2: "Grass", 3: "Road", 4: "House", 5: "House", 6: "Road", 7: "Grass",
|
||||
8: "Road", 9: "House", 10: "House", 11: "House", 12: "Road", 13: "Grass", 14: "Road", 15: "House"},
|
||||
7: {0: "House", 1: "Road", 2: "Grass", 3: "Road", 4: "Road", 5: "Road", 6: "Road", 7: "Grass",
|
||||
8: "Road", 9: "House", 10: "Grass", 11: "House", 12: "Road", 13: "Grass", 14: "Road", 15: "House"},
|
||||
8: {0: "House", 1: "Road", 2: "Grass", 3: "Road", 4: "House", 5: "House", 6: "Road", 7: "Grass",
|
||||
8: "Road", 9: "House", 10: "Grass", 11: "House", 12: "Road", 13: "Grass", 14: "Road", 15: "House"},
|
||||
9: {0: "House", 1: "Road", 2: "Road", 3: "Road", 4: "House", 5: "House", 6: "Road", 7: "Road",
|
||||
8: "Road", 9: "House", 10: "Grass", 11: "House", 12: "Road", 13: "Road", 14: "Road", 15: "House"},
|
||||
}
|
||||
|
16
helpler.py
Normal file
16
helpler.py
Normal file
@ -0,0 +1,16 @@
|
||||
from config import MAP
|
||||
from models.Road import Road
|
||||
from models.Grass import Grass
|
||||
from models.House import House
|
||||
|
||||
|
||||
def Render_Element(x, y):
|
||||
item = MAP[y][x]
|
||||
if item == "Road":
|
||||
return Road(x, y)
|
||||
elif item == "Grass":
|
||||
return Grass(x, y)
|
||||
elif item == "House":
|
||||
return House(x, y)
|
||||
elif item == "Factory":
|
||||
pass
|
10
main.py
10
main.py
@ -1,13 +1,7 @@
|
||||
import pygame
|
||||
from models.Grass import Grass
|
||||
from models.Garbage_Collector import Garbage_Collector
|
||||
from models.Road import Road
|
||||
from models.House import House
|
||||
from models.Pond import Pond
|
||||
from models.Tree import Tree
|
||||
from models.Factory import Factory
|
||||
from models.Dump import Dump
|
||||
from config import WINDOW_HEIGHT, WINDOW_WIDTH
|
||||
from helpler import Render_Element
|
||||
|
||||
|
||||
pygame.init()
|
||||
@ -16,7 +10,7 @@ WINDOW = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
|
||||
|
||||
display_group = pygame.sprite.Group()
|
||||
|
||||
draw_items = [[Grass(x, y) for x in range(16)] for y in range(10)]
|
||||
draw_items = [[Render_Element(x, y) for x in range(16)] for y in range(10)]
|
||||
|
||||
for line in draw_items:
|
||||
for item in line:
|
||||
|
@ -1,22 +1,15 @@
|
||||
import pygame
|
||||
from config import CELL_SIZE, MAP_HEIGHT, MAP_WIDTH
|
||||
from random import randint
|
||||
from config import MAP
|
||||
|
||||
|
||||
class Garbage_Collector(pygame.sprite.Sprite):
|
||||
def __init__(self):
|
||||
pygame.sprite.Sprite.__init__(self)
|
||||
self.road_positions = {row_index: {
|
||||
col_index: True for col_index in range(16)} for row_index in range(10)}
|
||||
|
||||
# for row_index in self.road_positions:
|
||||
# for col_index in self.road_positions[row_index]:
|
||||
# self.road_positions[row_index][0] = False
|
||||
# self.road_positions[row_index][2] = False
|
||||
# self.road_positions[row_index][3] = False
|
||||
# self.road_positions[row_index][5] = False
|
||||
# self.road_positions[row_index][7] = False
|
||||
# self.road_positions[row_index][8] = False
|
||||
col_index: (True if MAP[row_index][col_index] == "Road" else False)
|
||||
for col_index in MAP[row_index]} for row_index in MAP}
|
||||
|
||||
gc_initial_position = {"row": randint(0, 9), "col": randint(0, 15)}
|
||||
while not self.road_positions[gc_initial_position["row"]][gc_initial_position["col"]]:
|
||||
|
@ -8,4 +8,4 @@ class Road (pygame.sprite.Sprite):
|
||||
self.rect = pygame.Rect(
|
||||
x * CELL_SIZE, y * CELL_SIZE, CELL_SIZE, CELL_SIZE)
|
||||
self.image = pygame.transform.scale(pygame.image.load(
|
||||
"Resources/Images/road.jpg"), (CELL_SIZE, CELL_SIZE))
|
||||
"Resources/Images/road.png"), (CELL_SIZE, CELL_SIZE))
|
||||
|
Loading…
Reference in New Issue
Block a user