Traktor/source/main.py

74 lines
2.2 KiB
Python
Raw Normal View History

2024-03-07 18:01:12 +01:00
import pygame
2024-03-25 01:03:25 +01:00
import time
import random
2024-03-07 18:01:12 +01:00
2024-04-10 01:52:13 +02:00
from area.constants import WIDTH, HEIGHT, TILE_SIZE, GREY
2024-03-07 18:01:12 +01:00
from area.field import drawWindow
2024-03-25 01:03:25 +01:00
from area.tractor import Tractor
2024-04-10 01:52:13 +02:00
from area.field import tiles, fieldX, fieldY
2024-04-14 14:29:11 +02:00
from area.field import get_tile_coordinates
2024-03-25 01:03:25 +01:00
from ground import Dirt
from plant import Plant
2024-04-14 14:29:11 +02:00
from bfs import graphsearch, Istate, succ
2024-03-07 18:01:12 +01:00
WIN = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption('Intelligent tractor')
2024-04-10 01:52:13 +02:00
trail = pygame.image.load("resources/images/background.jpg").convert_alpha()
trail = pygame.transform.scale(trail, (TILE_SIZE, TILE_SIZE))
2024-03-07 18:01:12 +01:00
def main():
run = True
window = drawWindow(WIN)
pygame.display.update()
2024-04-09 15:02:58 +02:00
2024-04-14 14:29:11 +02:00
#getting coordinates of a certain tile - test:
2024-04-14 15:05:20 +02:00
tile_index=22
2024-04-14 14:29:11 +02:00
tile_x, tile_y = get_tile_coordinates(tile_index)
if tile_x is not None and tile_y is not None:
print(f"Coordinates of tile {tile_index} are: ({tile_x}, {tile_y})")
else: print("Such tile does not exist")
istate = Istate(170, 100, 2)
goaltest = []
goaltest.append(tile_x)
goaltest.append(tile_y)
2024-04-09 15:02:58 +02:00
2024-04-14 14:29:11 +02:00
print(graphsearch(istate, succ, goaltest))
#main loop:
2024-03-07 18:01:12 +01:00
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
2024-04-14 14:29:11 +02:00
#small test of work_on_field method:
2024-04-10 01:52:13 +02:00
time.sleep(1)
2024-03-25 01:03:25 +01:00
tile1 = tiles[0]
p1 = Plant('wheat', 'cereal', random.randint(1,100), random.randint(1,100), random.randint(1,100))
d1 = Dirt(random.randint(1, 100), random.randint(1,100))
d1.pests_and_weeds()
tile1.ground=d1
2024-04-09 15:02:58 +02:00
2024-04-10 01:52:13 +02:00
tractor = Tractor(0*TILE_SIZE, 0*TILE_SIZE, 1)
2024-04-09 15:02:58 +02:00
tractor.rotate_to_right()
2024-04-10 01:52:13 +02:00
tractor.rect.x += fieldX
tractor.rect.y += fieldY
2024-04-09 15:02:58 +02:00
tractor.draw_tractor(WIN)
2024-04-10 01:52:13 +02:00
time.sleep(1)
for _ in range(5):
WIN.blit(trail, (tractor.rect.x, tractor.rect.y, TILE_SIZE, TILE_SIZE))
tractor.move()
tractor.draw_tractor(WIN)
pygame.display.flip()
tractor.work_on_field(tile1, d1, p1)
time.sleep(2)
print("\n")
2024-03-25 01:03:25 +01:00
2024-04-09 15:02:58 +02:00
# in loop move tractor:
2024-03-07 18:01:12 +01:00
main()