Dodano zbieranie smieci
This commit is contained in:
parent
6168a2ed8f
commit
206a101d17
@ -1,10 +1,24 @@
|
|||||||
|
|
||||||
class Container():
|
class Container():
|
||||||
def __init__( self, max, y = 0, g = 0, b = 0 ):
|
def __init__(self, max, y=0, g=0, b=0):
|
||||||
self.y, self.g, self.b = y, g, b
|
self.y, self.g, self.b = y, g, b
|
||||||
|
self.max = max
|
||||||
|
|
||||||
def empty( self ):
|
def empty(self):
|
||||||
self.y, self.g, self.b = 0,0,0
|
self.y, self.g, self.b = 0, 0, 0
|
||||||
|
|
||||||
def status( self ):
|
def status(self):
|
||||||
return [self.y, self.g, self.b]
|
return [self.y, self.g, self.b]
|
||||||
|
|
||||||
|
def add(self, trash):
|
||||||
|
my_trash = [self.y, self.g, self.b]
|
||||||
|
leftovers = [0, 0, 0]
|
||||||
|
for i in range(0, len(trash)):
|
||||||
|
while(my_trash[i] < self.max and trash[i] > 0):
|
||||||
|
my_trash[i] += 1
|
||||||
|
trash[i] -= 1
|
||||||
|
self.y, self.g, self.b = my_trash
|
||||||
|
result = [0, 0, 0]
|
||||||
|
for i in range(0, len(trash)):
|
||||||
|
result[i] = trash[i] - leftovers[i]
|
||||||
|
|
||||||
|
return result
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
from DataModels.Cell import Cell
|
from DataModels.Cell import Cell
|
||||||
from DataModels.Road import Road
|
from DataModels.Road import Road
|
||||||
|
from DataModels.House import House
|
||||||
from config import GRID_WIDTH, GRID_HEIGHT
|
from config import GRID_WIDTH, GRID_HEIGHT
|
||||||
|
|
||||||
|
|
||||||
@ -16,5 +17,20 @@ class GC(Cell):
|
|||||||
"up": (x, y - 1) if y - 1 >= 0 and type(environment[x][y - 1]) == Road else (x, y)
|
"up": (x, y - 1) if y - 1 >= 0 and type(environment[x][y - 1]) == Road else (x, y)
|
||||||
}
|
}
|
||||||
self.x, self.y = movement[direction]
|
self.x, self.y = movement[direction]
|
||||||
print(self.x, self.y)
|
|
||||||
self.update_rect(self.x, self.y)
|
self.update_rect(self.x, self.y)
|
||||||
|
|
||||||
|
def collect(self, enviromnent):
|
||||||
|
print('collect')
|
||||||
|
x, y = [self.x, self.y]
|
||||||
|
coordinates = [(x, y - 1), (x, y + 1), (x - 1, y), (x + 1, y)]
|
||||||
|
|
||||||
|
for coordinate in coordinates:
|
||||||
|
try:
|
||||||
|
item = enviromnent[coordinate[0]][coordinate[1]]
|
||||||
|
except:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if(type(item) == House):
|
||||||
|
item.return_trash(self)
|
||||||
|
|
||||||
|
self.update_image()
|
||||||
|
@ -1,6 +1,12 @@
|
|||||||
from DataModels.Cell import Cell
|
from DataModels.Cell import Cell
|
||||||
|
|
||||||
class House( Cell ):
|
|
||||||
def __init__( self, x, y, max_rubbish, yellow = 0, green = 0, blue = 0 ):
|
class House(Cell):
|
||||||
Cell.__init__( self, x, y, max_rubbish, yellow, green, blue )
|
def __init__(self, x, y, max_rubbish, yellow=0, green=0, blue=0):
|
||||||
|
Cell.__init__(self, x, y, max_rubbish, yellow, green, blue)
|
||||||
|
|
||||||
|
def return_trash(self, collector):
|
||||||
|
self.container.y, self.container.g, self.container.b = collector.container.add(
|
||||||
|
[self.container.y, self.container.g, self.container.b])
|
||||||
|
print(collector.container.status())
|
||||||
|
self.update_image()
|
||||||
|
2
main.py
2
main.py
@ -90,6 +90,8 @@ while True:
|
|||||||
gc.move("left", map_objects)
|
gc.move("left", map_objects)
|
||||||
elif event.key == pygame.K_RIGHT:
|
elif event.key == pygame.K_RIGHT:
|
||||||
gc.move("right", map_objects)
|
gc.move("right", map_objects)
|
||||||
|
elif event.key == pygame.K_SPACE:
|
||||||
|
gc.collect(map_objects)
|
||||||
|
|
||||||
pygame_sprites.update()
|
pygame_sprites.update()
|
||||||
pygame_sprites.draw(GAME_WINDOW)
|
pygame_sprites.draw(GAME_WINDOW)
|
||||||
|
Loading…
Reference in New Issue
Block a user