Merge pull request 'trashbin-rendering' (#23) from trashbin-rendering into master
Reviewed-on: #23
This commit is contained in:
commit
8d563da40d
@ -1,29 +1,23 @@
|
|||||||
import pygame as pg
|
import pygame as pg
|
||||||
|
from enum import Enum
|
||||||
|
|
||||||
class trashbin(pg.sprite.Sprite):
|
from map.tile import Tile
|
||||||
|
|
||||||
def __init__(self,x,y,img, type):
|
class Waste_Type(Enum):
|
||||||
super().__init__()
|
BIO = 0
|
||||||
|
GLASS = 1
|
||||||
|
PLASTIC = 2
|
||||||
|
PAPER = 3
|
||||||
|
MIX = 4
|
||||||
|
|
||||||
# trashbin type
|
def __int__(self):
|
||||||
self.type = type
|
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)
|
||||||
|
|
||||||
# dimensions
|
self.waste_type = waste_type
|
||||||
if type == "small":
|
self.days_after_pickup = 0
|
||||||
self.width = 4
|
self.max_capacity = 100
|
||||||
self.height = 4
|
self.used_capacity = 0
|
||||||
elif type == "medium":
|
self.access = True
|
||||||
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()
|
|
||||||
|
3
main.py
3
main.py
@ -32,7 +32,7 @@ class Game():
|
|||||||
# initialize all variables and do all the setup for a new game
|
# initialize all variables and do all the setup for a new game
|
||||||
|
|
||||||
# sprite groups and map array for calculations
|
# 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()
|
self.agentSprites = pg.sprite.Group()
|
||||||
|
|
||||||
# player obj
|
# player obj
|
||||||
@ -102,6 +102,7 @@ class Game():
|
|||||||
#rerender map
|
#rerender map
|
||||||
map.render_tiles(self.roadTiles, self.screen, self.camera)
|
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.wallTiles, self.screen, self.camera, self.debug_mode)
|
||||||
|
map.render_tiles(self.trashbinTiles, self.screen, self.camera)
|
||||||
|
|
||||||
#rerender additional sprites
|
#rerender additional sprites
|
||||||
for sprite in self.agentSprites:
|
for sprite in self.agentSprites:
|
||||||
|
@ -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)
|
|
@ -8,10 +8,19 @@ ROAD_DIR = TEXTURES_DIR+"\\road\\"
|
|||||||
BUILDING_DIR = TEXTURES_DIR+"\\buliding\\"
|
BUILDING_DIR = TEXTURES_DIR+"\\buliding\\"
|
||||||
|
|
||||||
def load_img(path):
|
def load_img(path):
|
||||||
return pg.image.load(path)
|
return pg.image.load(path).convert_alpha()
|
||||||
|
|
||||||
def get_pattern():
|
def get_pattern():
|
||||||
return {
|
return {
|
||||||
0: load_img("resources/textures/road/GTA2_TILE_257.bmp"),
|
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")
|
||||||
}
|
}
|
@ -2,6 +2,8 @@ import random
|
|||||||
import pygame as pg
|
import pygame as pg
|
||||||
from settings import *
|
from settings import *
|
||||||
from map.tile import Tile
|
from map.tile import Tile
|
||||||
|
from map import map_pattern
|
||||||
|
from game_objects.trashbin import Trashbin
|
||||||
|
|
||||||
# tworzenie pustego arraya o podanych wymiarach
|
# tworzenie pustego arraya o podanych wymiarach
|
||||||
def get_blank_map_array():
|
def get_blank_map_array():
|
||||||
@ -11,16 +13,28 @@ def get_blank_map_array():
|
|||||||
# generowanie obiektow na mapie
|
# generowanie obiektow na mapie
|
||||||
def generate_map():
|
def generate_map():
|
||||||
map = get_blank_map_array()
|
map = get_blank_map_array()
|
||||||
|
|
||||||
|
# generowanie scian
|
||||||
for i in range(0, 20):
|
for i in range(0, 20):
|
||||||
x = random.randint(0, MAP_WIDTH-1)
|
x = random.randint(0, MAP_WIDTH-1)
|
||||||
y = random.randint(0, MAP_HEIGHT-1)
|
y = random.randint(0, MAP_HEIGHT-1)
|
||||||
map[y][x] = 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
|
return map
|
||||||
|
|
||||||
# tworzenie grup sprite'ow
|
# tworzenie grup sprite'ow
|
||||||
def get_sprites(map, pattern):
|
def get_sprites(map, pattern):
|
||||||
roadTiles = pg.sprite.Group()
|
roadTiles = pg.sprite.Group()
|
||||||
wallTiles = 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
|
#objechanie tablicy i generowanie tile'a na danych kordach
|
||||||
for i in range(len(map)):
|
for i in range(len(map)):
|
||||||
@ -28,13 +42,26 @@ def get_sprites(map, pattern):
|
|||||||
for j in range(len(map[i])):
|
for j in range(len(map[i])):
|
||||||
offsetX = j * TILE_SIZE_PX
|
offsetX = j * TILE_SIZE_PX
|
||||||
tileId = map[i][j]
|
tileId = map[i][j]
|
||||||
|
if tileId == 0 or tileId == 1:
|
||||||
tile = Tile(pattern[tileId], offsetX, offsetY, TILE_SIZE_PX, TILE_SIZE_PX)
|
tile = Tile(pattern[tileId], offsetX, offsetY, TILE_SIZE_PX, TILE_SIZE_PX)
|
||||||
if tileId == 0:
|
if tileId == 0:
|
||||||
roadTiles.add(tile)
|
roadTiles.add(tile)
|
||||||
else:
|
else:
|
||||||
wallTiles.add(tile)
|
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)
|
||||||
|
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:
|
class Camera:
|
||||||
def __init__(self,width,height):
|
def __init__(self,width,height):
|
||||||
|
@ -10,7 +10,7 @@ class Tile(pg.sprite.Sprite):
|
|||||||
self.width = width
|
self.width = width
|
||||||
self.height = height
|
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.image.blit(img, (0,0))
|
||||||
|
|
||||||
self.rect = pg.Rect(x, y, width, height)
|
self.rect = pg.Rect(x, y, width, height)
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
|
||||||
|
from map import map_utils
|
||||||
from settings import *
|
from settings import *
|
||||||
|
|
||||||
ROAD_TILE = 0
|
|
||||||
|
|
||||||
class Rotation(Enum):
|
class Rotation(Enum):
|
||||||
UP = 0
|
UP = 0
|
||||||
RIGHT = 1
|
RIGHT = 1
|
||||||
@ -36,7 +35,7 @@ def get_neighbours(node, searched_list, array):
|
|||||||
y = node.y + offset_y
|
y = node.y + offset_y
|
||||||
# prevent out of map coords
|
# prevent out of map coords
|
||||||
if (x >= 0 and x < MAP_WIDTH and y >= 0 and y < MAP_HEIGHT):
|
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 = Node(x, y, Rotation.NONE)
|
||||||
neighbour.rotation = get_needed_rotation(node, neighbour)
|
neighbour.rotation = get_needed_rotation(node, neighbour)
|
||||||
neighbours.append(neighbour)
|
neighbours.append(neighbour)
|
||||||
|
BIN
resources/textures/misc/trash_bin.png
Normal file
BIN
resources/textures/misc/trash_bin.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 17 KiB |
BIN
resources/textures/misc/trash_bin_small.png
Normal file
BIN
resources/textures/misc/trash_bin_small.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.3 KiB |
BIN
resources/textures/misc/trash_bin_small_bio.png
Normal file
BIN
resources/textures/misc/trash_bin_small_bio.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 10 KiB |
BIN
resources/textures/misc/trash_bin_small_glass.png
Normal file
BIN
resources/textures/misc/trash_bin_small_glass.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
BIN
resources/textures/misc/trash_bin_small_paper.png
Normal file
BIN
resources/textures/misc/trash_bin_small_paper.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
BIN
resources/textures/misc/trash_bin_small_plastic.png
Normal file
BIN
resources/textures/misc/trash_bin_small_plastic.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.8 KiB |
Loading…
Reference in New Issue
Block a user