moved and removed blitting from minefield
This commit is contained in:
parent
b9128bc7c8
commit
fa5339685d
@ -3,6 +3,28 @@ import pygame
|
||||
import project_constants as const
|
||||
|
||||
|
||||
# ================================= #
|
||||
# === SO THE OLD BLITTING WORKS === #
|
||||
# ================================= #
|
||||
|
||||
tile_asset_options = {
|
||||
"BLUE": const.ASSET_TILE_BLUE,
|
||||
"GREEN": const.ASSET_TILE_GREEN,
|
||||
"ORANGE": const.ASSET_TILE_ORANGE,
|
||||
"PURPLE": const.ASSET_TILE_PURPLE,
|
||||
"RED": const.ASSET_TILE_RED,
|
||||
"WHITE": const.ASSET_TILE_WHITE,
|
||||
"YELLOW": const.ASSET_TILE_YELLOW
|
||||
}
|
||||
|
||||
mine_asset_options = {
|
||||
'A': const.ASSET_MINE_A,
|
||||
'B': const.ASSET_MINE_B,
|
||||
'F': const.ASSET_MINE_F,
|
||||
'K': const.ASSET_MINE_K
|
||||
}
|
||||
|
||||
|
||||
# ====================== #
|
||||
# === MAIN FUNCTIONS === #
|
||||
# ====================== #
|
||||
@ -34,8 +56,26 @@ def blit_graphics(minefield):
|
||||
)
|
||||
)
|
||||
|
||||
# draw tiles and mines from minefield
|
||||
minefield.draw(const.SCREEN)
|
||||
for row in minefield.matrix:
|
||||
for tile in row:
|
||||
|
||||
# calculate tile position on the screen
|
||||
tile_screen_coords = calculate_screen_position(tile.position)
|
||||
|
||||
# draw a tile
|
||||
const.SCREEN.blit(
|
||||
tile_asset_options.get(tile.color),
|
||||
tile_screen_coords
|
||||
)
|
||||
|
||||
# darkening every other tile
|
||||
if (tile.position[0]+tile.position[1]) % 2 == 0:
|
||||
pass # darken_tile(tile.position)
|
||||
|
||||
# draw a mine on top if there is one
|
||||
if tile.mine is not None:
|
||||
# current icons don't represent actual types, thus every mine has the same icon (temporary solution)
|
||||
const.SCREEN.blit(mine_asset_options['A'], tile_screen_coords)
|
||||
|
||||
# all the tests in one place
|
||||
test_blits()
|
||||
@ -60,6 +100,18 @@ def calculate_screen_position(coords):
|
||||
return coords
|
||||
|
||||
|
||||
def darken_tile(coords):
|
||||
|
||||
shadow = pygame.Surface((const.V_TILE_SIZE, const.V_TILE_SIZE))
|
||||
shadow.fill((220, 220, 220))
|
||||
|
||||
const.SCREEN.blit(
|
||||
shadow,
|
||||
calculate_screen_position(coords),
|
||||
special_flags=pygame.BLEND_RGB_MULT
|
||||
)
|
||||
|
||||
|
||||
# ============== #
|
||||
# === SAPPER === #
|
||||
# ============== #
|
||||
|
49
minefield.py
49
minefield.py
@ -7,24 +7,6 @@ from mine_models import time_mine as tm
|
||||
from mine_models import chained_mine as cm
|
||||
|
||||
|
||||
tile_asset_options = {
|
||||
"BLUE": const.ASSET_TILE_BLUE,
|
||||
"GREEN": const.ASSET_TILE_GREEN,
|
||||
"ORANGE": const.ASSET_TILE_ORANGE,
|
||||
"PURPLE": const.ASSET_TILE_PURPLE,
|
||||
"RED": const.ASSET_TILE_RED,
|
||||
"WHITE": const.ASSET_TILE_WHITE,
|
||||
"YELLOW": const.ASSET_TILE_YELLOW
|
||||
}
|
||||
|
||||
mine_asset_options = {
|
||||
'A': const.ASSET_MINE_A,
|
||||
'B': const.ASSET_MINE_B,
|
||||
'F': const.ASSET_MINE_F,
|
||||
'K': const.ASSET_MINE_K
|
||||
}
|
||||
|
||||
|
||||
class Minefield:
|
||||
def __init__(self, json_path):
|
||||
self.turn = 0
|
||||
@ -56,34 +38,6 @@ class Minefield:
|
||||
|
||||
self.matrix[row][column].color = tile_data["color"].upper()
|
||||
|
||||
@staticmethod
|
||||
def calculate_screen_position(row, column):
|
||||
coords = (
|
||||
const.V_NUMBER_PADDING + const.V_SCREEN_PADDING + const.V_TILE_SIZE * column,
|
||||
const.V_NUMBER_PADDING + const.V_SCREEN_PADDING + const.V_TILE_SIZE * row,
|
||||
)
|
||||
|
||||
return coords
|
||||
|
||||
def draw(self, window):
|
||||
# iterate through tiles
|
||||
for row in self.matrix:
|
||||
for tile in row:
|
||||
|
||||
# calculate tile position on the screen
|
||||
tile_screen_coords = self.calculate_screen_position(tile.position[0], tile.position[1])
|
||||
|
||||
# draw a tile
|
||||
window.blit(tile_asset_options.get(tile.color), tile_screen_coords)
|
||||
|
||||
# draw a mine on top if there is one
|
||||
if tile.mine is not None:
|
||||
# TODO: blit appropriate mine type
|
||||
# current icons don't represent actual types, thus every mine has the same icon (temporary solution)
|
||||
window.blit(mine_asset_options['A'], tile_screen_coords)
|
||||
|
||||
# draw the sapper has been moved to main
|
||||
|
||||
# ================ #
|
||||
# === MOVEMENT === #
|
||||
# ================ #
|
||||
@ -92,9 +46,8 @@ class Minefield:
|
||||
# If Agent comes upon a tile with a mine his starting position shall be reestablished
|
||||
def is_valid_move(self, target_row: int, target_column: int):
|
||||
if 0 <= target_row < const.V_GRID_VER_TILES \
|
||||
and 0 <= target_column < const.V_GRID_HOR_TILES \
|
||||
and 0 <= target_column < const.V_GRID_HOR_TILES \
|
||||
and self.matrix[target_row][target_column].mine is None:
|
||||
|
||||
return True
|
||||
|
||||
return False
|
||||
|
Loading…
Reference in New Issue
Block a user