checkpoint

This commit is contained in:
lechwolowski 2020-04-02 19:53:39 +02:00
parent a36f436af8
commit 3456f34ba6
18 changed files with 294 additions and 172 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 3.7 KiB

View File

@ -0,0 +1,88 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
sodipodi:docname="my-mixed.svg"
inkscape:version="1.0beta2 (2b71d25, 2019-12-03)"
id="svg24"
version="1.1"
viewBox="0 0 100 100"
height="100mm"
width="100mm">
<defs
id="defs18" />
<sodipodi:namedview
inkscape:document-rotation="0"
inkscape:window-maximized="0"
inkscape:window-y="0"
inkscape:window-x="0"
inkscape:window-height="1058"
inkscape:window-width="1600"
showgrid="false"
inkscape:current-layer="g835"
inkscape:document-units="mm"
inkscape:cy="192.05147"
inkscape:cx="137.43365"
inkscape:zoom="1.4"
inkscape:pageshadow="2"
inkscape:pageopacity="0.0"
borderopacity="1.0"
bordercolor="#666666"
pagecolor="#ffffff"
id="base" />
<metadata
id="metadata21">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
transform="translate(0,-197)"
id="layer1"
inkscape:groupmode="layer"
inkscape:label="Layer 1">
<rect
y="195.10567"
x="-1.5616949"
height="103.56548"
width="103.56548"
id="rect26"
style="fill:#71c837;stroke-width:0.34196147" />
<g
id="g835"
transform="matrix(0.2022538,0,0,0.2022538,8.0341431,195.11143)">
<path
d="M 341.21484,512 H 75.953125 C 68,512 61.371094,505.90234 60.714844,497.97266 L 30.125,129.89453 c -0.355469,-4.26172 1.09375,-8.47656 3.988281,-11.625 2.894531,-3.14453 6.976563,-4.93359 11.253907,-4.93359 H 371.80078 c 4.27734,0 8.35547,1.78906 11.25391,4.93359 2.89453,3.14844 4.33984,7.36328 3.98828,11.625 L 356.45312,497.97266 C 355.79687,505.90234 349.16797,512 341.21484,512 Z m 0,0"
id="path2"
style="fill:#666666"
inkscape:connector-curvature="0" />
<path
d="M 401.875,143.92187 H 15.292969 C 6.847656,143.92187 0,137.07422 0,128.62891 0,88.0625 33.003906,55.058594 73.570312,55.058594 H 343.59766 c 40.5664,0 73.57031,33.003906 73.57031,73.570316 0,8.44531 -6.84766,15.29296 -15.29297,15.29296 z m 0,0"
id="path18"
inkscape:connector-curvature="0"
style="fill:#414952" />
<path
d="M 35.097656,189.72656 H 382.07031 L 385.875,143.92187 H 31.292969 Z m 0,0"
id="path22"
style="fill:#4d4d4d"
inkscape:connector-curvature="0" />
<path
transform="matrix(1.3081748,0,0,1.3081748,-39.723076,9.3376243)"
inkscape:connector-curvature="0"
id="path53"
d="M 36.113614,100.72761 C 32.083596,98.011784 30.770869,94.9566 30.921721,88.644221 31.480463,65.263616 47.964506,44.605953 71.984628,37.184534 l 5.234736,-1.617359 108.928576,-0.222037 c 78.47662,-0.159965 110.51648,0.0044 114.60864,0.58805 24.78791,3.535231 44.29606,23.357198 47.62974,48.395919 0.98861,7.425232 0.50447,10.75684 -1.99475,13.72699 -3.89528,4.629283 8.86522,4.281083 -156.88825,4.281083 H 38.502054 Z"
style="fill:#333333;stroke-width:0.714286" />
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 3.5 KiB

View File

