From 792db2f0c8fd262e5e53e813ec4eba4fb8eb8653 Mon Sep 17 00:00:00 2001 From: adrienmalin <41926238+adrienmalin@users.noreply.github.com> Date: Wed, 2 Jan 2019 03:00:47 +0100 Subject: [PATCH] hide on pause, T-SPIN on rotation 5 --- Main.gd | 29 ++++++++++++++++++++--------- Main.tscn | 4 ++-- Stats.tscn | 2 +- Tetrominos/TetroT.gd | 15 +++++++-------- Tetrominos/Tetromino.gd | 10 +++++----- 5 files changed, 35 insertions(+), 25 deletions(-) diff --git a/Main.gd b/Main.gd index 5c2bb81..677170e 100644 --- a/Main.gd +++ b/Main.gd @@ -60,9 +60,9 @@ func _ready(): func new_game(): $Stats.visible = true $Stats.new_game() + new_piece() resume() new_level() - new_piece() func new_level(): $Stats.new_level() @@ -129,8 +129,10 @@ func process_autoshift_action(): $Stats/HBC/VBC1/Score.text = str($Stats.score) func hard_drop(): + var score = 0 while move(movements["soft_drop"]): - $Stats.score += 2 + score += 2 + $Stats.score += score $Stats/HBC/VBC1/Score.text = str($Stats.score) lock() @@ -204,25 +206,34 @@ func resume(): $Stats/Clock.start() $MidiPlayer.resume() $MidiPlayer.mute_channels(LINE_CLEAR_MIDI_CHANNELS) + $GridMap.visible = true + next_piece.visible = true + current_piece.visible = true + if held_piece: + held_piece.visible = true + flash_print("GO!") -func pause(): +func pause(text = "PAUSE"): playing = false $DropTimer.stop() $LockDelay.stop() $Stats/Clock.stop() - $Stats.time = OS.get_system_time_secs() - $Stats.time + if text == "PAUSE": + $Stats.time = OS.get_system_time_secs() - $Stats.time + $GridMap.visible = false + next_piece.visible = false + current_piece.visible = false + if held_piece: + held_piece.visible = false $MidiPlayer.stop() - flash_print("PAUSE") + flash_print(text) func game_over(): - pause() - flash_print("GAME OVER") + pause("GAME OVER") func _notification(what): if what == MainLoop.NOTIFICATION_WM_FOCUS_OUT: pause() - #if what == MainLoop.NOTIFICATION_WM_FOCUS_IN: - # resume() func _on_LineCLearTimer_timeout(): $MidiPlayer.mute_channels(LINE_CLEAR_MIDI_CHANNELS) diff --git a/Main.tscn b/Main.tscn index a2f2544..d03ee9f 100644 --- a/Main.tscn +++ b/Main.tscn @@ -216,7 +216,7 @@ tracks/2/keys = { "values": [ Vector2( 0, 110 ), Vector2( 0, -50 ), Vector2( 0, -60 ), Vector2( 0, -100 ) ] } -[node name="Main" type="WorldEnvironment"] +[node name="Main" type="WorldEnvironment" index="0"] environment = SubResource( 2 ) script = ExtResource( 2 ) @@ -381,7 +381,7 @@ file = "res://midi/Tetris - Song A.mid" volume_db = -24 loop = true loop_start = 1.71 -soundfont = "res://midi/FluidR3 GM.sf2" +soundfont = "res://midi/TimGM6mb.sf2" [node name="Stats" parent="." index="12" instance=ExtResource( 6 )] diff --git a/Stats.tscn b/Stats.tscn index f3b690e..50279f7 100644 --- a/Stats.tscn +++ b/Stats.tscn @@ -19,7 +19,7 @@ use_filter = false font_data = ExtResource( 2 ) _sections_unfolded = [ "Font", "Settings" ] -[node name="Stats" type="MarginContainer" index="0"] +[node name="Stats" type="MarginContainer"] anchor_left = 0.0 anchor_top = 0.5 diff --git a/Tetrominos/TetroT.gd b/Tetrominos/TetroT.gd index 81bd34e..79dc014 100644 --- a/Tetrominos/TetroT.gd +++ b/Tetrominos/TetroT.gd @@ -8,13 +8,8 @@ const T_SLOT = [ ] func rotate(direction): - if .rotate(direction): - detect_t_spin() - return true - return false - -func detect_t_spin(): - if t_spin != T_SPIN: + var rotation_point = .rotate(direction) + if rotation_point and t_spin != T_SPIN: var center = to_global(minoes[0].translation) var a = not grid_map.is_free_cell(center + T_SLOT[orientation]) var b = not grid_map.is_free_cell(center + T_SLOT[(1+orientation)%4]) @@ -23,4 +18,8 @@ func detect_t_spin(): if a and b and (c or d): t_spin = T_SPIN elif c and d and (a or b): - t_spin = MINI_T_SPIN \ No newline at end of file + if rotation_point == 5: + t_spin = T_SPIN + else: + t_spin = MINI_T_SPIN + return rotation_point \ No newline at end of file diff --git a/Tetrominos/Tetromino.gd b/Tetrominos/Tetromino.gd index c409da1..29ef46f 100644 --- a/Tetrominos/Tetromino.gd +++ b/Tetrominos/Tetromino.gd @@ -113,14 +113,14 @@ func move(movement): func rotate(direction): var rotated_positions = rotated_positions(direction) var movements = SUPER_ROTATION_SYSTEM[orientation][direction] - for movement in movements: - if grid_map.possible_positions(rotated_positions, movement): + for i in range(movements.size()): + if grid_map.possible_positions(rotated_positions, movements[i]): orientation -= direction orientation %= NB_MINOES apply_positions(rotated_positions) - translate(movement) - return true - return false + translate(movements[i]) + return i+1 + return 0 func emit_trail(emit): var trail