dodane grafiki
36
Main/drawUI.py
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
from Main.constants import *
|
||||||
|
from Main.images import *
|
||||||
|
import pygame
|
||||||
|
|
||||||
|
|
||||||
|
def drawUI(board, display, tractor_horizontal_index, tractor_vertical_index):
|
||||||
|
display.fill(WHITE)
|
||||||
|
makeField(board, display)
|
||||||
|
drawTractor(display, tractor_right, tractor_horizontal_index, tractor_vertical_index)
|
||||||
|
pygame.display.update()
|
||||||
|
|
||||||
|
|
||||||
|
def makeField(board, screen: pygame.Surface):
|
||||||
|
for i in range(int(HORIZONTAL_TILES_NUMBER)):
|
||||||
|
for j in range(int(VERTICAL_TILES_NUMBER)):
|
||||||
|
field = board[i][j]
|
||||||
|
|
||||||
|
pos_x = i * TILE_SIZE + TILE_SIZE // 2
|
||||||
|
pos_y = j * TILE_SIZE + TILE_SIZE // 2
|
||||||
|
|
||||||
|
if field.state == 0:
|
||||||
|
do_podlania_rect.center = (pos_x, pos_y)
|
||||||
|
screen.blit(do_podlania, do_podlania_rect)
|
||||||
|
elif field.state == 1:
|
||||||
|
do_zaorania_rect.center = (pos_x, pos_y)
|
||||||
|
screen.blit(do_zaorania, do_zaorania_rect)
|
||||||
|
elif field.state == 2:
|
||||||
|
do_zasiania_rect.center = (pos_x, pos_y)
|
||||||
|
screen.blit(do_zasiania, do_zasiania_rect)
|
||||||
|
elif field.state == 3:
|
||||||
|
do_zebrania_rect.center = (pos_x, pos_y)
|
||||||
|
screen.blit(do_zebrania, do_zebrania_rect)
|
||||||
|
|
||||||
|
|
||||||
|
def drawTractor(screen: pygame.Surface, tractor_image, tractor_horizontal_index, tractor_vertical_index):
|
||||||
|
screen.blit(tractor_image, (tractor_horizontal_index * TILE_SIZE,tractor_vertical_index * TILE_SIZE))
|
@ -1,7 +1,6 @@
|
|||||||
from Main.constants import *
|
from Main.drawUI import *
|
||||||
import pygame
|
import pygame
|
||||||
|
|
||||||
|
|
||||||
def cruiseControl(cruiseControl, horizontal_change, vertical_change, tractor_horizontal_index, tractor_vertical_index):
|
def cruiseControl(cruiseControl, horizontal_change, vertical_change, tractor_horizontal_index, tractor_vertical_index):
|
||||||
if not cruiseControl:
|
if not cruiseControl:
|
||||||
horizontal_change = 0
|
horizontal_change = 0
|
||||||
@ -18,6 +17,7 @@ def manualTurning(event, tractor_horizontal_index, tractor_vertical_index, horiz
|
|||||||
if event.key == pygame.K_LEFT and tractor_horizontal_index > 0:
|
if event.key == pygame.K_LEFT and tractor_horizontal_index > 0:
|
||||||
vertical_change = 0
|
vertical_change = 0
|
||||||
horizontal_change = -1
|
horizontal_change = -1
|
||||||
|
|
||||||
elif event.key == pygame.K_RIGHT and tractor_horizontal_index < HORIZONTAL_TILES_NUMBER - 1:
|
elif event.key == pygame.K_RIGHT and tractor_horizontal_index < HORIZONTAL_TILES_NUMBER - 1:
|
||||||
horizontal_change = 1
|
horizontal_change = 1
|
||||||
vertical_change = 0
|
vertical_change = 0
|
35
Main/images.py
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
import pygame
|
||||||
|
from constants import *
|
||||||
|
|
||||||
|
tractor_up_image = pygame.image.load("resources/traktor_up.png")
|
||||||
|
tractor_up = pygame.transform.scale(tractor_up_image, (TILE_SIZE, TILE_SIZE))
|
||||||
|
|
||||||
|
tractor_right_image = pygame.image.load("resources/traktor_right.png")
|
||||||
|
tractor_right = pygame.transform.scale(tractor_right_image, (TILE_SIZE, TILE_SIZE))
|
||||||
|
|
||||||
|
tractor_down_image = pygame.image.load("resources/traktor_down.png")
|
||||||
|
tractor_down = pygame.transform.scale(tractor_down_image, (TILE_SIZE, TILE_SIZE))
|
||||||
|
|
||||||
|
tractor_left_image = pygame.image.load("resources/traktor_left.png")
|
||||||
|
tractor_left = pygame.transform.scale(tractor_left_image, (TILE_SIZE, TILE_SIZE))
|
||||||
|
|
||||||
|
do_podlania_image = pygame.image.load("resources/do_podlania.png")
|
||||||
|
do_podlania = pygame.transform.scale(do_podlania_image, (TILE_SIZE, TILE_SIZE))
|
||||||
|
|
||||||
|
do_zaorania_image = pygame.image.load("resources/do_zaorania.png")
|
||||||
|
do_zaorania = pygame.transform.scale(do_zaorania_image, (TILE_SIZE, TILE_SIZE))
|
||||||
|
|
||||||
|
do_zasiania_image = pygame.image.load("resources/do_zasiania.png")
|
||||||
|
do_zasiania = pygame.transform.scale(do_zasiania_image, (TILE_SIZE, TILE_SIZE))
|
||||||
|
|
||||||
|
do_zebrania_image = pygame.image.load("resources/do_zebrania.png")
|
||||||
|
do_zebrania = pygame.transform.scale(do_zebrania_image, (TILE_SIZE, TILE_SIZE))
|
||||||
|
|
||||||
|
tractor_up_rect = tractor_up.get_rect()
|
||||||
|
tractor_right_rect = tractor_right.get_rect()
|
||||||
|
tractor_down_rect = tractor_down.get_rect()
|
||||||
|
tractor_left_rect = tractor_left.get_rect()
|
||||||
|
do_podlania_rect = do_podlania.get_rect()
|
||||||
|
do_zaorania_rect = do_zaorania.get_rect()
|
||||||
|
do_zasiania_rect = do_zasiania.get_rect()
|
||||||
|
do_zebrania_rect = do_zebrania.get_rect()
|
BIN
Main/resources/do_podlania.png
Normal file
After Width: | Height: | Size: 15 KiB |
BIN
Main/resources/do_zaorania.png
Normal file
After Width: | Height: | Size: 8.2 KiB |
BIN
Main/resources/do_zasiania.png
Normal file
After Width: | Height: | Size: 11 KiB |
BIN
Main/resources/do_zebrania.png
Normal file
After Width: | Height: | Size: 29 KiB |
BIN
Main/resources/traktor_down.png
Normal file
After Width: | Height: | Size: 144 KiB |
BIN
Main/resources/traktor_left.png
Normal file
After Width: | Height: | Size: 140 KiB |
BIN
Main/resources/traktor_right.png
Normal file
After Width: | Height: | Size: 140 KiB |
BIN
Main/resources/traktor_up.png
Normal file
After Width: | Height: | Size: 144 KiB |
35
drawUI.py
@ -1,35 +0,0 @@
|
|||||||
from Main.constants import *
|
|
||||||
import pygame
|
|
||||||
|
|
||||||
|
|
||||||
def drawUI(board, display, tractor_horizontal_index, tractor_vertical_index):
|
|
||||||
display.fill(WHITE)
|
|
||||||
makeField(board, display)
|
|
||||||
drawTractor(display, tractor_horizontal_index, tractor_vertical_index)
|
|
||||||
pygame.display.update()
|
|
||||||
|
|
||||||
|
|
||||||
def makeField(board, display):
|
|
||||||
color = BLACK
|
|
||||||
for i in range(int(HORIZONTAL_TILES_NUMBER)):
|
|
||||||
for j in range(int(VERTICAL_TILES_NUMBER)):
|
|
||||||
field = board[i][j]
|
|
||||||
|
|
||||||
if field.state == 0:
|
|
||||||
color = WHITE
|
|
||||||
elif field.state == 1:
|
|
||||||
color = RED
|
|
||||||
elif field.state == 2:
|
|
||||||
color = YELLOW
|
|
||||||
elif field.state == 3:
|
|
||||||
color = GREEN
|
|
||||||
elif field.state == 4:
|
|
||||||
color = BLACK
|
|
||||||
pygame.draw.rect(display, color,
|
|
||||||
[i * TILE_SIZE, j * TILE_SIZE, TILE_SIZE, TILE_SIZE])
|
|
||||||
|
|
||||||
|
|
||||||
def drawTractor(display, tractor_horizontal_index, tractor_vertical_index):
|
|
||||||
pygame.draw.rect(display, BLACK,
|
|
||||||
[tractor_horizontal_index * TILE_SIZE, tractor_vertical_index * TILE_SIZE, TRACTOR_WIDTH,
|
|
||||||
TRACTOR_HEIGHT])
|
|