@ -0,0 +1,93 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
sodipodi:docname="my_glass.svg"
inkscape:version="1.0beta2 (2b71d25, 2019-12-03)"
id="svg8"
version="1.1"
viewBox="0 0 210 297"
height="297mm"
width="210mm">
<defs
id="defs2" />
<sodipodi:namedview
inkscape:window-maximized="0"
inkscape:window-y="0"
inkscape:window-x="0"
inkscape:window-height="1058"
inkscape:window-width="1600"
showgrid="false"
inkscape:document-rotation="0"
inkscape:current-layer="g835"
inkscape:document-units="mm"
inkscape:cy="546.14719"
inkscape:cx="400"
inkscape:zoom="0.66"
inkscape:pageshadow="2"
inkscape:pageopacity="0.0"
borderopacity="1.0"
bordercolor="#666666"
pagecolor="#ffffff"
id="base" />
<metadata
id="metadata5">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
id="layer1"
inkscape:groupmode="layer"
inkscape:label="Layer 1">
<g
inkscape:label="Layer 1"
id="layer1-7"
transform="matrix(2.0277026,0,0,2.0230643,4.9844865,-392.65152)">
<rect
style="fill:#71c837;stroke-width:0.341961"
id="rect26"
width="103.56548"
height="103.56548"
x="-2.271791"
y="194.4119" />
<g
style="display:inline"
transform="matrix(0.2027401,0,0,0.2027401,7.2226126,194.21567)"
id="g835">
<path
inkscape:connector-curvature="0"
style="fill:#55d400"
id="path2"
d="M 341.21484,512 H 75.953125 C 68,512 61.371094,505.90234 60.714844,497.97266 L 30.125,129.89453 c -0.355469,-4.26172 1.09375,-8.47656 3.988281,-11.625 2.894531,-3.14453 6.976563,-4.93359 11.253907,-4.93359 H 371.80078 c 4.27734,0 8.35547,1.78906 11.25391,4.93359 2.89453,3.14844 4.33984,7.36328 3.98828,11.625 L 356.45312,497.97266 C 355.79687,505.90234 349.16797,512 341.21484,512 Z m 0,0" />
<path
style="fill:#1a1a1a"
inkscape:connector-curvature="0"
id="path18"
d="M 401.875,143.92187 H 15.292969 C 6.847656,143.92187 0,137.07422 0,128.62891 0,88.0625 33.003906,55.058594 73.570312,55.058594 H 343.59766 c 40.5664,0 73.57031,33.003906 73.57031,73.570316 0,8.44531 -6.84766,15.29296 -15.29297,15.29296 z m 0,0" />
<path
inkscape:connector-curvature="0"
style="fill:#002b00"
id="path22"
d="M 35.097656,189.72656 H 382.07031 L 385.875,143.92187 H 31.292969 Z m 0,0" />
<path
transform="matrix(0.64360375,0,0,0.64507935,-47.749837,-0.63212123)"
inkscape:connector-curvature="0"
id="path46"
d="m 181.36364,790.90391 c -7.22977,-4.46578 -9.80581,-8.28707 -11.48314,-17.03401 -0.86244,-4.4975 -10.04402,-111.1318 -20.40352,-236.96514 -10.35949,-125.83333 -19.22611,-231.6856 -19.70359,-235.22727 l -0.86816,-6.43939 h 269.03224 c 147.96773,0 269.03279,0.51136 269.03347,1.13636 6.8e-4,0.625 -8.90915,108.52273 -19.79962,239.77273 -21.99985,265.13815 -19.9243,248.52939 -31.81611,254.59613 -5.72515,2.92074 -10.0255,2.97952 -217.64333,2.97396 -203.55458,-0.005 -211.9798,-0.115 -216.34824,-2.81337 z"
style="fill:#225500;stroke-width:1.51515" />
</g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 3.8 KiB

View File

@ -2,10 +2,8 @@ from config import MAP
from models.Road import Road
from models.Grass import Grass
from models.House import House
from models.Trash_Glass import Trash_Glass
from models.Trash_Paper import Trash_Paper
from models.Trash_Plastic import Trash_Plastic
from models.Trash_Mixed import Trash_Mixed
from models.Trash import Trash
def Render_Element(x, y):
@ -16,11 +14,5 @@ def Render_Element(x, y):
return Grass(x, y)
elif item == "House":
return House(x, y)
elif item == "Glass":
return Trash_Glass(x, y)
elif item == "Paper":
return Trash_Paper(x, y)
elif item == "Plastic":
return Trash_Plastic(x, y)
elif item == "Mixed":
return Trash_Mixed(x, y)
else:
return Trash(x, y, item)

