This commit is contained in:
Raman Keraz 2021-03-16 13:27:39 +01:00
parent 2eadb299f0
commit b877fbaf4e
4 changed files with 37 additions and 17 deletions

View File

@ -1,7 +1,6 @@
#!/usr/bin/python3 #!/usr/bin/python3
import pygame from images import *
from config import * from config import *
@ -12,8 +11,9 @@ class Agent:
self.__move = FIELD_SIZE self.__move = FIELD_SIZE
def draw(self, screen: pygame.Surface): def draw(self, screen: pygame.Surface):
rect = pygame.Rect(self.__pos_x, self.__pos_y, FIELD_SIZE, FIELD_SIZE) tractorrect.size = (FIELD_SIZE, FIELD_SIZE)
pygame.draw.rect(screen, C_BLACK, rect) tractorrect.center = (self.__pos_x + FIELD_SIZE/2, self.__pos_y + FIELD_SIZE/2)
screen.blit(tractor, tractorrect)
def move_up(self): def move_up(self):
if self.__pos_y - self.__move >= 0: if self.__pos_y - self.__move >= 0:

View File

@ -27,22 +27,30 @@ class Board:
def draw(self, screen: pygame.Surface): def draw(self, screen: pygame.Surface):
size = (FIELD_SIZE/HORIZONTAL_NUM_OF_FIELDS, FIELD_SIZE/HORIZONTAL_NUM_OF_FIELDS)
for x in range(len(self.__fields)): for x in range(len(self.__fields)):
for y in range(len(self.__fields[x])): for y in range(len(self.__fields[x])):
obj = self.__fields[x][y] obj = self.__fields[x][y]
i = x * FIELD_SIZE
j = y * FIELD_SIZE
if obj == 'grass': if obj == 'grass':
grassrect.center = (x, y) grassrect.size = (size)
grassrect.center = (i, j)
screen.blit(grass, grassrect) screen.blit(grass, grassrect)
if obj == 'corn': if obj == 'corn':
cornrect.center = (x, y) cornrect.size = (size)
cornrect.center = (i, j)
screen.blit(corn, cornrect) screen.blit(corn, cornrect)
if obj == 'sunflower': if obj == 'sunflower':
sunflowerrect.center = (x, y) sunflowerrect.size = (size)
sunflowerrect.center = (i, j)
screen.blit(sunflower, sunflowerrect) screen.blit(sunflower, sunflowerrect)
if obj == 'sand': if obj == 'sand':
sandrect.center = (x, y) sandrect.size = (size)
sandrect.center = (i, j)
screen.blit(sand, sandrect) screen.blit(sand, sandrect)
if obj == 'clay': if obj == 'clay':
clayrect.center = (x, y) clayrect.size = (size)
clayrect.center = (i, j)
screen.blit(clay, clayrect) screen.blit(clay, clayrect)

View File

@ -10,7 +10,7 @@ __all__ = (
# Board settings: # Board settings:
VERTICAL_NUM_OF_FIELDS = 6 VERTICAL_NUM_OF_FIELDS = 6
HORIZONTAL_NUM_OF_FIELDS = 6 HORIZONTAL_NUM_OF_FIELDS = 6
FIELD_SIZE = 64 FIELD_SIZE = 60
WIDTH = HORIZONTAL_NUM_OF_FIELDS * FIELD_SIZE WIDTH = HORIZONTAL_NUM_OF_FIELDS * FIELD_SIZE
HEIGHT = VERTICAL_NUM_OF_FIELDS * FIELD_SIZE HEIGHT = VERTICAL_NUM_OF_FIELDS * FIELD_SIZE

View File

@ -1,13 +1,25 @@
import pygame import pygame
from config import *
soilType = ('sand','clay', 'soil', 'grass', 'corn', 'sunflower') soilType = ('sand','clay', 'grass', 'corn', 'sunflower')
tractor = pygame.image.load("resources/tractor.png") tractor_scale = pygame.image.load("resources/tractor.png")
clay = pygame.image.load("resources/clay.png") tractor = pygame.transform.scale(tractor_scale, (FIELD_SIZE, FIELD_SIZE))
sand = pygame.image.load("resources/sand.png")
grass = pygame.image.load("resources/grass.png") clay_scale= pygame.image.load("resources/clay.png")
corn = pygame.image.load("resources/corn.png") clay = pygame.transform.scale(clay_scale, (FIELD_SIZE, FIELD_SIZE))
sunflower = pygame.image.load("resources/sunflower.png")
sand_scale = pygame.image.load("resources/sand.png")
sand = pygame.transform.scale(sand_scale, (FIELD_SIZE, FIELD_SIZE))
grass_scale = pygame.image.load("resources/grass.png")
grass = pygame.transform.scale(grass_scale, (FIELD_SIZE, FIELD_SIZE))
corn_scale = pygame.image.load("resources/corn.png")
corn = pygame.transform.scale(corn_scale, (FIELD_SIZE, FIELD_SIZE))
sunflower_scale = pygame.image.load("resources/sunflower.png")
sunflower = pygame.transform.scale(sunflower_scale, (FIELD_SIZE, FIELD_SIZE))
tractorrect = tractor.get_rect() tractorrect = tractor.get_rect()
clayrect = clay.get_rect() clayrect = clay.get_rect()