diff --git a/game_objects/trashbin.py b/game_objects/trashbin.py index 1538c79..9b8ea8b 100644 --- a/game_objects/trashbin.py +++ b/game_objects/trashbin.py @@ -1,29 +1,23 @@ import pygame as pg +from enum import Enum -class trashbin(pg.sprite.Sprite): - - def __init__(self,x,y,img, type): - super().__init__() +from map.tile import Tile + +class Waste_Type(Enum): + BIO = 0 + GLASS = 1 + PLASTIC = 2 + PAPER = 3 + MIX = 4 + + def __int__(self): + return self.value +class Trashbin(Tile): + def __init__(self, img, x, y, width, height, waste_type: Waste_Type): + super().__init__(img, x, y, width, height) - # trashbin type - self.type = type - - # dimensions - if type == "small": - self.width = 4 - self.height = 4 - elif type == "medium": - self.width = 8 - self.height = 8 - elif type == "large": - self.width = 16 - self.height = 16 - - # spawn coords - self.x = x - self.y = y - - # load trashbin image - self.image = pg.image.load(img) - self.image = pg.transform.scale(self.image, (self.x,self.y)) - self.rect = self.image.get_rect() \ No newline at end of file + self.waste_type = waste_type + self.days_after_pickup = 0 + self.max_capacity = 100 + self.used_capacity = 0 + self.access = True diff --git a/main.py b/main.py index 598f5b4..8e12ca7 100644 --- a/main.py +++ b/main.py @@ -32,7 +32,7 @@ class Game(): # initialize all variables and do all the setup for a new game # sprite groups and map array for calculations - (self.roadTiles, self.wallTiles), self.mapArray = map.get_tiles() + (self.roadTiles, self.wallTiles, self.trashbinTiles), self.mapArray = map.get_tiles() self.agentSprites = pg.sprite.Group() # player obj @@ -102,6 +102,7 @@ class Game(): #rerender map map.render_tiles(self.roadTiles, self.screen, self.camera) map.render_tiles(self.wallTiles, self.screen, self.camera, self.debug_mode) + map.render_tiles(self.trashbinTiles, self.screen, self.camera) #rerender additional sprites for sprite in self.agentSprites: diff --git a/map/camera.py b/map/camera.py deleted file mode 100644 index ee229f7..0000000 --- a/map/camera.py +++ /dev/null @@ -1,24 +0,0 @@ -from settings import * - -class Camera: - def __init__(self,width,height): - self.camera = pg.Rect(0,0, width, height) - self.width = width - self.height = height - - def apply(self,entity): - return entity.rect.move(self.camera.topleft) - - def apply_rect(self, rect): - return rect.move(self.camera.topleft) - - def update(self,target): - x = -target.rect.x + int(WIDTH/2) - y = -target.rect.y + int(HEIGHT / 2) - - # limit scrolling to map size - x = min(0, x) # left - y = min(0, y) # top - x = max(-(self.width - WIDTH), x) # right - y = max(-(self.height - HEIGHT), y) # bottom - self.camera = pg.Rect(x, y, self.width, self.height) \ No newline at end of file diff --git a/map/map_pattern.py b/map/map_pattern.py index c129396..1e6526f 100644 --- a/map/map_pattern.py +++ b/map/map_pattern.py @@ -8,10 +8,19 @@ ROAD_DIR = TEXTURES_DIR+"\\road\\" BUILDING_DIR = TEXTURES_DIR+"\\buliding\\" def load_img(path): - return pg.image.load(path) + return pg.image.load(path).convert_alpha() def get_pattern(): return { 0: load_img("resources/textures/road/GTA2_TILE_257.bmp"), - 1: load_img("resources/textures/buliding/GTA2_TILE_187.bmp"), + 1: load_img("resources/textures/buliding/GTA2_TILE_187.bmp") + } + +def get_trashbin_pattern(): + return { + 0: load_img("resources/textures/misc/trash_bin_small_bio.png"), + 1: load_img("resources/textures/misc/trash_bin_small_glass.png"), + 2: load_img("resources/textures/misc/trash_bin_small_plastic.png"), + 3: load_img("resources/textures/misc/trash_bin_small_paper.png"), + 4: load_img("resources/textures/misc/trash_bin_small.png") } \ No newline at end of file diff --git a/map/map_utils.py b/map/map_utils.py index f889e2c..1a32047 100644 --- a/map/map_utils.py +++ b/map/map_utils.py @@ -2,6 +2,8 @@ import random import pygame as pg from settings import * from map.tile import Tile +from map import map_pattern +from game_objects.trashbin import Trashbin # tworzenie pustego arraya o podanych wymiarach def get_blank_map_array(): @@ -11,16 +13,28 @@ def get_blank_map_array(): # generowanie obiektow na mapie def generate_map(): map = get_blank_map_array() + + # generowanie scian for i in range(0, 20): x = random.randint(0, MAP_WIDTH-1) y = random.randint(0, MAP_HEIGHT-1) map[y][x] = 1 + + # generowanie smietnikow + for i in range(0, 5): + x = random.randint(0, MAP_WIDTH-1) + y = random.randint(0, MAP_HEIGHT-1) + map[y][x] = 2 + return map # tworzenie grup sprite'ow def get_sprites(map, pattern): roadTiles = pg.sprite.Group() wallTiles = pg.sprite.Group() + trashbinTiles = pg.sprite.Group() + + trashbin_pattern = map_pattern.get_trashbin_pattern() #objechanie tablicy i generowanie tile'a na danych kordach for i in range(len(map)): @@ -28,13 +42,26 @@ def get_sprites(map, pattern): for j in range(len(map[i])): offsetX = j * TILE_SIZE_PX tileId = map[i][j] - tile = Tile(pattern[tileId], offsetX, offsetY, TILE_SIZE_PX, TILE_SIZE_PX) - if tileId == 0: + if tileId == 0 or tileId == 1: + tile = Tile(pattern[tileId], offsetX, offsetY, TILE_SIZE_PX, TILE_SIZE_PX) + if tileId == 0: + roadTiles.add(tile) + else: + wallTiles.add(tile) + elif tileId == 2: + trashbinId = random.randint(0, 4) + tile = Tile(pattern[0], offsetX, offsetY, TILE_SIZE_PX, TILE_SIZE_PX) + trashbin = Trashbin(trashbin_pattern[trashbinId], offsetX, offsetY, 32, 30, trashbinId) roadTiles.add(tile) - else: - wallTiles.add(tile) + trashbinTiles.add(trashbin) - return roadTiles, wallTiles + return roadTiles, wallTiles, trashbinTiles + +def isRoadTile(tileId: int) -> bool: + if tileId == 0 or tileId == 2: + return True + else: + return False class Camera: def __init__(self,width,height): diff --git a/map/tile.py b/map/tile.py index a2467f2..1e32a0b 100644 --- a/map/tile.py +++ b/map/tile.py @@ -10,7 +10,7 @@ class Tile(pg.sprite.Sprite): self.width = width self.height = height - self.image = pg.Surface([width, height]) + self.image = pg.Surface([width, height], pg.SRCALPHA, 32) self.image.blit(img, (0,0)) self.rect = pg.Rect(x, y, width, height) diff --git a/path_search_algorthms/a_star_utils.py b/path_search_algorthms/a_star_utils.py index 20caee1..ee24f61 100644 --- a/path_search_algorthms/a_star_utils.py +++ b/path_search_algorthms/a_star_utils.py @@ -1,9 +1,8 @@ from enum import Enum +from map import map_utils from settings import * -ROAD_TILE = 0 - class Rotation(Enum): UP = 0 RIGHT = 1 @@ -36,7 +35,7 @@ def get_neighbours(node, searched_list, array): y = node.y + offset_y # prevent out of map coords if (x >= 0 and x < MAP_WIDTH and y >= 0 and y < MAP_HEIGHT): - if(array[y][x] == ROAD_TILE and (x, y) not in searched_list): + if(map_utils.isRoadTile(array[y][x]) and (x, y) not in searched_list): neighbour = Node(x, y, Rotation.NONE) neighbour.rotation = get_needed_rotation(node, neighbour) neighbours.append(neighbour) diff --git a/resources/textures/misc/trash_bin.png b/resources/textures/misc/trash_bin.png new file mode 100644 index 0000000..686ed0c Binary files /dev/null and b/resources/textures/misc/trash_bin.png differ diff --git a/resources/textures/misc/trash_bin_small.png b/resources/textures/misc/trash_bin_small.png new file mode 100644 index 0000000..1ea5920 Binary files /dev/null and b/resources/textures/misc/trash_bin_small.png differ diff --git a/resources/textures/misc/trash_bin_small_bio.png b/resources/textures/misc/trash_bin_small_bio.png new file mode 100644 index 0000000..156d60a Binary files /dev/null and b/resources/textures/misc/trash_bin_small_bio.png differ diff --git a/resources/textures/misc/trash_bin_small_glass.png b/resources/textures/misc/trash_bin_small_glass.png new file mode 100644 index 0000000..f5923bf Binary files /dev/null and b/resources/textures/misc/trash_bin_small_glass.png differ diff --git a/resources/textures/misc/trash_bin_small_paper.png b/resources/textures/misc/trash_bin_small_paper.png new file mode 100644 index 0000000..cbc4af0 Binary files /dev/null and b/resources/textures/misc/trash_bin_small_paper.png differ diff --git a/resources/textures/misc/trash_bin_small_plastic.png b/resources/textures/misc/trash_bin_small_plastic.png new file mode 100644 index 0000000..7cf5a4d Binary files /dev/null and b/resources/textures/misc/trash_bin_small_plastic.png differ