stop clock, replay
This commit is contained in:
parent
f8cc91e585
commit
0d1caac357
@ -33,7 +33,7 @@ HIGHLIGHT_TEXT_COLOR = arcade.color.BUBBLES
|
|||||||
FONT_NAME = "joystix monospace.ttf"
|
FONT_NAME = "joystix monospace.ttf"
|
||||||
TEXT_MARGIN = 40
|
TEXT_MARGIN = 40
|
||||||
FONT_SIZE = 10
|
FONT_SIZE = 10
|
||||||
HIGHLIGHT_TEXT_FONT_SIZE = 19
|
HIGHLIGHT_TEXT_FONT_SIZE = 20
|
||||||
TEXT_HEIGHT = 13.2
|
TEXT_HEIGHT = 13.2
|
||||||
TEXT = """SCORE
|
TEXT = """SCORE
|
||||||
HIGH SCORE
|
HIGH SCORE
|
||||||
@ -109,6 +109,9 @@ class TetrArcade(arcade.Window):
|
|||||||
Status.PAUSED: {
|
Status.PAUSED: {
|
||||||
arcade.key.ESCAPE: self.resume,
|
arcade.key.ESCAPE: self.resume,
|
||||||
arcade.key.F1: self.resume
|
arcade.key.F1: self.resume
|
||||||
|
},
|
||||||
|
Status.OVER: {
|
||||||
|
arcade.key.ENTER: self.new_game
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.autorepeatable_actions = (self.move_left, self.move_right, self.soft_drop)
|
self.autorepeatable_actions = (self.move_left, self.move_right, self.soft_drop)
|
||||||
@ -136,7 +139,6 @@ class TetrArcade(arcade.Window):
|
|||||||
font_name = FONT_NAME,
|
font_name = FONT_NAME,
|
||||||
anchor_x = 'right'
|
anchor_x = 'right'
|
||||||
)
|
)
|
||||||
self.highlight_texts = []
|
|
||||||
|
|
||||||
self.new_game()
|
self.new_game()
|
||||||
|
|
||||||
@ -157,9 +159,15 @@ class TetrArcade(arcade.Window):
|
|||||||
|
|
||||||
def new_game(self):
|
def new_game(self):
|
||||||
self.pressed_actions = []
|
self.pressed_actions = []
|
||||||
|
self.highlight_texts = []
|
||||||
self.auto_repeat = False
|
self.auto_repeat = False
|
||||||
arcade.schedule(self.clock, 1)
|
arcade.schedule(self.clock, 1)
|
||||||
self.game.new_game()
|
self.game.new_game()
|
||||||
|
self.update_matrix()
|
||||||
|
if self.game.status in (Status.PLAYING, Status.OVER):
|
||||||
|
self.update_current_piece()
|
||||||
|
self.update_held_piece()
|
||||||
|
self.update_next_pieces()
|
||||||
|
|
||||||
def new_piece(self, piece):
|
def new_piece(self, piece):
|
||||||
piece_sprites = arcade.SpriteList()
|
piece_sprites = arcade.SpriteList()
|
||||||
@ -212,7 +220,11 @@ class TetrArcade(arcade.Window):
|
|||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
if action in self.autorepeatable_actions:
|
if action in self.autorepeatable_actions:
|
||||||
|
try:
|
||||||
self.pressed_actions.remove(action)
|
self.pressed_actions.remove(action)
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
if not self.pressed_actions:
|
if not self.pressed_actions:
|
||||||
self.stop_autorepeat()
|
self.stop_autorepeat()
|
||||||
arcade.schedule(self.repeat_action, AUTOREPEAT_DELAY)
|
arcade.schedule(self.repeat_action, AUTOREPEAT_DELAY)
|
||||||
@ -282,24 +294,40 @@ class TetrArcade(arcade.Window):
|
|||||||
self.game.swap()
|
self.game.swap()
|
||||||
|
|
||||||
def pause(self, delta_time=0):
|
def pause(self, delta_time=0):
|
||||||
print("pause")
|
self.highlight_texts = ("""PAUSE
|
||||||
self.game.status = "paused"
|
|
||||||
|
PRESS
|
||||||
|
[ESC]
|
||||||
|
TO
|
||||||
|
RESUME""",)
|
||||||
|
self.game.status = Status.PAUSED
|
||||||
self.stop_fall()
|
self.stop_fall()
|
||||||
self.cancel_prelock()
|
self.cancel_prelock()
|
||||||
|
arcade.unschedule(self.clock)
|
||||||
self.pressed_actions = []
|
self.pressed_actions = []
|
||||||
self.stop_autorepeat()
|
self.stop_autorepeat()
|
||||||
|
|
||||||
def resume(self, delta_time=0):
|
def resume(self, delta_time=0):
|
||||||
self.game.status = "playing"
|
self.highlight_texts = []
|
||||||
|
self.game.status = Status.PLAYING
|
||||||
self.start_fall()
|
self.start_fall()
|
||||||
if self.game.current_piece.prelocked:
|
if self.game.current_piece.prelocked:
|
||||||
arcade.schedule(self.lock, self.game.lock_delay)
|
arcade.schedule(self.lock, self.game.lock_delay)
|
||||||
|
arcade.schedule(self.clock, 1)
|
||||||
|
|
||||||
def game_over(self):
|
def game_over(self):
|
||||||
arcade.unschedule(self.repeat_action)
|
arcade.unschedule(self.repeat_action)
|
||||||
self.cancel_prelock()
|
self.cancel_prelock()
|
||||||
self.stop_fall()
|
self.stop_fall()
|
||||||
self.highlight_texts = ("GAME\nOVER",)
|
arcade.unschedule(self.clock)
|
||||||
|
self.highlight_texts = ("""GAME
|
||||||
|
OVER
|
||||||
|
|
||||||
|
PRESS
|
||||||
|
[ENTER]
|
||||||
|
TO
|
||||||
|
PLAY
|
||||||
|
AGAIN""",)
|
||||||
|
|
||||||
def add_highlight_text(self, string):
|
def add_highlight_text(self, string):
|
||||||
self.highlight_texts.append(string)
|
self.highlight_texts.append(string)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user