gówno się zdarza
This commit is contained in:
parent
1955a6c0d9
commit
c232181ac8
@ -1,3 +1,6 @@
|
||||
import pygame
|
||||
|
||||
|
||||
class Garbagetruck:
|
||||
image: object
|
||||
position: object
|
||||
@ -5,12 +8,13 @@ class Garbagetruck:
|
||||
trash: list
|
||||
capacity: int
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, file="sprites/garbage_truck.png"):
|
||||
self.capacity: int = 20
|
||||
self.trash: list = []
|
||||
self.trashweight: int = 0
|
||||
self.image: object = None
|
||||
self.position: object = None
|
||||
self.image = pygame.image.load(file).convert_alpha()
|
||||
self.image = pygame.transform.scale(self.image, (32,32))
|
||||
self.position = [800, 500]
|
||||
self.route = None
|
||||
self.scanner = None
|
||||
self.planner = None
|
||||
|
@ -1,23 +0,0 @@
|
||||
class Tile:
|
||||
def __init__(self):
|
||||
self.position = None
|
||||
self.image = None
|
||||
self.parent = None
|
||||
|
||||
def getSprite(self):
|
||||
return self.image
|
||||
|
||||
def setSprite(self, sprite):
|
||||
self.image = sprite
|
||||
|
||||
def getPosition(self):
|
||||
return self.position
|
||||
|
||||
def setPosition(self, position):
|
||||
self.position = position
|
||||
|
||||
def getParent(self):
|
||||
return self.parent
|
||||
|
||||
def setParent(self, parent):
|
||||
self.parent = parent
|
35
classes/Tilemap.py
Normal file
35
classes/Tilemap.py
Normal file
@ -0,0 +1,35 @@
|
||||
import pygame
|
||||
import numpy as np
|
||||
|
||||
|
||||
class Tilemap:
|
||||
|
||||
def __init__(self, tileset, size=(30, 20), rect=None):
|
||||
self.size = size
|
||||
self.tileset = tileset
|
||||
self.map = np.zeros(size, dtype=int)
|
||||
h, w = self.size
|
||||
self.image = pygame.Surface((32*w, 32*h))
|
||||
if rect:
|
||||
self.rect = pygame.Rect(rect)
|
||||
else:
|
||||
self.rect = self.image.get_rect()
|
||||
|
||||
def render(self):
|
||||
m, n = self.map.shape
|
||||
for i in range(m):
|
||||
for j in range(n):
|
||||
tile = self.tileset.tiles[self.map[i, j]]
|
||||
self.image.blit(tile, (i*32, j*32))
|
||||
|
||||
def set_zero(self):
|
||||
self.map = np.zeros(self.size, dtype=int)
|
||||
self.render()
|
||||
|
||||
def set_random(self):
|
||||
n = len(self.tileset.tiles)
|
||||
self.map = np.random.randint(n, size=self.size)
|
||||
self.render()
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.__class__.__name__} {self.size}'
|
29
classes/Tileset.py
Normal file
29
classes/Tileset.py
Normal file
@ -0,0 +1,29 @@
|
||||
import pygame
|
||||
|
||||
|
||||
class Tileset:
|
||||
|
||||
def __init__(self, file, size=(32, 32), margin=1, spacing=1):
|
||||
self.file = file
|
||||
self.size = size
|
||||
self.margin = margin
|
||||
self.spacing = spacing
|
||||
self.image = pygame.image.load(file)
|
||||
self.rect = self.image.get_rect()
|
||||
self.tiles = []
|
||||
self.load()
|
||||
|
||||
def load(self):
|
||||
self.tiles = []
|
||||
x0 = y0 = self.margin
|
||||
w, h = self.rect.size
|
||||
dx = self.size[0] + self.spacing
|
||||
dy = self.size[1] + self.spacing
|
||||
for x in range(x0, w, dx):
|
||||
for y in range(y0, h, dy):
|
||||
tile = pygame.Surface(self.size)
|
||||
tile.blit(self.image, (0, 0), (x, y, *self.size))
|
||||
self.tiles.append(tile)
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.__class__.__name__} file:{self.file} tile:{self.size}'
|
@ -1,6 +1,7 @@
|
||||
from classes.Junkyard import *
|
||||
from classes.Trashcan import *
|
||||
from classes.Household import *
|
||||
from classes.Garbagetruck import *
|
||||
from QOLfunc import *
|
||||
import pygame
|
||||
|
||||
|
13
main.py
13
main.py
@ -9,18 +9,9 @@ colors = {
|
||||
"red": (255, 0, 0)
|
||||
}
|
||||
|
||||
garbage_truck_image = pygame.image.load('sprites/garbage_truck.png')
|
||||
|
||||
new_garbage_truck_size = (120, 120)
|
||||
new_house_size = (140, 120)
|
||||
|
||||
garbage_truck_image = garbage_truck_image.convert_alpha()
|
||||
garbage_truck_image = pygame.transform.scale(garbage_truck_image, new_garbage_truck_size)
|
||||
|
||||
|
||||
garbage_truck_position = [800, 500]
|
||||
|
||||
|
||||
garbagetruck = Garbagetruck()
|
||||
junkyard = Junkyard()
|
||||
trashcans = trashcanGenerator(junkyard)
|
||||
houses = householdGenerator(junkyard)
|
||||
@ -48,7 +39,7 @@ while running:
|
||||
screen.blit(house.getImage(), house.getPosition())
|
||||
pygame.draw.circle(screen, colors["red"], junkyard.getPosition(), 10)
|
||||
|
||||
screen.blit(garbage_truck_image, junkyard.getPosition())
|
||||
screen.blit(garbagetruck.getImage(), junkyard.getPosition())
|
||||
pygame.display.flip()
|
||||
|
||||
pygame.quit()
|
||||
|
25
tests.py
Normal file
25
tests.py
Normal file
@ -0,0 +1,25 @@
|
||||
from classes.Tilemap import *
|
||||
from classes.Tileset import *
|
||||
|
||||
W = 960
|
||||
H = 640
|
||||
SIZE = (W, H)
|
||||
|
||||
pygame.init()
|
||||
|
||||
screen = pygame.display.set_mode(SIZE)
|
||||
pygame.display.set_caption("Tilemap Demo")
|
||||
tilemap = Tilemap(Tileset("sprites/Tiles/1 Tiles/FieldsTile_38.png"), (30, 20))
|
||||
|
||||
running = True
|
||||
while running:
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
running = False
|
||||
|
||||
screen.fill((0, 0, 0))
|
||||
tilemap.render()
|
||||
screen.blit(tilemap.image, tilemap.rect)
|
||||
pygame.display.update()
|
||||
|
||||
pygame.quit()
|
Loading…
Reference in New Issue
Block a user