Compare commits
3 Commits
850aad353e
...
b1cef21f00
Author | SHA1 | Date | |
---|---|---|---|
|
b1cef21f00 | ||
|
2c4808312f | ||
|
9db4f4d122 |
@ -59,7 +59,6 @@ TEXT_COLOR = arcade.color.BUBBLES
|
|||||||
FONT_NAME = "joystix monospace.ttf"
|
FONT_NAME = "joystix monospace.ttf"
|
||||||
STATS_TEXT_MARGIN = 40
|
STATS_TEXT_MARGIN = 40
|
||||||
STATS_TEXT_SIZE = 16
|
STATS_TEXT_SIZE = 16
|
||||||
STATS_TEXT_HEIGHT = 20.8
|
|
||||||
HIGHLIGHT_TEXT_COLOR = arcade.color.BUBBLES
|
HIGHLIGHT_TEXT_COLOR = arcade.color.BUBBLES
|
||||||
HIGHLIGHT_TEXT_SIZE = 20
|
HIGHLIGHT_TEXT_SIZE = 20
|
||||||
|
|
||||||
@ -83,18 +82,6 @@ QUIT ALT+F4
|
|||||||
"""
|
"""
|
||||||
START_TEXT = "TETRARCADE" + CONTROL_TEXT + "PRESS [ENTER] TO START"
|
START_TEXT = "TETRARCADE" + CONTROL_TEXT + "PRESS [ENTER] TO START"
|
||||||
PAUSE_TEXT = "PAUSE" + CONTROL_TEXT + "PRESS [ESC] TO RESUME"
|
PAUSE_TEXT = "PAUSE" + CONTROL_TEXT + "PRESS [ESC] TO RESUME"
|
||||||
STATS_TEXT = """SCORE
|
|
||||||
|
|
||||||
HIGH SCORE
|
|
||||||
|
|
||||||
LEVEL
|
|
||||||
|
|
||||||
GOAL
|
|
||||||
|
|
||||||
LINES
|
|
||||||
|
|
||||||
TIME
|
|
||||||
"""
|
|
||||||
GAME_OVER_TEXT = """GAME
|
GAME_OVER_TEXT = """GAME
|
||||||
OVER
|
OVER
|
||||||
|
|
||||||
@ -122,7 +109,7 @@ 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
|
||||||
self.update()
|
self.refresh()
|
||||||
|
|
||||||
|
|
||||||
class TetrominoSprites(MinoesSprites):
|
class TetrominoSprites(MinoesSprites):
|
||||||
@ -134,11 +121,10 @@ class TetrominoSprites(MinoesSprites):
|
|||||||
mino.sprite = MinoSprite(mino, window, alpha)
|
mino.sprite = MinoSprite(mino, window, alpha)
|
||||||
self.append(mino.sprite)
|
self.append(mino.sprite)
|
||||||
|
|
||||||
def update(self):
|
def refresh(self):
|
||||||
for mino in self.tetromino:
|
for mino in self.tetromino:
|
||||||
coord = mino.coord + self.tetromino.coord
|
coord = mino.coord + self.tetromino.coord
|
||||||
mino.sprite.set_position(coord.x, coord.y)
|
mino.sprite.set_position(coord.x, coord.y)
|
||||||
super().update()
|
|
||||||
|
|
||||||
def set_alpha(self, alpha):
|
def set_alpha(self, alpha):
|
||||||
for sprite in self:
|
for sprite in self:
|
||||||
@ -150,15 +136,14 @@ class MatrixSprites(MinoesSprites):
|
|||||||
def __init__(self, matrix):
|
def __init__(self, matrix):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.matrix = matrix
|
self.matrix = matrix
|
||||||
self.update()
|
self.refresh()
|
||||||
|
|
||||||
def update(self):
|
def refresh(self):
|
||||||
for y, line in enumerate(self.matrix):
|
for y, line in enumerate(self.matrix):
|
||||||
for x, mino in enumerate(line):
|
for x, mino in enumerate(line):
|
||||||
if mino:
|
if mino:
|
||||||
mino.sprite.set_position(x, y)
|
mino.sprite.set_position(x, y)
|
||||||
self.append(mino.sprite)
|
self.append(mino.sprite)
|
||||||
super().update()
|
|
||||||
|
|
||||||
|
|
||||||
class TetrArcade(tetrislogic.TetrisLogic, arcade.Window):
|
class TetrArcade(tetrislogic.TetrisLogic, arcade.Window):
|
||||||
@ -171,7 +156,7 @@ class TetrArcade(tetrislogic.TetrisLogic, arcade.Window):
|
|||||||
self.KEY_MAP = {
|
self.KEY_MAP = {
|
||||||
tetrislogic.State.STARTING: {
|
tetrislogic.State.STARTING: {
|
||||||
arcade.key.ENTER: self.new_game,
|
arcade.key.ENTER: self.new_game,
|
||||||
arcade.key.F11: self.toogle_fullscreen
|
arcade.key.F11: self.toggle_fullscreen
|
||||||
},
|
},
|
||||||
tetrislogic.State.PLAYING: {
|
tetrislogic.State.PLAYING: {
|
||||||
arcade.key.LEFT: self.move_left,
|
arcade.key.LEFT: self.move_left,
|
||||||
@ -195,16 +180,16 @@ class TetrArcade(tetrislogic.TetrisLogic, arcade.Window):
|
|||||||
arcade.key.NUM_0: self.swap,
|
arcade.key.NUM_0: self.swap,
|
||||||
arcade.key.ESCAPE: self.pause,
|
arcade.key.ESCAPE: self.pause,
|
||||||
arcade.key.F1: self.pause,
|
arcade.key.F1: self.pause,
|
||||||
arcade.key.F11: self.toogle_fullscreen
|
arcade.key.F11: self.toggle_fullscreen
|
||||||
},
|
},
|
||||||
tetrislogic.State.PAUSED: {
|
tetrislogic.State.PAUSED: {
|
||||||
arcade.key.ESCAPE: self.resume,
|
arcade.key.ESCAPE: self.resume,
|
||||||
arcade.key.F1: self.resume,
|
arcade.key.F1: self.resume,
|
||||||
arcade.key.F11: self.toogle_fullscreen
|
arcade.key.F11: self.toggle_fullscreen
|
||||||
},
|
},
|
||||||
tetrislogic.State.OVER: {
|
tetrislogic.State.OVER: {
|
||||||
arcade.key.ENTER: self.new_game,
|
arcade.key.ENTER: self.new_game,
|
||||||
arcade.key.F11: self.toogle_fullscreen
|
arcade.key.F11: self.toggle_fullscreen
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -223,14 +208,6 @@ class TetrArcade(tetrislogic.TetrisLogic, arcade.Window):
|
|||||||
self.matrix_bg = arcade.Sprite(MATRIX_SPRITE_PATH)
|
self.matrix_bg = arcade.Sprite(MATRIX_SPRITE_PATH)
|
||||||
self.matrix_bg.alpha = MATRIX_BG_ALPHA
|
self.matrix_bg.alpha = MATRIX_BG_ALPHA
|
||||||
self.matrix.sprites = MatrixSprites(self.matrix)
|
self.matrix.sprites = MatrixSprites(self.matrix)
|
||||||
self.stats_text = arcade.create_text(
|
|
||||||
text = STATS_TEXT,
|
|
||||||
color = TEXT_COLOR,
|
|
||||||
font_size = STATS_TEXT_SIZE,
|
|
||||||
font_name = FONT_NAME,
|
|
||||||
anchor_x = 'right'
|
|
||||||
)
|
|
||||||
self.scale = 1
|
|
||||||
|
|
||||||
def on_hide(self):
|
def on_hide(self):
|
||||||
self.pause()
|
self.pause()
|
||||||
@ -257,8 +234,8 @@ class TetrArcade(tetrislogic.TetrisLogic, arcade.Window):
|
|||||||
if tetromino:
|
if tetromino:
|
||||||
tetromino.sprites.resize(self.scale)
|
tetromino.sprites.resize(self.scale)
|
||||||
|
|
||||||
def toogle_fullscreen(self):
|
def toggle_fullscreen(self):
|
||||||
self.fullscreen = not self.fullscreen
|
self.set_fullscreen(not self.fullscreen)
|
||||||
|
|
||||||
def new_game(self):
|
def new_game(self):
|
||||||
self.highlight_texts = []
|
self.highlight_texts = []
|
||||||
@ -274,7 +251,7 @@ class TetrArcade(tetrislogic.TetrisLogic, arcade.Window):
|
|||||||
super().new_current()
|
super().new_current()
|
||||||
self.ghost.sprites = TetrominoSprites(self.ghost, self, GHOST_ALPHA)
|
self.ghost.sprites = TetrominoSprites(self.ghost, self, GHOST_ALPHA)
|
||||||
for tetromino in [self.current, self.ghost] + self.next:
|
for tetromino in [self.current, self.ghost] + self.next:
|
||||||
tetromino.sprites.update()
|
tetromino.sprites.refresh()
|
||||||
|
|
||||||
def move(self, movement, prelock=True):
|
def move(self, movement, prelock=True):
|
||||||
moved = super().move(movement, prelock)
|
moved = super().move(movement, prelock)
|
||||||
@ -286,14 +263,14 @@ class TetrArcade(tetrislogic.TetrisLogic, arcade.Window):
|
|||||||
change_y = movement.y * size
|
change_y = movement.y * size
|
||||||
self.current.sprites.move(change_x, change_y)
|
self.current.sprites.move(change_x, change_y)
|
||||||
if movement in (tetrislogic.Movement.LEFT, tetrislogic.Movement.RIGHT):
|
if movement in (tetrislogic.Movement.LEFT, tetrislogic.Movement.RIGHT):
|
||||||
self.ghost.sprites.update()
|
self.ghost.sprites.refresh()
|
||||||
return moved
|
return moved
|
||||||
|
|
||||||
def rotate(self, rotation):
|
def rotate(self, rotation):
|
||||||
rotated = super().rotate(rotation)
|
rotated = super().rotate(rotation)
|
||||||
if rotated:
|
if rotated:
|
||||||
for tetromino in (self.current, self.ghost):
|
for tetromino in (self.current, self.ghost):
|
||||||
tetromino.sprites.update()
|
tetromino.sprites.refresh()
|
||||||
return rotated
|
return rotated
|
||||||
|
|
||||||
def swap(self):
|
def swap(self):
|
||||||
@ -301,10 +278,10 @@ class TetrArcade(tetrislogic.TetrisLogic, arcade.Window):
|
|||||||
self.ghost.sprites = TetrominoSprites(self.ghost, self, GHOST_ALPHA)
|
self.ghost.sprites = TetrominoSprites(self.ghost, self, GHOST_ALPHA)
|
||||||
for tetromino in [self.held, self.current, self.ghost]:
|
for tetromino in [self.held, self.current, self.ghost]:
|
||||||
if tetromino:
|
if tetromino:
|
||||||
tetromino.sprites.update()
|
tetromino.sprites.refresh()
|
||||||
|
|
||||||
def lock(self):
|
def lock(self):
|
||||||
self.current.sprites.update()
|
self.current.sprites.refresh()
|
||||||
super().lock()
|
super().lock()
|
||||||
|
|
||||||
def on_key_press(self, key, modifiers):
|
def on_key_press(self, key, modifiers):
|
||||||
@ -347,15 +324,30 @@ class TetrArcade(tetrislogic.TetrisLogic, arcade.Window):
|
|||||||
if tetromino:
|
if tetromino:
|
||||||
tetromino.sprites.draw()
|
tetromino.sprites.draw()
|
||||||
|
|
||||||
arcade.render_text(
|
|
||||||
self.stats_text,
|
|
||||||
self.matrix_bg.left - STATS_TEXT_MARGIN,
|
|
||||||
self.matrix_bg.bottom
|
|
||||||
)
|
|
||||||
t = time.localtime(self.time)
|
t = time.localtime(self.time)
|
||||||
|
font_size = STATS_TEXT_SIZE * self.scale
|
||||||
|
for y, text in enumerate(
|
||||||
|
(
|
||||||
|
"TIME",
|
||||||
|
"LINES",
|
||||||
|
"GOAL",
|
||||||
|
"LEVEL",
|
||||||
|
"HIGH SCORE",
|
||||||
|
"SCORE"
|
||||||
|
)
|
||||||
|
):
|
||||||
|
arcade.draw_text(
|
||||||
|
text = text,
|
||||||
|
start_x = self.matrix_bg.left - STATS_TEXT_MARGIN*self.scale - self.matrix_bg.width,
|
||||||
|
start_y = self.matrix_bg.bottom + 1.5*(2*y+1)*font_size,
|
||||||
|
color = TEXT_COLOR,
|
||||||
|
font_size = font_size,
|
||||||
|
align = 'right',
|
||||||
|
font_name = FONT_NAME,
|
||||||
|
anchor_x = 'left'
|
||||||
|
)
|
||||||
for y, text in enumerate(
|
for y, text in enumerate(
|
||||||
(
|
(
|
||||||
|
|
||||||
"{:02d}:{:02d}:{:02d}".format(
|
"{:02d}:{:02d}:{:02d}".format(
|
||||||
t.tm_hour-1, t.tm_min, t.tm_sec
|
t.tm_hour-1, t.tm_min, t.tm_sec
|
||||||
),
|
),
|
||||||
@ -368,10 +360,10 @@ class TetrArcade(tetrislogic.TetrisLogic, arcade.Window):
|
|||||||
):
|
):
|
||||||
arcade.draw_text(
|
arcade.draw_text(
|
||||||
text = text,
|
text = text,
|
||||||
start_x = self.matrix_bg.left - STATS_TEXT_MARGIN,
|
start_x = self.matrix_bg.left - STATS_TEXT_MARGIN*self.scale,
|
||||||
start_y = self.matrix_bg.bottom + 2*y*STATS_TEXT_HEIGHT,
|
start_y = self.matrix_bg.bottom + 3*y*font_size,
|
||||||
color = TEXT_COLOR,
|
color = TEXT_COLOR,
|
||||||
font_size = STATS_TEXT_SIZE,
|
font_size = font_size,
|
||||||
align = 'right',
|
align = 'right',
|
||||||
font_name = FONT_NAME,
|
font_name = FONT_NAME,
|
||||||
anchor_x = 'right'
|
anchor_x = 'right'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user