From e40dd9305f3f41b83e2523ace693d468c29485a9 Mon Sep 17 00:00:00 2001 From: adrienmalin <41926238+adrienmalin@users.noreply.github.com> Date: Wed, 2 Jan 2019 03:50:11 +0100 Subject: [PATCH] FlashText3 --- FlashText.gd | 13 +++++++++++++ Main.gd | 46 +++++++++++++++++++++++++++------------------- Main.tscn | 10 +++++----- Stats.gd | 2 ++ 4 files changed, 47 insertions(+), 24 deletions(-) create mode 100644 FlashText.gd diff --git a/FlashText.gd b/FlashText.gd new file mode 100644 index 0000000..f59c384 --- /dev/null +++ b/FlashText.gd @@ -0,0 +1,13 @@ +extends Control + +var texts = PoolStringArray() + +func print(text): + texts.append(text) + if texts.size() > 2: + texts.remove(0) + $Label.text = texts.join("\n") + $AnimationPlayer.play("Flash") + +func _on_AnimationPlayer_animation_finished(anim_name): + texts.resize(0) \ No newline at end of file diff --git a/Main.gd b/Main.gd index 677170e..95602d0 100644 --- a/Main.gd +++ b/Main.gd @@ -66,7 +66,7 @@ func new_game(): func new_level(): $Stats.new_level() - flash_print("Level\n%d"%$Stats.level) + $FlashText.print("Level\n%d"%$Stats.level) $DropTimer.wait_time = pow(0.8 - (($Stats.level - 1) * 0.007), $Stats.level - 1) if $Stats.level > 15: $LockDelay.wait_time = 0.5 * pow(0.9, $Stats.level-15) @@ -158,17 +158,31 @@ func _on_LockDelay_timeout(): lock() func lock(): + var score $GridMap.lock(current_piece) remove_child(current_piece) var lines_cleared = $GridMap.clear_lines() if lines_cleared or current_piece.t_spin: - var new_score = SCORES[lines_cleared][current_piece.t_spin] - $Stats.update_score(new_score) + score = SCORES[lines_cleared][current_piece.t_spin] + $Stats.update_score(score) if current_piece.t_spin: - flash_print(T_SPIN_NAMES[current_piece.t_spin]) + $FlashText.print(T_SPIN_NAMES[current_piece.t_spin]) if lines_cleared: - flash_print(LINES_CLEARED_NAMES[lines_cleared]) - flash_print(str(100*new_score)) + $FlashText.print(LINES_CLEARED_NAMES[lines_cleared]) + $FlashText.print(str(100*score)) + + # Combos + if lines_cleared: + $Stats.combos += 1 + if $Stats.combos > 0: + $Stats.score += (20 if lines_cleared==1 else 50) * $Stats.combos * $Stats.level + $Stats/HBC/VBC1/Score.text = str($Stats.score) + if $Stats.combos == 1: + $FlashText.print("COMBO") + else: + $FlashText.print("COMBO x%d"%$Stats.combos) + + # SFX if lines_cleared == Tetromino.NB_MINOES: for channel in LINE_CLEAR_MIDI_CHANNELS: $MidiPlayer.channel_status[channel].vomume = 127 @@ -179,10 +193,15 @@ func lock(): $LineCLearTimer.wait_time = 0.43 $MidiPlayer.unmute_channels(LINE_CLEAR_MIDI_CHANNELS) $LineCLearTimer.start() + else: + $Stats.combos = -1 if $Stats.goal <= 0: new_level() new_piece() +func _on_LineCLearTimer_timeout(): + $MidiPlayer.mute_channels(LINE_CLEAR_MIDI_CHANNELS) + func hold(): if not current_piece_held: current_piece_held = true @@ -211,7 +230,7 @@ func resume(): current_piece.visible = true if held_piece: held_piece.visible = true - flash_print("GO!") + $FlashText.print("GO!") func pause(text = "PAUSE"): playing = false @@ -226,7 +245,7 @@ func pause(text = "PAUSE"): if held_piece: held_piece.visible = false $MidiPlayer.stop() - flash_print(text) + $FlashText.print(text) func game_over(): pause("GAME OVER") @@ -234,14 +253,3 @@ func game_over(): func _notification(what): if what == MainLoop.NOTIFICATION_WM_FOCUS_OUT: pause() - -func _on_LineCLearTimer_timeout(): - $MidiPlayer.mute_channels(LINE_CLEAR_MIDI_CHANNELS) - -func flash_print(text): - $FlashText/Label.text += text + "\n" - if not $FlashText/AnimationPlayer.is_playing(): - $FlashText/AnimationPlayer.play("Flash") - -func _on_AnimationPlayer_animation_finished(anim_name): - $FlashText/Label.text = "" diff --git a/Main.tscn b/Main.tscn index d03ee9f..b1bb656 100644 --- a/Main.tscn +++ b/Main.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=15 format=2] +[gd_scene load_steps=16 format=2] [ext_resource path="res://starmap_g8k.jpg" type="Texture" id=1] [ext_resource path="res://Main.gd" type="Script" id=2] @@ -6,7 +6,8 @@ [ext_resource path="res://GridMap.gd" type="Script" id=4] [ext_resource path="res://midi/MidiPlayer.tscn" type="PackedScene" id=5] [ext_resource path="res://Stats.tscn" type="PackedScene" id=6] -[ext_resource path="res://fonts/525-ROUN.TTF" type="DynamicFontData" id=7] +[ext_resource path="res://FlashText.gd" type="Script" id=7] +[ext_resource path="res://fonts/525-ROUN.TTF" type="DynamicFontData" id=8] [sub_resource type="PanoramaSky" id=1] @@ -170,7 +171,7 @@ subdivide_depth = 0 size = 50 use_mipmaps = true use_filter = false -font_data = ExtResource( 7 ) +font_data = ExtResource( 8 ) _sections_unfolded = [ "Font", "Settings" ] [sub_resource type="Animation" id=7] @@ -401,6 +402,7 @@ mouse_filter = 0 mouse_default_cursor_shape = 0 size_flags_horizontal = 1 size_flags_vertical = 1 +script = ExtResource( 7 ) [node name="Label" type="Label" parent="FlashText" index="0"] @@ -448,8 +450,6 @@ _sections_unfolded = [ "Playback Options" ] [connection signal="timeout" from="LineCLearTimer" to="." method="_on_LineCLearTimer_timeout"] -[connection signal="animation_finished" from="FlashText/AnimationPlayer" to="." method="_on_AnimationPlayer_animation_finished"] - [connection signal="animation_finished" from="FlashText/AnimationPlayer" to="FlashText" method="_on_AnimationPlayer_animation_finished"] diff --git a/Stats.gd b/Stats.gd index bf3a5c3..49e2067 100644 --- a/Stats.gd +++ b/Stats.gd @@ -7,6 +7,7 @@ var goal var score var high_score var time +var combos func _ready(): var save_game = File.new() @@ -23,6 +24,7 @@ func new_game(): goal = 0 score = 0 time = 0 + combos = -1 func new_level(): level += 1