trashbin-rendering #23
@ -1,29 +1,23 @@
|
||||
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):
|
||||
super().__init__()
|
||||
class Waste_Type(Enum):
|
||||
BIO = 0
|
||||
GLASS = 1
|
||||
PLASTIC = 2
|
||||
PAPER = 3
|
||||
MIX = 4
|
||||
|
||||
# trashbin type
|
||||
self.type = type
|
||||
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)
|
||||
|
||||
# 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()
|
||||
self.waste_type = waste_type
|
||||
self.days_after_pickup = 0
|
||||
self.max_capacity = 100
|
||||
self.used_capacity = 0
|
||||
self.access = True
|
||||
|
3
main.py
3
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:
|
||||
|
@ -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")
|
||||
}
|
@ -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):
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user