Traktor/source/area/field.py

71 lines
1.8 KiB
Python
Raw Normal View History

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 tile import Tile
tiles = []
2024-03-07 18:01:12 +01:00
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
2024-03-07 18:01:12 +01:00
def createTiles():
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()
2024-04-10 01:52:13 +02:00
return tiles
2024-03-07 18:01:12 +01:00
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()
2024-03-07 18:01:12 +01:00
def drawWindow(win):
win.fill(GREY)
createField(win)
pygame.display.flip()
2024-04-10 01:52:13 +02:00
2024-04-14 14:29:11 +02:00
#experimental:
# def update_tiles(win, tractor):
# tiles = createTiles()
# for tile in tiles:
# if tile.x == tractor.previous_x and tile.y == tractor.previous_y:
# tile.x = tractor.x
# tile.y = tractor.y
2024-04-10 01:52:13 +02:00
2024-04-14 14:29:11 +02:00
# if tile.image is not None:
# new_tile = Tile(tile.x, tile.y)
# new_tile.image = tile.image
2024-04-10 01:52:13 +02:00
2024-04-14 14:29:11 +02:00
# tiles.append(new_tile)
2024-04-10 01:52:13 +02:00
2024-04-14 14:29:11 +02:00
# image = pygame.image.load(tile.image).convert()
# image = pygame.transform.scale(image, (TILE_SIZE, TILE_SIZE))
# win.blit(image, (tile.x + fieldX-1, tile.y + fieldY-1))
def get_tile_coordinates(index):
if index < len(tiles):
tile = tiles[index]
return tile.x, tile.y
else:
return None