redefine consts in TetrArcade.py
This commit is contained in:
parent
5f137a62ec
commit
f48f1fc000
@ -17,10 +17,26 @@ You can install it with:
|
|||||||
python -m pip install --user arcade"""
|
python -m pip install --user arcade"""
|
||||||
)
|
)
|
||||||
|
|
||||||
from tetrislogic import TetrisLogic, Color, State
|
from tetrislogic import TetrisLogic, Color, State, Coord
|
||||||
|
|
||||||
|
|
||||||
# Constants
|
# Constants
|
||||||
|
# Matrix
|
||||||
|
NB_LINES = 20
|
||||||
|
NB_COLS = 10
|
||||||
|
NB_NEXT = 5
|
||||||
|
|
||||||
|
# Delays (seconds)
|
||||||
|
LOCK_DELAY = 0.5
|
||||||
|
FALL_DELAY = 1
|
||||||
|
AUTOREPEAT_DELAY = 0.300
|
||||||
|
AUTOREPEAT_PERIOD = 0.010
|
||||||
|
|
||||||
|
# Piece init coord
|
||||||
|
MATRIX_PIECE_COORD = Coord(4, NB_LINES)
|
||||||
|
NEXT_PIECE_COORDS = [Coord(NB_COLS + 4, NB_LINES - 4 * n - 3) for n in range(NB_NEXT)]
|
||||||
|
HELD_PIECE_COORD = Coord(-5, NB_LINES - 3)
|
||||||
|
|
||||||
# Window
|
# Window
|
||||||
WINDOW_WIDTH = 800
|
WINDOW_WIDTH = 800
|
||||||
WINDOW_HEIGHT = 600
|
WINDOW_HEIGHT = 600
|
||||||
@ -48,7 +64,6 @@ if getattr(sys, 'frozen', False):
|
|||||||
DATA_DIR = os.path.dirname(sys.executable)
|
DATA_DIR = os.path.dirname(sys.executable)
|
||||||
else:
|
else:
|
||||||
# The application is not frozen
|
# The application is not frozen
|
||||||
# Change this bit to match where you store your data files:
|
|
||||||
DATA_DIR = os.path.dirname(__file__)
|
DATA_DIR = os.path.dirname(__file__)
|
||||||
DATA_DIR = os.path.join(DATA_DIR, "res")
|
DATA_DIR = os.path.join(DATA_DIR, "res")
|
||||||
|
|
||||||
@ -74,14 +89,8 @@ TEXTURES = arcade.load_textures(
|
|||||||
)
|
)
|
||||||
TEXTURES = {color: TEXTURES[i] for color, i in MINOES_COLOR_ID.items()}
|
TEXTURES = {color: TEXTURES[i] for color, i in MINOES_COLOR_ID.items()}
|
||||||
|
|
||||||
# User profile path
|
# Music
|
||||||
if sys.platform == "win32":
|
MUSIC_PATH = os.path.join(DATA_DIR, "Tetris - Song A.mp3")
|
||||||
USER_PROFILE_DIR = os.environ.get("appdata", os.path.expanduser("~\Appdata\Roaming"))
|
|
||||||
else:
|
|
||||||
USER_PROFILE_DIR = os.environ.get("XDG_DATA_HOME", os.path.expanduser("~/.local/share"))
|
|
||||||
USER_PROFILE_DIR = os.path.join(USER_PROFILE_DIR, "TetrArcade")
|
|
||||||
HIGH_SCORE_PATH = os.path.join(USER_PROFILE_DIR, ".high_score")
|
|
||||||
CONF_PATH = os.path.join(USER_PROFILE_DIR, "TetrArcade.ini")
|
|
||||||
|
|
||||||
# Text
|
# Text
|
||||||
TEXT_COLOR = arcade.color.BUBBLES
|
TEXT_COLOR = arcade.color.BUBBLES
|
||||||
@ -92,11 +101,18 @@ STATS_TEXT_WIDTH = 150
|
|||||||
HIGHLIGHT_TEXT_COLOR = arcade.color.BUBBLES
|
HIGHLIGHT_TEXT_COLOR = arcade.color.BUBBLES
|
||||||
HIGHLIGHT_TEXT_SIZE = 20
|
HIGHLIGHT_TEXT_SIZE = 20
|
||||||
|
|
||||||
# Music
|
# User profile path
|
||||||
MUSIC_PATH = os.path.join(DATA_DIR, "Tetris - Song A.mp3")
|
if sys.platform == "win32":
|
||||||
|
USER_PROFILE_DIR = os.environ.get("appdata", os.path.expanduser("~\Appdata\Roaming"))
|
||||||
|
else:
|
||||||
|
USER_PROFILE_DIR = os.environ.get("XDG_DATA_HOME", os.path.expanduser("~/.local/share"))
|
||||||
|
USER_PROFILE_DIR = os.path.join(USER_PROFILE_DIR, "TetrArcade")
|
||||||
|
HIGH_SCORE_PATH = os.path.join(USER_PROFILE_DIR, ".high_score")
|
||||||
|
CONF_PATH = os.path.join(USER_PROFILE_DIR, "TetrArcade.ini")
|
||||||
|
|
||||||
|
|
||||||
class MinoSprite(arcade.Sprite):
|
class MinoSprite(arcade.Sprite):
|
||||||
|
|
||||||
def __init__(self, mino, window, alpha):
|
def __init__(self, mino, window, alpha):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.alpha = alpha
|
self.alpha = alpha
|
||||||
@ -114,6 +130,7 @@ class MinoSprite(arcade.Sprite):
|
|||||||
|
|
||||||
|
|
||||||
class MinoesSprites(arcade.SpriteList):
|
class MinoesSprites(arcade.SpriteList):
|
||||||
|
|
||||||
def resize(self, scale):
|
def resize(self, scale):
|
||||||
for sprite in self:
|
for sprite in self:
|
||||||
sprite.scale = scale
|
sprite.scale = scale
|
||||||
@ -121,6 +138,7 @@ class MinoesSprites(arcade.SpriteList):
|
|||||||
|
|
||||||
|
|
||||||
class TetrominoSprites(MinoesSprites):
|
class TetrominoSprites(MinoesSprites):
|
||||||
|
|
||||||
def __init__(self, tetromino, window, alpha=NORMAL_ALPHA):
|
def __init__(self, tetromino, window, alpha=NORMAL_ALPHA):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.tetromino = tetromino
|
self.tetromino = tetromino
|
||||||
@ -136,6 +154,7 @@ class TetrominoSprites(MinoesSprites):
|
|||||||
|
|
||||||
|
|
||||||
class MatrixSprites(MinoesSprites):
|
class MatrixSprites(MinoesSprites):
|
||||||
|
|
||||||
def __init__(self, matrix):
|
def __init__(self, matrix):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.matrix = matrix
|
self.matrix = matrix
|
||||||
@ -150,6 +169,18 @@ class MatrixSprites(MinoesSprites):
|
|||||||
|
|
||||||
|
|
||||||
class TetrArcade(TetrisLogic, arcade.Window):
|
class TetrArcade(TetrisLogic, arcade.Window):
|
||||||
|
|
||||||
|
NB_LINES = NB_LINES
|
||||||
|
NB_COLS = NB_COLS
|
||||||
|
NB_NEXT = NB_NEXT
|
||||||
|
LOCK_DELAY = LOCK_DELAY
|
||||||
|
FALL_DELAY = FALL_DELAY
|
||||||
|
AUTOREPEAT_DELAY = AUTOREPEAT_DELAY
|
||||||
|
AUTOREPEAT_PERIOD = AUTOREPEAT_PERIOD
|
||||||
|
MATRIX_PIECE_COORD = MATRIX_PIECE_COORD
|
||||||
|
NEXT_PIECE_COORDS = NEXT_PIECE_COORDS
|
||||||
|
HELD_PIECE_COORD = HELD_PIECE_COORD
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
locale.setlocale(locale.LC_ALL, "")
|
locale.setlocale(locale.LC_ALL, "")
|
||||||
self.highlight_texts = []
|
self.highlight_texts = []
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from .consts import NB_LINES, NB_COLS, NB_NEXT
|
from .consts import NB_LINES, NB_COLS, NB_NEXT
|
||||||
from .utils import Movement, Rotation, Color
|
from .utils import Movement, Rotation, Color, Coord
|
||||||
from .tetromino import Mino, Tetromino
|
from .tetromino import Mino, Tetromino
|
||||||
from .tetrislogic import TetrisLogic, State, Matrix
|
from .tetrislogic import TetrisLogic, State, Matrix
|
||||||
|
@ -10,11 +10,10 @@ NB_NEXT = 5
|
|||||||
# Delays (seconds)
|
# Delays (seconds)
|
||||||
LOCK_DELAY = 0.5
|
LOCK_DELAY = 0.5
|
||||||
FALL_DELAY = 1
|
FALL_DELAY = 1
|
||||||
AUTOREPEAT_DELAY = 0.200 # Official : 0.300
|
AUTOREPEAT_DELAY = 0.300 # Official : 0.300 s
|
||||||
AUTOREPEAT_PERIOD = 0.010 # Official : 0.010
|
AUTOREPEAT_PERIOD = 0.010 # Official : 0.010 s
|
||||||
|
|
||||||
|
|
||||||
# Piece init coord
|
# Piece init coord
|
||||||
CURRENT_COORD = Coord(4, NB_LINES)
|
MATRIX_PIECE_COORD = Coord(4, NB_LINES)
|
||||||
NEXT_COORDS = [Coord(NB_COLS + 4, NB_LINES - 4 * n - 3) for n in range(NB_NEXT)]
|
NEXT_PIECE_COORDS = [Coord(NB_COLS + 4, NB_LINES - 4 * n - 3) for n in range(NB_NEXT)]
|
||||||
HELD_COORD = Coord(-5, NB_LINES - 3)
|
HELD_PIECE_COORD = Coord(-5, NB_LINES - 3)
|
||||||
|
@ -12,9 +12,9 @@ from .consts import (
|
|||||||
FALL_DELAY,
|
FALL_DELAY,
|
||||||
AUTOREPEAT_DELAY,
|
AUTOREPEAT_DELAY,
|
||||||
AUTOREPEAT_PERIOD,
|
AUTOREPEAT_PERIOD,
|
||||||
CURRENT_COORD,
|
MATRIX_PIECE_COORD,
|
||||||
NEXT_COORDS,
|
NEXT_PIECE_COORDS,
|
||||||
HELD_COORD,
|
HELD_PIECE_COORD,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -66,9 +66,9 @@ class TetrisLogic:
|
|||||||
FALL_DELAY = FALL_DELAY
|
FALL_DELAY = FALL_DELAY
|
||||||
AUTOREPEAT_DELAY = AUTOREPEAT_DELAY
|
AUTOREPEAT_DELAY = AUTOREPEAT_DELAY
|
||||||
AUTOREPEAT_PERIOD = AUTOREPEAT_PERIOD
|
AUTOREPEAT_PERIOD = AUTOREPEAT_PERIOD
|
||||||
CURRENT_COORD = CURRENT_COORD
|
MATRIX_PIECE_COORD = MATRIX_PIECE_COORD
|
||||||
NEXT_COORDS = NEXT_COORDS
|
NEXT_PIECE_COORDS = NEXT_PIECE_COORDS
|
||||||
HELD_COORD = HELD_COORD
|
HELD_PIECE_COORD = HELD_PIECE_COORD
|
||||||
random_bag = []
|
random_bag = []
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -138,12 +138,12 @@ class TetrisLogic:
|
|||||||
|
|
||||||
def new_matrix_piece(self):
|
def new_matrix_piece(self):
|
||||||
self.matrix.piece = self.next.pieces.pop(0)
|
self.matrix.piece = self.next.pieces.pop(0)
|
||||||
self.matrix.piece.coord = self.CURRENT_COORD
|
self.matrix.piece.coord = self.MATRIX_PIECE_COORD
|
||||||
self.matrix.ghost = self.matrix.piece.ghost()
|
self.matrix.ghost = self.matrix.piece.ghost()
|
||||||
self.move_ghost()
|
self.move_ghost()
|
||||||
self.next.pieces.append(self.new_tetromino())
|
self.next.pieces.append(self.new_tetromino())
|
||||||
self.next.pieces[-1].coord = self.NEXT_COORDS[-1]
|
self.next.pieces[-1].coord = self.NEXT_PIECE_COORDS[-1]
|
||||||
for tetromino, coord in zip(self.next.pieces, self.NEXT_COORDS):
|
for tetromino, coord in zip(self.next.pieces, self.NEXT_PIECE_COORDS):
|
||||||
tetromino.coord = coord
|
tetromino.coord = coord
|
||||||
|
|
||||||
if not self.can_move(self.matrix.piece.coord, (mino.coord for mino in self.matrix.piece)):
|
if not self.can_move(self.matrix.piece.coord, (mino.coord for mino in self.matrix.piece)):
|
||||||
@ -318,14 +318,14 @@ class TetrisLogic:
|
|||||||
self.matrix.piece.prelocked = False
|
self.matrix.piece.prelocked = False
|
||||||
self.stop(self.lock)
|
self.stop(self.lock)
|
||||||
self.matrix.piece, self.held.piece = self.held.piece, self.matrix.piece
|
self.matrix.piece, self.held.piece = self.held.piece, self.matrix.piece
|
||||||
self.held.piece.coord = self.HELD_COORD
|
self.held.piece.coord = self.HELD_PIECE_COORD
|
||||||
if type(self.held.piece) == I_Tetrimino:
|
if type(self.held.piece) == I_Tetrimino:
|
||||||
self.held.piece.coord += Movement.LEFT
|
self.held.piece.coord += Movement.LEFT
|
||||||
for mino, coord in zip(self.held.piece, self.held.piece.MINOES_COORDS):
|
for mino, coord in zip(self.held.piece, self.held.piece.MINOES_COORDS):
|
||||||
mino.coord = coord
|
mino.coord = coord
|
||||||
|
|
||||||
if self.matrix.piece:
|
if self.matrix.piece:
|
||||||
self.matrix.piece.coord = self.CURRENT_COORD
|
self.matrix.piece.coord = self.MATRIX_PIECE_COORD
|
||||||
self.matrix.ghost = self.matrix.piece.ghost()
|
self.matrix.ghost = self.matrix.piece.ghost()
|
||||||
self.move_ghost()
|
self.move_ghost()
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user