55 lines
1.3 KiB
Python
55 lines
1.3 KiB
Python
# create a field here : 1: add tiles, 2: place them
|
|
import pygame
|
|
import random
|
|
|
|
from area.constants import WIDTH,FIELD_WIDTH,TILE_SIZE,GREY,ROWS,COLS
|
|
from tile import Tile
|
|
from ground import Dirt
|
|
|
|
tiles = []
|
|
|
|
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
|
|
|
|
|
|
def createTiles():
|
|
for y in range(0, COLS):
|
|
for x in range(0, ROWS):
|
|
tile = Tile(x*TILE_SIZE, y*TILE_SIZE)
|
|
dirt = Dirt(random.randint(1, 100), random.randint(1, 100))
|
|
dirt.pests_and_weeds()
|
|
tile.ground = dirt
|
|
tile.randomizeContent()
|
|
tiles.append(tile)
|
|
positionFieldElements()
|
|
return tiles
|
|
|
|
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()
|
|
|
|
|
|
def drawWindow(win):
|
|
win.fill(GREY)
|
|
createField(win)
|
|
pygame.display.flip()
|
|
|
|
|
|
def get_tile_coordinates(index):
|
|
if index < len(tiles):
|
|
tile = tiles[index]
|
|
return tile.x, tile.y
|
|
else:
|
|
return None |