47
knowledge.py Normal file
View File

@ -0,0 +1,47 @@
from models.House import House
# from models.Trash_Glass import Trash_Glass
from models.Trash_Paper import Trash_Paper
from models.Trash_Plastic import Trash_Plastic
from models.Trash_Mixed import Trash_Mixed
class Knowledge:
def __init__(self, items, gc):
self.num = items
self.gc = gc
self.houses = []
for line in items:
for item in line:
if isinstance(item, House):
self.houses.append(item)
elif isinstance(item, Trash_Mixed):
print(item.trash)
self.Trash_Mixed = item
elif isinstance(item, Trash_Paper):
print(item.trash)
self.Trash_Paper = item
elif isinstance(item, Trash_Glass):
print(item.trash)
self.Trash_Glass = item
elif isinstance(item, Trash_Plastic):
print(item.trash)
self.Trash_Plastic = item
def show(self):
print({"Trash": {"mixed": self.Trash_Mixed.trash, "glass": self.Trash_Glass.trash,
"paper": self.Trash_Paper.trash, "plastic": self.Trash_Plastic.trash}},
{"Garbage Collector": {"mixed": self.gc.mixed, "glass": self.gc.glass,
"paper": self.gc.paper, "plastic": self.gc.plastic}}
)
print(self.houses)
for house in self.houses:
print(house.mixed)
# inst = Knowledge(5)
# numb = inst
# inst.update(2)
# print(inst.num, numb.num)

34
main.py
View File

@ -1,7 +1,9 @@
import pygame
from models.Garbage_Collector import Garbage_Collector
from config import WINDOW_HEIGHT, WINDOW_WIDTH
from helpler import Render_Element
from config import WINDOW_HEIGHT, WINDOW_WIDTH, TRASH_GLASS_IMAGE
# from helpler import Render_Element
# from knowledge import Knowledge
from models.Trash import Trash
pygame.init()
@ -10,18 +12,22 @@ WINDOW = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
display_group = pygame.sprite.Group()
draw_items = [[Render_Element(x, y) for x in range(16)] for y in range(10)]
# draw_items = [[Render_Element(x, y) for x in range(16)] for y in range(10)]
for line in draw_items:
for item in line:
display_group.add(item)
# for line in draw_items:
# for item in line:
# display_group.add(item)
gc = Garbage_Collector()
# gc = Garbage_Collector()
display_group.add(gc)
# display_group.add(gc)
clock = pygame.time.Clock()
glassg = pygame.sprite.Group()
glassg.add(Trash(0, 0, "Glass", TRASH_GLASS_IMAGE))
def refresh_screen():
display_group.draw(WINDOW)
@ -32,7 +38,11 @@ def refresh_screen():
pygame.display.update()
refresh_screen()
glassg.draw(WINDOW)
pygame.display.update()
# know = Knowledge(draw_items, gc)
# refresh_screen()
# Game Loop
running = True
while running:
@ -51,7 +61,11 @@ while running:
gc.move_down()
if event.key == pygame.K_SPACE:
gc.trash_flow(draw_items)
# know.show()
refresh_screen()
# refresh_screen()
glassg.draw(WINDOW)
pygame.display.update()
clock.tick(30)

View File

@ -1,11 +0,0 @@
import pygame
from config import CELL_SIZE
class Factory (pygame.sprite.Sprite):
def __init__(self, x, y):
pygame.sprite.Sprite.__init__(self)
self.rect = pygame.Rect(
x * CELL_SIZE, y * CELL_SIZE, CELL_SIZE, CELL_SIZE)
self.image = pygame.transform.scale(pygame.image.load(
"Resources/Images/factory.jpg"), (CELL_SIZE, CELL_SIZE))

View File

