166 lines
3.6 KiB
Python
166 lines
3.6 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) (moved to asset_constants)
|
|
# MAP a JSON map file
|
|
|
|
|
|
# ================= #
|
|
# === VARIABLES === #
|
|
# ================= #
|
|
|
|
V_NAME_OF_WINDOW = "MineFusion TM"
|
|
V_FPS = 60
|
|
|
|
ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
DIR_ASSETS = os.path.join(ROOT_DIR, "resources", "assets")
|
|
|
|
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_WIDTH = V_TILE_AREA_WIDTH + 2 * V_SCREEN_PADDING + V_NUMBER_PADDING + V_SIDE_MENU_WIDTH + 10
|
|
SCREEN_HEIGHT = V_TILE_AREA_HEIGHT + 2 * V_SCREEN_PADDING + V_NUMBER_PADDING
|
|
SCREEN = pygame.display.set_mode((SCREEN_WIDTH, 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 old 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)
|
|
|
|
|
|
# ============== #
|
|
# ==== MAPS ==== #
|
|
# ============== #
|
|
|
|
MAP_RANDOM_10x10 = os.path.join("resources", "minefields", "fourthmap.json")
|
|
|
|
|