Merge remote-tracking branch 'origin/master'

This commit is contained in:
v7eZ3t 2021-03-29 01:24:47 +02:00
commit f0c13cb6ea
17 changed files with 73 additions and 37 deletions

36
Main/drawUI.py Normal file
View 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))

View File

@ -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
View 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()

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 144 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 140 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 140 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 144 KiB

View File

@ -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.get_state() == 0:
color = WHITE
elif field.get_state() == 1:
color = RED
elif field.get_state() == 2:
color = YELLOW
elif field.get_state() == 3:
color = GREEN
elif field.get_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])