@ -2,10 +2,6 @@ import pygame
from config import CELL_SIZE, MAP_HEIGHT, MAP_WIDTH, MAP, FONT, BLACK, BLUE, GREEN, YELLOW, GARBAGE_COLLECTOR_IMAGE
from random import randint
from models.House import House
from models.Trash_Glass import Trash_Glass
from models.Trash_Paper import Trash_Paper
from models.Trash_Plastic import Trash_Plastic
from models.Trash_Mixed import Trash_Mixed
from PIL import Image
from PIL import ImageFont
from PIL import ImageDraw
@ -35,7 +31,7 @@ class Garbage_Collector(Numbers):
Numbers.__init__(self, self.col, self.row)
self.text_update()
self.img_update(GARBAGE_COLLECTOR_IMAGE, self.texts, self.rotation)
# self.img_update(GARBAGE_COLLECTOR_IMAGE, self.texts, self.rotation)
def text_update(self):
self.texts = [
@ -53,8 +49,8 @@ class Garbage_Collector(Numbers):
self.rect = pygame.Rect(
self.col * CELL_SIZE, self.row * CELL_SIZE, CELL_SIZE, CELL_SIZE)
self.text_update()
self.img_update(GARBAGE_COLLECTOR_IMAGE, self.texts,
self.rotation, self.mirror)
# self.img_update(GARBAGE_COLLECTOR_IMAGE, self.texts,
# self.rotation, self.mirror)
def move_up(self):
self.rotation = 90

View File

@ -14,7 +14,7 @@ class House (Numbers):
self.glass = 5
self.plastic = 5
self.text_update()
self.img_update(HOUSE_IMAGE, self.texts)
# self.img_update(HOUSE_IMAGE, self.texts)
def text_update(self):
self.texts = [
@ -29,7 +29,7 @@ class House (Numbers):
if self.mixed > 0:
self.mixed -= 1
self.text_update()
self.img_update(HOUSE_IMAGE, self.texts)
# self.img_update(HOUSE_IMAGE, self.texts)
return True
else:
return False
@ -38,7 +38,7 @@ class House (Numbers):
if self.paper > 0:
self.paper -= 1
self.text_update()
self.img_update(HOUSE_IMAGE, self.texts)
# self.img_update(HOUSE_IMAGE, self.texts)
return True
else:
return False
@ -47,7 +47,7 @@ class House (Numbers):
if self.glass > 0:
self.glass -= 1
self.text_update()
self.img_update(HOUSE_IMAGE, self.texts)
# self.img_update(HOUSE_IMAGE, self.texts)
return True
else:
return False
@ -56,7 +56,7 @@ class House (Numbers):
if self.plastic > 0:
self.plastic -= 1
self.text_update()
self.img_update(HOUSE_IMAGE, self.texts)
# self.img_update(HOUSE_IMAGE, self.texts)
return True
else:
return False

View File

@ -11,16 +11,15 @@ class Numbers (pygame.sprite.Sprite):
self.rect = pygame.Rect(
x * CELL_SIZE, y * CELL_SIZE, CELL_SIZE, CELL_SIZE)
def img_update(self, image, texts, rotation=0, mirror=False):
def img_load(self, image, font_size, rotation=0, mirror=False):
img = Image.open(f"Resources/Images/{image}")
img = img.resize((CELL_SIZE, CELL_SIZE))
img = img.rotate(rotation)
img = img.transpose(method=Image.FLIP_LEFT_RIGHT) if mirror else img
draw = ImageDraw.Draw(img)
font = ImageFont.truetype(FONT, 16)
font = ImageFont.truetype(FONT, font_size)
return draw, font, img
for txt in texts:
draw.text(txt["position"], txt["quantity"],
txt["color"], font=font)
def img_save(self, draw, img):
data, size, mode = img.tobytes(), img.size, img.mode
self.image = pygame.image.frombuffer(data, size, mode)

View File

@ -1,11 +0,0 @@
import pygame
from config import CELL_SIZE
class Pond (pygame.sprite.Sprite):
def __init__(self, x, y):
pygame.sprite.Sprite.__init__(self)
self.rect = pygame.Rect(
x * CELL_SIZE, y * CELL_SIZE, CELL_SIZE, CELL_SIZE)
self.image = pygame.transform.scale(pygame.image.load(
"Resources/Images/pond.png"), (CELL_SIZE, CELL_SIZE))

26
models/Trash.py Normal file
View File

@ -0,0 +1,26 @@
import pygame
from config import CELL_SIZE
from PIL import Image
from PIL import ImageFont
from PIL import ImageDraw
from models.Numbers import Numbers
class Trash (Numbers):
def __init__(self, x, y, trash_type, image_name):
Numbers.__init__(self, x, y)
self.trash_type = trash_type
self.image_name = image_name
self.trash = 0
self.update()
def update(self):
draw, font, img = self.img_load(self.image_name, 32)
w, h = draw.textsize(str(self.trash), font=font)
draw.text(((CELL_SIZE - w) / 2, (CELL_SIZE - h)
* 2 / 3), str(self.trash), font=font)
self.img_save(draw, img)
def put_trash(self):
self.trash += 1
self.update()

View File

@ -1,25 +0,0 @@
import pygame
from config import CELL_SIZE, FONT, BLACK, BLUE, GREEN, YELLOW, TRASH_GLASS_IMAGE
from PIL import Image
from PIL import ImageFont
from PIL import ImageDraw
from models.Numbers import Numbers
class Trash_Glass (Numbers):
def __init__(self, x, y):
Numbers.__init__(self, x, y)
self.trash = 0
self.text_update()
self.img_update(TRASH_GLASS_IMAGE, self.texts)
def text_update(self):
self.texts = [
{"quantity": str(self.trash), "color": GREEN,
"position": (30, 30)},
]
def put_trash(self):
self.trash += 1
self.text_update()
self.img_update(TRASH_GLASS_IMAGE, self.texts)

View File

@ -1,25 +0,0 @@
import pygame
from config import CELL_SIZE, FONT, BLACK, BLUE, GREEN, YELLOW, TRASH_MIXED_IMAGE
from PIL import Image
from PIL import ImageFont
from PIL import ImageDraw
from models.Numbers import Numbers
class Trash_Mixed (Numbers):
def __init__(self, x, y):
Numbers.__init__(self, x, y)
self.trash = 0
self.text_update()
self.img_update(TRASH_MIXED_IMAGE, self.texts)
def text_update(self):
self.texts = [
{"quantity": str(self.trash), "color": BLACK,
"position": (30, 30)},
]
def put_trash(self):
self.trash += 1
self.text_update()
self.img_update(TRASH_MIXED_IMAGE, self.texts)

View File

@ -1,25 +0,0 @@
import pygame
from config import CELL_SIZE, FONT, BLACK, BLUE, GREEN, YELLOW, TRASH_PAPER_IMAGE
from PIL import Image
from PIL import ImageFont
from PIL import ImageDraw
from models.Numbers import Numbers
class Trash_Paper (Numbers):
def __init__(self, x, y):
Numbers.__init__(self, x, y)
self.trash = 0
self.text_update()
self.img_update(TRASH_PAPER_IMAGE, self.texts)
def text_update(self):
self.texts = [
{"quantity": str(self.trash), "color": BLUE,
"position": (30, 30)},
]
def put_trash(self):
self.trash += 1
self.text_update()
self.img_update(TRASH_PAPER_IMAGE, self.texts)

View File

@ -1,25 +0,0 @@
import pygame
from config import CELL_SIZE, FONT, BLACK, BLUE, GREEN, YELLOW, TRASH_PLASTIC_IMAGE
from PIL import Image
from PIL import ImageFont
from PIL import ImageDraw
from models.Numbers import Numbers
class Trash_Plastic (Numbers):
def __init__(self, x, y):
Numbers.__init__(self, x, y)
self.trash = 0
self.text_update()
self.img_update(TRASH_PLASTIC_IMAGE, self.texts)
def text_update(self):
self.texts = [
{"quantity": str(self.trash), "color": YELLOW,
"position": (30, 30)},
]
def put_trash(self):
self.trash += 1
self.text_update()
self.img_update(TRASH_PLASTIC_IMAGE, self.texts)

View File

@ -1,11 +0,0 @@
import pygame
from config import CELL_SIZE
class Tree (pygame.sprite.Sprite):
def __init__(self, x, y):
pygame.sprite.Sprite.__init__(self)
self.rect = pygame.Rect(
x * CELL_SIZE, y * CELL_SIZE, CELL_SIZE, CELL_SIZE)
self.image = pygame.transform.scale(pygame.image.load(
"Resources/Images/tree.jpg"), (CELL_SIZE, CELL_SIZE))