Compare commits
4 Commits
7c30177bf1
...
5baf1c3a3d
Author | SHA1 | Date | |
---|---|---|---|
![]() |
5baf1c3a3d | ||
![]() |
2658f77669 | ||
![]() |
e4aa771022 | ||
![]() |
c99e738034 |
6
src/config.py
Normal file
6
src/config.py
Normal file
@ -0,0 +1,6 @@
|
||||
import os
|
||||
from dotenv import find_dotenv, load_dotenv
|
||||
|
||||
# you can set TILE_SIZE in the .env file to adjust the window size
|
||||
load_dotenv(find_dotenv())
|
||||
TILE_SIZE = int(os.getenv("TILE_SIZE"))
|
@ -9,6 +9,7 @@ class Field:
|
||||
self.tiles.add(Tile(x, 'grass', self))
|
||||
self.tractor = Tractor(self)
|
||||
|
||||
|
||||
def draw(self, surface):
|
||||
self.tiles.draw(surface)
|
||||
self.tractor.draw(surface)
|
||||
self.tractor.draw(surface)
|
||||
|
11
src/main.py
11
src/main.py
@ -2,16 +2,17 @@ import sys
|
||||
import pygame
|
||||
from field import Field
|
||||
import os
|
||||
from dotenv import find_dotenv, load_dotenv
|
||||
from config import TILE_SIZE
|
||||
|
||||
if __name__ == "__main__":
|
||||
pygame.init()
|
||||
WHITE = (255, 255, 255)
|
||||
# loading TILE_SIZE to adjust window size
|
||||
load_dotenv(find_dotenv())
|
||||
WINDOW_SIZE = int(os.getenv("TILE_SIZE")) * 16
|
||||
|
||||
WINDOW_SIZE = TILE_SIZE * 16
|
||||
screen = pygame.display.set_mode((WINDOW_SIZE, WINDOW_SIZE))
|
||||
|
||||
field = Field()
|
||||
|
||||
running = True
|
||||
while running:
|
||||
for event in pygame.event.get():
|
||||
@ -23,4 +24,4 @@ if __name__ == "__main__":
|
||||
field.draw(screen)
|
||||
|
||||
pygame.display.flip()
|
||||
pygame.time.Clock().tick(10)
|
||||
pygame.time.Clock().tick(10)
|
||||
|
14
src/tile.py
14
src/tile.py
@ -1,11 +1,12 @@
|
||||
import os
|
||||
import pygame
|
||||
from dotenv import find_dotenv, load_dotenv
|
||||
from kb import tractor_kb
|
||||
import pytholog as pl
|
||||
import random
|
||||
from config import TILE_SIZE
|
||||
|
||||
class Tile(pygame.sprite.Sprite):
|
||||
|
||||
def __init__(self, id, field, type):
|
||||
super().__init__()
|
||||
self.id = id
|
||||
@ -20,24 +21,17 @@ class Tile(pygame.sprite.Sprite):
|
||||
|
||||
self.faza = 'posadzono'
|
||||
|
||||
# you can set TILE_SIZE in the .env file to adjust the window size
|
||||
load_dotenv(find_dotenv())
|
||||
TILE_SIZE = int(os.getenv("TILE_SIZE"))
|
||||
self.rect = self.image.get_rect()
|
||||
self.rect.topleft = (x * TILE_SIZE, y * TILE_SIZE)
|
||||
|
||||
|
||||
def draw(self, surface):
|
||||
self.tiles.draw(surface)
|
||||
|
||||
|
||||
def set_type(self, type):
|
||||
self.type = type
|
||||
# if self.type == 'grass':
|
||||
# self.image = pygame.image.load("images/grass.png").convert()
|
||||
self.image = pygame.image.load("images/grass.png").convert()
|
||||
|
||||
# you can set TILE_SIZE in the .env file to adjust the window size
|
||||
load_dotenv(find_dotenv())
|
||||
TILE_SIZE = int(os.getenv("TILE_SIZE"))
|
||||
self.image = pygame.transform.scale(self.image, (TILE_SIZE, TILE_SIZE))
|
||||
|
||||
|
||||
|
@ -1,32 +1,29 @@
|
||||
import pygame
|
||||
import os
|
||||
from dotenv import find_dotenv, load_dotenv
|
||||
from kb import ile_podlac
|
||||
from tile import Tile
|
||||
from config import TILE_SIZE
|
||||
|
||||
class Tractor(pygame.sprite.Sprite):
|
||||
def __init__(self, field):
|
||||
super().__init__
|
||||
self.field = field
|
||||
|
||||
self.image = pygame.image.load('images/tractor.png').convert_alpha()
|
||||
# you can set TILE_SIZE in the .env to adjust window size
|
||||
load_dotenv(find_dotenv())
|
||||
TILE_SIZE = int(os.getenv("TILE_SIZE"))
|
||||
self.image = pygame.transform.scale(self.image, (TILE_SIZE, TILE_SIZE))
|
||||
self.rect = self.image.get_rect()
|
||||
|
||||
x, y = 0, 0
|
||||
self.rect.topleft = (x, y)
|
||||
|
||||
self.water = 200
|
||||
self.water = 50
|
||||
|
||||
|
||||
def draw(self, surface):
|
||||
surface.blit(self.image, self.rect)
|
||||
|
||||
def move(self, direction):
|
||||
# you can set TILE_SIZE in the .env to adjust window size
|
||||
load_dotenv(find_dotenv())
|
||||
TILE_SIZE = int(os.getenv("TILE_SIZE"))
|
||||
|
||||
def move(self, direction):
|
||||
if direction == "up" and self.rect.y > 0:
|
||||
self.rect.y -= TILE_SIZE
|
||||
self.print_tile_type()
|
||||
@ -43,10 +40,11 @@ class Tractor(pygame.sprite.Sprite):
|
||||
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")
|
||||
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")
|
||||
print(f"❗ {water_needed - self.water} more litres of water needed to water {curent_tile.type}\n")
|
||||
|
||||
|
||||
def update(self):
|
||||
keys = pygame.key.get_pressed()
|
||||
@ -58,20 +56,19 @@ class Tractor(pygame.sprite.Sprite):
|
||||
self.move('up')
|
||||
if keys[pygame.K_DOWN]:
|
||||
self.move('down')
|
||||
if keys[pygame.K_r]:
|
||||
self.water = 50
|
||||
print(f"💧 replenished water level: {self.water} litres\n")
|
||||
|
||||
|
||||
def print_tile_type(self):
|
||||
load_dotenv(find_dotenv())
|
||||
TILE_SIZE = int(os.getenv("TILE_SIZE"))
|
||||
|
||||
x = self.rect.x // TILE_SIZE
|
||||
y = self.rect.y // TILE_SIZE
|
||||
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")
|
||||
|
||||
|
||||
def get_current_tile(self):
|
||||
load_dotenv(find_dotenv())
|
||||
TILE_SIZE = int(os.getenv("TILE_SIZE"))
|
||||
|
||||
x = self.rect.x // TILE_SIZE
|
||||
y = self.rect.y // TILE_SIZE
|
||||
current_tile = self.field.tiles.sprites()[y * 16 + x]
|
||||
|
Loading…
Reference in New Issue
Block a user