2024-03-07 18:01:12 +01:00
|
|
|
# create a field here : 1: add tiles, 2: place them
|
|
|
|
import pygame
|
|
|
|
|
|
|
|
from area.constants import WIDTH,HEIGHT,FIELD_WIDTH,FIELD_HEIGHT,TILE_SIZE,GREY,ROWS,COLS
|
|
|
|
from area.tractor import Tractor
|
|
|
|
from tile import Tile
|
|
|
|
|
|
|
|
tiles = []
|
|
|
|
tractor = Tractor(0*TILE_SIZE, 0*TILE_SIZE)
|
|
|
|
fieldX = (WIDTH-FIELD_WIDTH)/2
|
|
|
|
# in center of the screen
|
|
|
|
fieldY = 100
|
|
|
|
|
|
|
|
# move field elements to field position
|
|
|
|
|
|
|
|
def positionFieldElements():
|
|
|
|
for t in tiles:
|
|
|
|
t.x += fieldX
|
|
|
|
t.y += fieldY
|
|
|
|
tractor.x += fieldX
|
|
|
|
tractor.y += fieldY
|
|
|
|
|
|
|
|
def createTiles():
|
2024-03-22 22:14:05 +01:00
|
|
|
for y in range(0, COLS):
|
|
|
|
for x in range(0, ROWS):
|
2024-03-07 18:01:12 +01:00
|
|
|
tile = Tile(x*TILE_SIZE, y*TILE_SIZE)
|
|
|
|
tile.randomizeContent()
|
|
|
|
tiles.append(tile)
|
|
|
|
positionFieldElements()
|
|
|
|
|
|
|
|
def createField(win):
|
|
|
|
createTiles()
|
|
|
|
for t in tiles:
|
|
|
|
image = pygame.image.load(t.image).convert()
|
|
|
|
image = pygame.transform.scale(image, (TILE_SIZE, TILE_SIZE))
|
|
|
|
win.blit(image, (t.x, t.y))
|
|
|
|
pygame.display.flip()
|
|
|
|
imageTractor = pygame.image.load(tractor.image).convert_alpha()
|
|
|
|
imageTractor = pygame.transform.scale(imageTractor, (TILE_SIZE, TILE_SIZE))
|
|
|
|
win.blit(imageTractor, (tractor.x, tractor.y))
|
|
|
|
pygame.display.flip()
|
|
|
|
|
|
|
|
def drawWindow(win):
|
|
|
|
win.fill(GREY)
|
|
|
|
createField(win)
|