2024-03-08 20:21:45 +01:00
import pygame
2024-03-10 15:03:56 +01:00
import Slot
2024-03-11 13:24:12 +01:00
import Tractor
2024-03-10 15:03:56 +01:00
import random
import time
2024-03-11 21:24:16 +01:00
import displayControler as dCon
2024-03-08 19:58:18 +01:00
2024-03-11 13:24:12 +01:00
2024-03-08 20:21:45 +01:00
pygame . init ( )
2024-03-08 19:58:18 +01:00
2024-03-10 15:03:56 +01:00
BLACK = ( 0 , 0 , 0 )
BROWN = ( 139 , 69 , 19 )
WHITE = ( 255 , 255 , 255 )
RED = ( 255 , 0 , 0 )
GREEN = ( 0 , 255 , 0 )
2024-03-11 21:24:16 +01:00
screen = pygame . display . set_mode ( ( dCon . getScreenWidth ( ) , dCon . getScreenHeihgt ( ) ) )
2024-03-08 20:21:45 +01:00
screen . fill ( WHITE )
pygame . display . update ( )
2024-03-08 19:58:18 +01:00
2024-03-10 15:03:56 +01:00
2024-03-11 13:24:12 +01:00
#Tractor creation
traktor = Tractor . Tractor ( 0 , 0 , screen )
2024-03-10 15:03:56 +01:00
SLOT_DICT = { } #Slot are stored in dictionary with key being a Tuple of x and y coordinates so top left slot key is (0,0) and value is slot object
""" #Draw grid and tractor (old one)
def draw_grid ( ) :
for x in range ( 0 , 8 ) :
pygame . draw . line ( screen , BLACK , ( x * CUBE_SIZE , 0 ) , ( x * CUBE_SIZE , HEIGHT ) ) #We got 8 lines in Y axis so to draw them we use x from range <0,7) to make slot manage easier
2024-03-11 10:18:52 +01:00
for y in range ( 0 , 4 ) :
pygame . draw . line ( screen , BLACK , ( 0 , y * CUBE_SIZE ) , ( WIDTH , y * CUBE_SIZE ) ) #We got 4 lines in X axis so to draw them we use y from range <0,4) to make slot manage easier
2024-03-08 19:58:18 +01:00
2024-03-08 20:21:45 +01:00
# Draw tractor
2024-03-10 15:03:56 +01:00
tractor_image = pygame . image . load ( ' images/traktor.png ' )
tractor_image = pygame . transform . scale ( tractor_image , ( CUBE_SIZE , CUBE_SIZE ) )
screen . blit ( tractor_image , ( CUBE_SIZE - 128 , CUBE_SIZE - 128 ) ) """
2024-03-11 13:24:12 +01:00
2024-03-10 15:03:56 +01:00
#Draw grid and tractor (new one)
def draw_grid ( ) :
2024-03-11 21:24:16 +01:00
for x in range ( 0 , dCon . NUM_X ) : #We got 8 cubes in X axis so we use for from 0 to 7 do draw them all
for y in range ( 0 , dCon . NUM_Y ) : #We got 4 cubes in Y axis so we use for from 0 to 3 to draw them all
2024-03-11 10:18:52 +01:00
new_slot = Slot . Slot ( x , y , BROWN , screen ) #Creation of empty slot
SLOT_DICT [ ( x , y ) ] = new_slot #Adding slots to dict
2024-03-10 15:03:56 +01:00
for entity in SLOT_DICT :
2024-03-11 13:24:12 +01:00
SLOT_DICT [ entity ] . draw ( )
traktor . draw_tractor ( )
2024-03-10 15:03:56 +01:00
2024-03-11 10:18:52 +01:00
def change_color_of_slot ( coordinates , color ) : #Coordinates must be tuple (x,y) x from range 0,7 and y in range 0,3 (left top slot has cord (0,0) ), color has to be from defined or custom in RGB value (R,G,B)
2024-03-10 15:03:56 +01:00
SLOT_DICT [ coordinates ] . color_change ( color )
def random_color ( ) :
x = random . randint ( 0 , 3 )
switcher = { 0 : BROWN ,
1 : GREEN ,
2 : RED ,
3 : WHITE }
return switcher [ x ]
2024-03-08 19:58:18 +01:00
2024-03-11 10:18:52 +01:00
#Demo purpose, can be reused for photos of crops in the future(?)
2024-03-10 15:03:56 +01:00
def randomize_colors ( ) :
font = pygame . font . Font ( ' freesansbold.ttf ' , 32 )
text = font . render ( ' Randomizing crops ' , True , BLACK , WHITE )
textRect = text . get_rect ( )
2024-03-11 21:24:16 +01:00
textRect . center = ( dCon . getScreenWidth ( ) / / 2 , dCon . getScreenHeihgt ( ) / / 2 )
2024-03-10 15:03:56 +01:00
screen . blit ( text , textRect )
pygame . display . update ( )
time . sleep ( 3 )
for coordinates in SLOT_DICT :
SLOT_DICT [ coordinates ] . color_change ( random_color ( ) )
2024-03-11 13:24:12 +01:00
traktor . draw_tractor ( )
2024-03-08 20:21:45 +01:00
2024-03-11 10:18:52 +01:00
def init_demo ( ) : #Demo purpose
2024-03-10 15:03:56 +01:00
draw_grid ( )
time . sleep ( 2 )
randomize_colors ( )
2024-03-11 13:31:13 +01:00
2024-03-11 13:24:12 +01:00
def demo_move ( ) :
SLOT_DICT [ ( traktor . x_axis , traktor . y_axis ) ] . draw ( )
traktor . random_move ( )
2024-03-10 15:03:56 +01:00
init_demo ( )
2024-03-08 20:21:45 +01:00
while True :
2024-03-11 13:24:12 +01:00
time . sleep ( 1 )
demo_move ( )
2024-03-08 20:21:45 +01:00
for event in pygame . event . get ( ) :
if event . type == pygame . QUIT :
quit ( )