add house class and simple test with draw it on field
This commit is contained in:
parent
74fa5435b9
commit
f81b6c38d0
29
house.py
Normal file
29
house.py
Normal file
@ -0,0 +1,29 @@
|
||||
import pygame.image
|
||||
from typing import Optional
|
||||
import os
|
||||
from random import randint
|
||||
|
||||
class House(pygame.sprite.Sprite):
|
||||
|
||||
def __init__(self, x:int, y:int,
|
||||
number_of_bins:int = 0, if_exist: bool = False):
|
||||
|
||||
super().__init__()
|
||||
self.number_of_bins = number_of_bins
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.if_exist = if_exist
|
||||
self.bin_id: Optional[int]
|
||||
self.base_path = "./resources/textures/buliding/"
|
||||
# Statyczny sprite domku, obecnie randomny
|
||||
# self.image = pygame.image.load("./resources/textures/buliding/GTA2_TILE_112.bmp")
|
||||
self.image = pygame.image.load(f"{self.base_path}{self.get_random_house_texture()}")
|
||||
|
||||
|
||||
def get_random_house_texture(self):
|
||||
files = os.listdir(self.base_path)
|
||||
value = randint(0, len(files)-1)
|
||||
return files[value]
|
||||
|
||||
|
||||
|
21
main.py
21
main.py
@ -1,7 +1,7 @@
|
||||
import pygame
|
||||
from map import preparedMap
|
||||
from agent import trashmaster
|
||||
|
||||
from house import House
|
||||
|
||||
class WalleGame():
|
||||
|
||||
@ -23,10 +23,11 @@ class WalleGame():
|
||||
def update_window(self):
|
||||
pygame.display.update()
|
||||
|
||||
def draw_trashmaster(self, smieciara: trashmaster, pos):
|
||||
def draw_object(self, drawable_object, pos):
|
||||
# pos => (x, y)
|
||||
self.screen.blit(smieciara.image, pos )
|
||||
|
||||
# drawable object must have .image field inside class
|
||||
self.screen.blit(drawable_object.image, pos )
|
||||
|
||||
def reloadMap(self):
|
||||
self.screen.fill(pygame.Color(self.BACKGROUND_COLOR))
|
||||
self.screen.blit(self.map, (0,0))
|
||||
@ -36,7 +37,11 @@ def main():
|
||||
game.update_window()
|
||||
|
||||
smieciara_object = trashmaster(16,16,"./resources/textures/garbagetruck/trashmaster_blu.png")
|
||||
game.draw_trashmaster(smieciara_object, (0, 0))
|
||||
game.draw_object(smieciara_object, (0, 0))
|
||||
|
||||
house_object = House(20, 20)
|
||||
# Test draw house object
|
||||
game.draw_object(house_object, (20,20))
|
||||
|
||||
game.update_window()
|
||||
|
||||
@ -48,9 +53,11 @@ def main():
|
||||
running = False
|
||||
if event.type == pygame.KEYDOWN:
|
||||
game.reloadMap()
|
||||
game.draw_trashmaster(smieciara_object,
|
||||
smieciara_object.movement(event.key, 16))
|
||||
game.draw_object(smieciara_object,
|
||||
smieciara_object.movement(event.key, 16))
|
||||
|
||||
game.update_window()
|
||||
|
||||
pygame.quit()
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user