2023-03-26 18:19:10 +02:00
|
|
|
import os
|
|
|
|
|
2023-03-10 22:52:29 +01:00
|
|
|
import pygame
|
|
|
|
import random
|
2023-03-22 21:46:26 +01:00
|
|
|
import land
|
2023-03-21 23:55:52 +01:00
|
|
|
import tractor
|
2023-03-22 17:13:24 +01:00
|
|
|
import blocks
|
2023-03-13 10:36:49 +01:00
|
|
|
from pygame.locals import *
|
2023-03-10 22:52:29 +01:00
|
|
|
from datetime import datetime
|
|
|
|
|
2023-03-21 23:55:52 +01:00
|
|
|
|
|
|
|
class Game:
|
2023-03-13 10:36:49 +01:00
|
|
|
cell_size = 50
|
2023-03-22 21:09:00 +01:00
|
|
|
cell_number = 15 #horizontally
|
2023-03-26 18:19:10 +02:00
|
|
|
blocks_number = 15 # to-check sth is wrong: duplicate(?) and overlap
|
2023-03-22 21:09:00 +01:00
|
|
|
|
2023-03-10 22:52:29 +01:00
|
|
|
def __init__(self):
|
2023-03-22 21:09:00 +01:00
|
|
|
self.dead_leaf_body = []
|
|
|
|
self.green_leaf_body = []
|
|
|
|
self.stone_body = []
|
|
|
|
self.flower_body = []
|
2023-03-22 21:46:26 +01:00
|
|
|
self.dead_grass_body = []
|
|
|
|
self.grass_body = []
|
|
|
|
|
2023-03-26 18:19:10 +02:00
|
|
|
self.potato_field = []
|
|
|
|
|
|
|
|
|
2023-03-22 21:09:00 +01:00
|
|
|
self.entire_block = {}
|
|
|
|
|
2023-03-10 22:52:29 +01:00
|
|
|
pygame.init()
|
2023-03-22 17:13:24 +01:00
|
|
|
self.surface = pygame.display.set_mode((self.cell_size*self.cell_number, self.cell_size*self.cell_number)) # initialize a window
|
|
|
|
|
2023-03-22 21:46:26 +01:00
|
|
|
self.land = land.Land(self.cell_size, self.cell_number, self.grass_body)
|
2023-03-10 22:52:29 +01:00
|
|
|
|
2023-03-22 21:09:00 +01:00
|
|
|
self.blocks = blocks.Blocks(self.surface,self.cell_size)
|
2023-03-10 22:52:29 +01:00
|
|
|
|
2023-03-22 21:09:00 +01:00
|
|
|
self.blocks.locate_blocks(self.blocks_number, self.cell_number, self.dead_leaf_body)
|
|
|
|
self.blocks.locate_blocks(self.blocks_number, self.cell_number, self.stone_body)
|
|
|
|
self.blocks.locate_blocks(self.blocks_number, self.cell_number, self.flower_body)
|
2023-03-12 20:22:10 +01:00
|
|
|
|
2023-03-26 18:19:10 +02:00
|
|
|
self.potato = blocks.Blocks(self.surface, self.cell_size)
|
|
|
|
self.potato.locate_soil('black earth', 6, 1, [])
|
|
|
|
|
2023-03-21 23:55:52 +01:00
|
|
|
self.tractor = tractor.Tractor(self.surface, self.cell_size)
|
2023-03-13 10:36:49 +01:00
|
|
|
self.tractor.draw()
|
|
|
|
|
2023-03-10 22:52:29 +01:00
|
|
|
def run(self):
|
2023-03-26 18:19:10 +02:00
|
|
|
print(self.potato.get_soil_info().get_name())
|
|
|
|
print(self.potato.get_soil_info().get_acidity())
|
|
|
|
print(self.potato.get_soil_info().get_irrigation())
|
2023-03-10 22:52:29 +01:00
|
|
|
running = True
|
2023-03-13 10:36:49 +01:00
|
|
|
clock = pygame.time.Clock()
|
2023-03-10 22:52:29 +01:00
|
|
|
last_time = datetime.now()
|
|
|
|
|
|
|
|
while running:
|
2023-03-13 10:36:49 +01:00
|
|
|
clock.tick(60) # manual fps control not to overwork the computer
|
2023-03-10 22:52:29 +01:00
|
|
|
time_now = datetime.now()
|
|
|
|
|
|
|
|
for event in pygame.event.get():
|
|
|
|
if event.type == KEYDOWN:
|
|
|
|
if pygame.key.get_pressed()[K_ESCAPE]:
|
|
|
|
running = False
|
|
|
|
# in case we want to use keyboard
|
2023-03-13 10:36:49 +01:00
|
|
|
if pygame.key.get_pressed()[K_UP]:
|
2023-03-22 21:09:00 +01:00
|
|
|
self.tractor.move('up',self.cell_size, self.cell_number)
|
2023-03-13 10:36:49 +01:00
|
|
|
if pygame.key.get_pressed()[K_DOWN]:
|
2023-03-22 21:09:00 +01:00
|
|
|
self.tractor.move('down',self.cell_size, self.cell_number)
|
2023-03-13 10:36:49 +01:00
|
|
|
if pygame.key.get_pressed()[K_LEFT]:
|
2023-03-22 21:09:00 +01:00
|
|
|
self.tractor.move('left',self.cell_size, self.cell_number)
|
2023-03-13 10:36:49 +01:00
|
|
|
if pygame.key.get_pressed()[K_RIGHT]:
|
2023-03-22 21:09:00 +01:00
|
|
|
self.tractor.move('right',self.cell_size, self.cell_number)
|
|
|
|
if pygame.key.get_pressed()[K_SPACE]:
|
|
|
|
self.tractor.water(self.dead_leaf_body, self.green_leaf_body, self.cell_size)
|
2023-03-22 21:46:26 +01:00
|
|
|
#self.tractor.water(self.grass_body, self.dead_grass_body, self.cell_size)
|
|
|
|
|
2023-03-10 22:52:29 +01:00
|
|
|
elif event.type == QUIT:
|
|
|
|
running = False
|
|
|
|
|
2023-03-13 14:38:22 +01:00
|
|
|
self.surface.fill((140, 203, 97)) # background color
|
2023-03-21 23:55:52 +01:00
|
|
|
|
2023-03-22 21:46:26 +01:00
|
|
|
self.land.place_grass(self.surface, self.cell_number, self.cell_size, self.grass_body, 'good')
|
|
|
|
#self.land.place_grass(self.surface, self.cell_number, self.cell_size, self.dead_grass_body, 'bad')
|
2023-03-22 17:13:24 +01:00
|
|
|
|
2023-03-22 21:09:00 +01:00
|
|
|
self.blocks.place_blocks(self.surface, self.cell_size, self.dead_leaf_body, 'leaf')
|
|
|
|
self.blocks.place_blocks(self.surface, self.cell_size, self.green_leaf_body, 'alive')
|
|
|
|
self.blocks.place_blocks(self.surface, self.cell_size, self.stone_body, 'stone')
|
|
|
|
self.blocks.place_blocks(self.surface, self.cell_size, self.flower_body, 'flower')
|
2023-03-22 17:13:24 +01:00
|
|
|
|
|
|
|
|
2023-03-13 10:36:49 +01:00
|
|
|
self.tractor.draw()
|
2023-03-13 14:38:22 +01:00
|
|
|
pygame.display.update()
|
2023-03-13 10:36:49 +01:00
|
|
|
|
|
|
|
|
2023-03-21 23:55:52 +01:00
|
|
|
# if (time_now - last_time).total_seconds() > 1: # tractor moves every 1 sec
|
|
|
|
#last_time = datetime.now()
|
2023-03-13 10:36:49 +01:00
|
|
|
#self.tractor.walk()
|
|
|
|
#print(f'x, y = ({int(self.tractor.x / 50)}, {int(self.tractor.y / 50)})')
|
2023-03-10 22:52:29 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
game = Game()
|
|
|
|
game.run()
|