feat(logs): print out growth modifier based on tile neighbours
This commit is contained in:
parent
5baf1c3a3d
commit
505926461e
@ -1,6 +1,6 @@
|
|||||||
import pygame
|
import pygame
|
||||||
import os
|
import os
|
||||||
from kb import ile_podlac
|
from kb import ile_podlac, multi_sasiedzi
|
||||||
from tile import Tile
|
from tile import Tile
|
||||||
from config import TILE_SIZE
|
from config import TILE_SIZE
|
||||||
|
|
||||||
@ -26,24 +26,16 @@ class Tractor(pygame.sprite.Sprite):
|
|||||||
def move(self, direction):
|
def move(self, direction):
|
||||||
if direction == "up" and self.rect.y > 0:
|
if direction == "up" and self.rect.y > 0:
|
||||||
self.rect.y -= TILE_SIZE
|
self.rect.y -= TILE_SIZE
|
||||||
self.print_tile_type()
|
self.log_info()
|
||||||
elif direction == "down" and self.rect.y < 15 * TILE_SIZE:
|
elif direction == "down" and self.rect.y < 15 * TILE_SIZE:
|
||||||
self.rect.y += TILE_SIZE
|
self.rect.y += TILE_SIZE
|
||||||
self.print_tile_type()
|
self.log_info()
|
||||||
elif direction == "left" and self.rect.x > 0:
|
elif direction == "left" and self.rect.x > 0:
|
||||||
self.rect.x -= TILE_SIZE
|
self.rect.x -= TILE_SIZE
|
||||||
self.print_tile_type()
|
self.log_info()
|
||||||
elif direction == "right" and self.rect.x < 15 * TILE_SIZE:
|
elif direction == "right" and self.rect.x < 15 * TILE_SIZE:
|
||||||
self.rect.x += TILE_SIZE
|
self.rect.x += TILE_SIZE
|
||||||
self.print_tile_type()
|
self.log_info()
|
||||||
|
|
||||||
curent_tile = self.get_current_tile()
|
|
||||||
water_needed = ile_podlac(curent_tile.type, curent_tile.faza)[0]['Woda']
|
|
||||||
if self.water >= water_needed:
|
|
||||||
print(f"💦 watered {curent_tile.type} with {water_needed} liters\n")
|
|
||||||
self.water -= water_needed
|
|
||||||
else:
|
|
||||||
print(f"❗ {water_needed - self.water} more litres of water needed to water {curent_tile.type}\n")
|
|
||||||
|
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
@ -61,11 +53,28 @@ class Tractor(pygame.sprite.Sprite):
|
|||||||
print(f"💧 replenished water level: {self.water} litres\n")
|
print(f"💧 replenished water level: {self.water} litres\n")
|
||||||
|
|
||||||
|
|
||||||
def print_tile_type(self):
|
def log_info(self):
|
||||||
|
# print on what tile type the tractor is on
|
||||||
x = self.rect.x // TILE_SIZE
|
x = self.rect.x // TILE_SIZE
|
||||||
y = self.rect.y // TILE_SIZE
|
y = self.rect.y // TILE_SIZE
|
||||||
tile_type = self.field.tiles.sprites()[y * 16 + x].type
|
tile_type = self.field.tiles.sprites()[y * 16 + x].type
|
||||||
print(f"🧭 the tractor is on a {tile_type} tile")
|
print(f"🧭 the tractor is on a {tile_type} tile")
|
||||||
|
|
||||||
|
# print if the tile can be watered
|
||||||
|
current_tile = self.get_current_tile()
|
||||||
|
water_needed = ile_podlac(current_tile.type, current_tile.faza)[0]['Woda']
|
||||||
|
if self.water >= water_needed:
|
||||||
|
print(f"💦 watered {current_tile.type} with {water_needed} liters")
|
||||||
|
self.water -= water_needed
|
||||||
|
else:
|
||||||
|
print(f"❗ {water_needed - self.water} more litres of water needed to water {current_tile.type}")
|
||||||
|
|
||||||
|
# print out what are the neighbors of the current tile and their effect on growth
|
||||||
|
neighbors = self.get_neighbors_list()
|
||||||
|
modifier = multi_sasiedzi(current_tile.type, neighbors)[0]['Mul']
|
||||||
|
print(f"🌱 the growth modifier for {current_tile.type} on this tile is ~{modifier:.2f} based on its neighbors: {', '.join(neighbors)}")
|
||||||
|
|
||||||
|
print() # empty line at end of log statement
|
||||||
|
|
||||||
|
|
||||||
def get_current_tile(self):
|
def get_current_tile(self):
|
||||||
@ -73,3 +82,22 @@ class Tractor(pygame.sprite.Sprite):
|
|||||||
y = self.rect.y // TILE_SIZE
|
y = self.rect.y // TILE_SIZE
|
||||||
current_tile = self.field.tiles.sprites()[y * 16 + x]
|
current_tile = self.field.tiles.sprites()[y * 16 + x]
|
||||||
return current_tile
|
return current_tile
|
||||||
|
|
||||||
|
|
||||||
|
def get_neighbors_list(self):
|
||||||
|
x = self.rect.x // TILE_SIZE
|
||||||
|
y = self.rect.y // TILE_SIZE
|
||||||
|
neighbors = []
|
||||||
|
self.field.tiles.sprites()[y * 16 + x].type
|
||||||
|
|
||||||
|
if x > 0:
|
||||||
|
neighbors.append(self.field.tiles.sprites()[y * 16 + x - 1].type)
|
||||||
|
if x < 15:
|
||||||
|
neighbors.append(self.field.tiles.sprites()[y * 16 + x + 1].type)
|
||||||
|
if y > 0:
|
||||||
|
neighbors.append(self.field.tiles.sprites()[(y - 1) * 16 + x].type)
|
||||||
|
if y < 15:
|
||||||
|
neighbors.append(self.field.tiles.sprites()[(y + 1) * 16 + x].type)
|
||||||
|
|
||||||
|
return neighbors
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user