moved and removed blitting from minefield

This commit is contained in:
s452635 2021-05-03 20:33:17 +02:00
parent b9128bc7c8
commit fa5339685d
2 changed files with 55 additions and 50 deletions

View File

@ -3,6 +3,28 @@ import pygame
import project_constants as const 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 === # # === MAIN FUNCTIONS === #
# ====================== # # ====================== #
@ -34,8 +56,26 @@ def blit_graphics(minefield):
) )
) )
# draw tiles and mines from minefield for row in minefield.matrix:
minefield.draw(const.SCREEN) 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 # all the tests in one place
test_blits() test_blits()
@ -60,6 +100,18 @@ def calculate_screen_position(coords):
return 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 === # # === SAPPER === #
# ============== # # ============== #

View File

@ -7,24 +7,6 @@ from mine_models import time_mine as tm
from mine_models import chained_mine as cm 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: class Minefield:
def __init__(self, json_path): def __init__(self, json_path):
self.turn = 0 self.turn = 0
@ -56,34 +38,6 @@ class Minefield:
self.matrix[row][column].color = tile_data["color"].upper() 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 === # # === MOVEMENT === #
# ================ # # ================ #
@ -94,7 +48,6 @@ class Minefield:
if 0 <= target_row < const.V_GRID_VER_TILES \ 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: and self.matrix[target_row][target_column].mine is None:
return True return True
return False return False