459 lines
12 KiB
Python
459 lines
12 KiB
Python
import pygame
|
|
import os
|
|
from enum import Enum
|
|
|
|
from ui.button import Button
|
|
from ui.input_box import InputBox
|
|
|
|
# VARIABLE STARTS WITH ... IF IT'S
|
|
# V a value like a string or an int
|
|
# STRUCT a list or other structure of values
|
|
# FUNC a function
|
|
# OBJ a classes instance
|
|
# ASSET a png file (or other graphic format)
|
|
# MAP a JSON map file
|
|
|
|
|
|
# ================= #
|
|
# === VARIABLES === #
|
|
# ================= #
|
|
|
|
V_NAME_OF_WINDOW = "MineFusion TM"
|
|
DIR_ASSETS = os.path.join("resources", "assets")
|
|
V_FPS = 60
|
|
|
|
TURN_INTERVAL = 0.3 # interval between two turns in seconds
|
|
|
|
V_TILE_SIZE = 60
|
|
V_GRID_VER_TILES = 10 # vertical (number of rows)
|
|
V_GRID_HOR_TILES = 10 # horizontal (number of columns)
|
|
V_SCREEN_PADDING = 10
|
|
V_NUMBER_PADDING = 50
|
|
V_TILE_AREA_HEIGHT = V_TILE_SIZE * V_GRID_VER_TILES
|
|
V_TILE_AREA_WIDTH = V_TILE_SIZE * V_GRID_HOR_TILES
|
|
|
|
# side menu values
|
|
V_SIDE_MENU_WIDTH = 80
|
|
V_INPUT_BOX_HEIGHT = 55
|
|
V_BUTTON_HEIGHT = 40
|
|
|
|
SCREEN = pygame.display.set_mode(
|
|
(
|
|
V_TILE_AREA_WIDTH + 2 * V_SCREEN_PADDING + V_NUMBER_PADDING + V_SIDE_MENU_WIDTH + 10, # screen width
|
|
V_TILE_AREA_HEIGHT + 2 * V_SCREEN_PADDING + V_NUMBER_PADDING # screen height
|
|
)
|
|
)
|
|
|
|
|
|
# =============== #
|
|
# ==== ENUMS ==== #
|
|
# =============== #
|
|
|
|
class Direction(Enum):
|
|
UP = 0
|
|
RIGHT = 1
|
|
DOWN = 2
|
|
LEFT = 3
|
|
|
|
def next(self):
|
|
v = (self.value + 1) % 4
|
|
return Direction(v)
|
|
|
|
def previous(self):
|
|
v = (self.value - 1) % 4
|
|
return Direction(v)
|
|
|
|
|
|
class Action(Enum):
|
|
ROTATE_LEFT = 0
|
|
ROTATE_RIGHT = 1
|
|
GO = 2
|
|
|
|
|
|
class Digit(Enum):
|
|
ONES = 0
|
|
TENS = 1
|
|
|
|
|
|
class Coords(Enum):
|
|
X = 0
|
|
Y = 1
|
|
|
|
|
|
class Terrain(Enum):
|
|
CONCRETE = 2
|
|
GRASS = 5
|
|
MUD = 8
|
|
MINE = 500
|
|
|
|
|
|
# =============== #
|
|
# === STRUCTS === #
|
|
# =============== #
|
|
|
|
# # NORMAL STRUCTS
|
|
|
|
# # USED BY JSON GENERATOR
|
|
|
|
# used to generate random tile colors
|
|
STRUCT_TILE_TERRAINS = ["CONCRETE", "GRASS", "MUD"]
|
|
|
|
# used to generate random mines and create not random mines
|
|
STRUCT_MINE_TYPES = ["standard", "chained", "time"]
|
|
|
|
# values that are predefined for certain mine types and can't be changed by changing any parameters
|
|
# put here all dict keys that have hardcoded values and are not supposed to be editable
|
|
HARDCODED_VALUES = ["mine_type"]
|
|
|
|
# default values and key-value pairs for JsonGenerator class
|
|
# when defining a new mine it's dict template must be put here
|
|
STRUCT_MINE_ATTRIBUTES = {
|
|
"standard": {
|
|
"mine_type": "standard"
|
|
},
|
|
"chained": {
|
|
"mine_type": "chained",
|
|
"predecessor": None
|
|
},
|
|
"time": {
|
|
"mine_type": "time",
|
|
"timer": None
|
|
}
|
|
}
|
|
|
|
# types of attributes the mines have
|
|
# used for random mine generation
|
|
# int - integral number
|
|
STRUCT_MINE_ATTRIBUTE_TYPES = {
|
|
"standard": [],
|
|
"chained": [],
|
|
"time": [int]
|
|
}
|
|
|
|
|
|
# ============== #
|
|
# ==== FUNC ==== #
|
|
# ============== #
|
|
|
|
def get_tile_coordinates(position):
|
|
row, column = position
|
|
padding = V_SCREEN_PADDING + V_NUMBER_PADDING
|
|
|
|
return tuple((padding + column * V_TILE_SIZE, padding + row * V_TILE_SIZE))
|
|
|
|
|
|
# ============= #
|
|
# ==== OBJ ==== #
|
|
# ============= #
|
|
|
|
# initializing pygame modules so all instances can be constructed properly
|
|
pygame.init()
|
|
|
|
# creating ui components used in menu
|
|
HIGHLIGHT = pygame.transform.scale(
|
|
pygame.image.load(os.path.join(DIR_ASSETS, "old_tiles/tile_white.png")),
|
|
(V_TILE_SIZE, V_TILE_SIZE)
|
|
)
|
|
HIGHLIGHT.set_alpha(100)
|
|
|
|
_gui_width = V_SIDE_MENU_WIDTH
|
|
_ib_height, _bt_height = V_INPUT_BOX_HEIGHT, V_BUTTON_HEIGHT
|
|
_gui_x = V_TILE_AREA_WIDTH + 2 * V_SCREEN_PADDING + V_NUMBER_PADDING
|
|
_gui_y = SCREEN.get_height() / 2 - (2 * _ib_height + 2 * _bt_height + 30) / 2
|
|
|
|
INPUT_ROW = InputBox(
|
|
position=(_gui_x, _gui_y),
|
|
dimensions=(_gui_width, _ib_height),
|
|
text="row",
|
|
box_color=(100, 200, 100),
|
|
bottom_strip_color=(120, 220, 120),
|
|
inner_box_color=(120, 220, 120),
|
|
outline_color=(80, 180, 80),
|
|
outline_additional_pixel=True,
|
|
valid_input_characters="1234567890",
|
|
input_centered=True,
|
|
clear_input_on_click=True
|
|
)
|
|
INPUT_COLUMN = InputBox(
|
|
position=(_gui_x, _gui_y + _ib_height + 10),
|
|
dimensions=(_gui_width, _ib_height),
|
|
text="column",
|
|
box_color=(100, 200, 100),
|
|
bottom_strip_color=(120, 220, 120),
|
|
inner_box_color=(120, 220, 120),
|
|
outline_color=(80, 180, 80),
|
|
outline_additional_pixel=True,
|
|
valid_input_characters="1234567890",
|
|
input_centered=True,
|
|
clear_input_on_click=True
|
|
)
|
|
RANDOM_BUTTON = Button(
|
|
position=(_gui_x, _gui_y + 2 * _ib_height + 20),
|
|
dimensions=(_gui_width, _bt_height),
|
|
text="random",
|
|
box_color=(100, 200, 100),
|
|
outline_color=(80, 180, 80),
|
|
outline_additional_pixel=True
|
|
)
|
|
OK_BUTTON = Button(
|
|
position=(_gui_x, _gui_y + 2 * _ib_height + _bt_height + 30),
|
|
dimensions=(_gui_width, _bt_height),
|
|
text="ok",
|
|
box_color=(100, 200, 100),
|
|
outline_color=(80, 180, 80),
|
|
outline_additional_pixel=True
|
|
)
|
|
|
|
|
|
# ============== #
|
|
# ==== MAPS ==== #
|
|
# ============== #
|
|
|
|
MAP_RANDOM_10x10 = os.path.join("resources", "minefields", "fourthmap.json")
|
|
|
|
# ============== #
|
|
# === ASSETS === #
|
|
# ============== #
|
|
|
|
ASSET_BACKGROUND = pygame.transform.scale(
|
|
pygame.image.load(os.path.join(DIR_ASSETS, "numbered_grid.png")),
|
|
(650, 650)
|
|
)
|
|
|
|
ASSET_SAPPER = pygame.transform.scale(
|
|
pygame.image.load(os.path.join(DIR_ASSETS, "robot_sapper.png")),
|
|
(V_TILE_SIZE, V_TILE_SIZE)
|
|
)
|
|
|
|
ASSET_WALL = pygame.transform.scale(
|
|
pygame.image.load(os.path.join(DIR_ASSETS, "brick_wall.png")),
|
|
(V_TILE_SIZE, V_TILE_SIZE)
|
|
)
|
|
|
|
ASSET_CONCRETE = pygame.transform.scale(
|
|
pygame.image.load(os.path.join(DIR_ASSETS, "concrete.png")),
|
|
(V_TILE_SIZE, V_TILE_SIZE)
|
|
)
|
|
|
|
ASSET_MUD = pygame.transform.scale(
|
|
pygame.image.load(os.path.join(DIR_ASSETS, "mud.png")),
|
|
(V_TILE_SIZE, V_TILE_SIZE)
|
|
)
|
|
|
|
ASSET_GRASS = pygame.transform.scale(
|
|
pygame.image.load(os.path.join(DIR_ASSETS, "grass.png")),
|
|
(V_TILE_SIZE, V_TILE_SIZE)
|
|
)
|
|
|
|
ASSET_MINE = pygame.transform.scale(
|
|
pygame.image.load(os.path.join(DIR_ASSETS, "mine.png")),
|
|
(V_TILE_SIZE, V_TILE_SIZE)
|
|
)
|
|
|
|
ASSET_CHAINS = pygame.transform.scale(
|
|
pygame.image.load(os.path.join(DIR_ASSETS, "chains.png")),
|
|
(V_TILE_SIZE, V_TILE_SIZE)
|
|
)
|
|
|
|
ASSET_TIME_MINE = pygame.transform.scale(
|
|
pygame.image.load(os.path.join(DIR_ASSETS, "time_mine.png")),
|
|
(V_TILE_SIZE, V_TILE_SIZE)
|
|
)
|
|
|
|
# ==================== #
|
|
# === TIME NUMBERS === #
|
|
# ==================== #
|
|
|
|
ASSET_NUMBER_TIME_0 = pygame.transform.scale(
|
|
pygame.image.load(os.path.join(DIR_ASSETS, "time_numbers/time_number_0.png")),
|
|
(6, 16)
|
|
)
|
|
|
|
ASSET_NUMBER_TIME_1 = pygame.transform.scale(
|
|
pygame.image.load(os.path.join(DIR_ASSETS, "time_numbers/time_number_1.png")),
|
|
(6, 16)
|
|
)
|
|
|
|
ASSET_NUMBER_TIME_2 = pygame.transform.scale(
|
|
pygame.image.load(os.path.join(DIR_ASSETS, "time_numbers/time_number_2.png")),
|
|
(6, 16)
|
|
)
|
|
|
|
ASSET_NUMBER_TIME_3 = pygame.transform.scale(
|
|
pygame.image.load(os.path.join(DIR_ASSETS, "time_numbers/time_number_3.png")),
|
|
(6, 16)
|
|
)
|
|
|
|
ASSET_NUMBER_TIME_4 = pygame.transform.scale(
|
|
pygame.image.load(os.path.join(DIR_ASSETS, "time_numbers/time_number_4.png")),
|
|
(6, 16)
|
|
)
|
|
|
|
ASSET_NUMBER_TIME_5 = pygame.transform.scale(
|
|
pygame.image.load(os.path.join(DIR_ASSETS, "time_numbers/time_number_5.png")),
|
|
(6, 16)
|
|
)
|
|
|
|
ASSET_NUMBER_TIME_6 = pygame.transform.scale(
|
|
pygame.image.load(os.path.join(DIR_ASSETS, "time_numbers/time_number_6.png")),
|
|
(6, 16)
|
|
)
|
|
|
|
ASSET_NUMBER_TIME_7 = pygame.transform.scale(
|
|
pygame.image.load(os.path.join(DIR_ASSETS, "time_numbers/time_number_7.png")),
|
|
(6, 16)
|
|
)
|
|
|
|
ASSET_NUMBER_TIME_8 = pygame.transform.scale(
|
|
pygame.image.load(os.path.join(DIR_ASSETS, "time_numbers/time_number_8.png")),
|
|
(6, 16)
|
|
)
|
|
|
|
ASSET_NUMBER_TIME_9 = pygame.transform.scale(
|
|
pygame.image.load(os.path.join(DIR_ASSETS, "time_numbers/time_number_9.png")),
|
|
(6, 16)
|
|
)
|
|
|
|
# ====================== #
|
|
# === CHAINS NUMBERS === #
|
|
# ====================== #
|
|
|
|
ASSET_NUMBER_CHAINS_0 = pygame.transform.scale(
|
|
pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_0.png")),
|
|
(6, 12)
|
|
)
|
|
|
|
ASSET_NUMBER_CHAINS_1 = pygame.transform.scale(
|
|
pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_1.png")),
|
|
(6, 12)
|
|
)
|
|
|
|
ASSET_NUMBER_CHAINS_2 = pygame.transform.scale(
|
|
pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_2.png")),
|
|
(6, 12)
|
|
)
|
|
|
|
ASSET_NUMBER_CHAINS_3 = pygame.transform.scale(
|
|
pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_3.png")),
|
|
(6, 12)
|
|
)
|
|
|
|
ASSET_NUMBER_CHAINS_4 = pygame.transform.scale(
|
|
pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_4.png")),
|
|
(6, 12)
|
|
)
|
|
|
|
ASSET_NUMBER_CHAINS_5 = pygame.transform.scale(
|
|
pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_5.png")),
|
|
(6, 12)
|
|
)
|
|
|
|
ASSET_NUMBER_CHAINS_6 = pygame.transform.scale(
|
|
pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_6.png")),
|
|
(6, 12)
|
|
)
|
|
|
|
ASSET_NUMBER_CHAINS_7 = pygame.transform.scale(
|
|
pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_7.png")),
|
|
(6, 12)
|
|
)
|
|
|
|
ASSET_NUMBER_CHAINS_8 = pygame.transform.scale(
|
|
pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_8.png")),
|
|
(6, 12)
|
|
)
|
|
|
|
ASSET_NUMBER_CHAINS_9 = pygame.transform.scale(
|
|
pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_9.png")),
|
|
(6, 12)
|
|
)
|
|
|
|
ASSET_NUMBER_CHAINS_10 = pygame.transform.scale(
|
|
pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_10.png")),
|
|
(6, 12)
|
|
)
|
|
|
|
ASSET_NUMBER_CHAINS_11 = pygame.transform.scale(
|
|
pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_11.png")),
|
|
(6, 12)
|
|
)
|
|
|
|
ASSET_NUMBER_CHAINS_12 = pygame.transform.scale(
|
|
pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_12.png")),
|
|
(6, 12)
|
|
)
|
|
|
|
ASSET_NUMBER_CHAINS_13 = pygame.transform.scale(
|
|
pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_13.png")),
|
|
(6, 12)
|
|
)
|
|
|
|
ASSET_NUMBER_CHAINS_14 = pygame.transform.scale(
|
|
pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_14.png")),
|
|
(6, 12)
|
|
)
|
|
|
|
ASSET_NUMBER_CHAINS_15 = pygame.transform.scale(
|
|
pygame.image.load(os.path.join(DIR_ASSETS, "chain_numbers/chain_number_15.png")),
|
|
(6, 12)
|
|
)
|
|
|
|
# ================== #
|
|
# === OLD ASSETS === #
|
|
# ================== #
|
|
|
|
ASSET_MINE_A = pygame.transform.scale(
|
|
pygame.image.load(os.path.join(DIR_ASSETS, "simple_assets/mine_a.png")),
|
|
(V_TILE_SIZE, V_TILE_SIZE)
|
|
)
|
|
|
|
ASSET_MINE_B = pygame.transform.scale(
|
|
pygame.image.load(os.path.join(DIR_ASSETS, "simple_assets/mine_b.png")),
|
|
(V_TILE_SIZE, V_TILE_SIZE)
|
|
)
|
|
|
|
ASSET_MINE_F = pygame.transform.scale(
|
|
pygame.image.load(os.path.join(DIR_ASSETS, "simple_assets/mine_f.png")),
|
|
(V_TILE_SIZE, V_TILE_SIZE)
|
|
)
|
|
|
|
ASSET_MINE_K = pygame.transform.scale(
|
|
pygame.image.load(os.path.join(DIR_ASSETS, "simple_assets/mine_k.png")),
|
|
(V_TILE_SIZE, V_TILE_SIZE)
|
|
)
|
|
|
|
ASSET_TILE_ORANGE = pygame.transform.scale(
|
|
pygame.image.load(os.path.join(DIR_ASSETS, "old_tiles/tile_orange.png")),
|
|
(V_TILE_SIZE, V_TILE_SIZE)
|
|
)
|
|
|
|
ASSET_TILE_RED = pygame.transform.scale(
|
|
pygame.image.load(os.path.join(DIR_ASSETS, "old_tiles/tile_red.png")),
|
|
(V_TILE_SIZE, V_TILE_SIZE)
|
|
)
|
|
|
|
ASSET_TILE_BLUE = pygame.transform.scale(
|
|
pygame.image.load(os.path.join(DIR_ASSETS, "old_tiles/tile_blue.png")),
|
|
(V_TILE_SIZE, V_TILE_SIZE)
|
|
)
|
|
|
|
ASSET_TILE_PURPLE = pygame.transform.scale(
|
|
pygame.image.load(os.path.join(DIR_ASSETS, "old_tiles/tile_purple.png")),
|
|
(V_TILE_SIZE, V_TILE_SIZE)
|
|
)
|
|
|
|
ASSET_TILE_GREEN = pygame.transform.scale(
|
|
pygame.image.load(os.path.join(DIR_ASSETS, "old_tiles/tile_green.png")),
|
|
(V_TILE_SIZE, V_TILE_SIZE)
|
|
)
|
|
|
|
ASSET_TILE_YELLOW = pygame.transform.scale(
|
|
pygame.image.load(os.path.join(DIR_ASSETS, "old_tiles/tile_yellow.png")),
|
|
(V_TILE_SIZE, V_TILE_SIZE)
|
|
)
|
|
|
|
ASSET_TILE_WHITE = pygame.transform.scale(
|
|
pygame.image.load(os.path.join(DIR_ASSETS, "old_tiles/tile_white.png")),
|
|
(V_TILE_SIZE, V_TILE_SIZE)
|
|
)
|