diff --git a/Main.gd b/Main.gd index ffae056..da9b1fc 100644 --- a/Main.gd +++ b/Main.gd @@ -42,11 +42,6 @@ var autoshift_action = "" var playing = true -var level -var goal -var score -var time - func random_piece(): if not random_bag: random_bag = [ @@ -63,22 +58,15 @@ func _ready(): new_game() func new_game(): - level = 0 - goal = 0 - score = 0 - time = 0 + $Stats.visible = true + $Stats.new_game() resume() new_level() new_piece() func new_level(): - level += 1 - goal += 5 * level - $DropTimer.wait_time = pow(0.8 - ((level - 1) * 0.007), level - 1) - if level > 15: - $LockDelay.wait_time = 0.5 * pow(0.9, level-15) - $Stats/HBC/VBC1/Level.text = str(level) - $Stats/HBC/VBC1/Goal.text = str(goal) + $Stats.new_level() + $DropTimer.wait_time = pow(0.8 - (($Stats.level - 1) * 0.007), $Stats.level - 1) func new_piece(): current_piece = next_piece @@ -162,11 +150,8 @@ func lock(): remove_child(current_piece) var lines_cleared = $GridMap.clear_lines() if lines_cleared or current_piece.t_spin: - var s = SCORES[lines_cleared][current_piece.t_spin] - score += 100 * s - goal -= s - print_temp(T_SPIN_NAMES[current_piece.t_spin] + ' ' + LINES_CLEARED_NAMES[lines_cleared] + "\nScore " + str(score)) - $Stats/HBC/VBC1/Score.text = str(score) + $Stats.update_score(SCORES[lines_cleared][current_piece.t_spin]) + print_temp(T_SPIN_NAMES[current_piece.t_spin] + ' ' + LINES_CLEARED_NAMES[lines_cleared]) if lines_cleared == Tetromino.NB_MINOES: for channel in LINE_CLEAR_MIDI_CHANNELS: $MidiPlayer.channel_status[channel].vomume = 127 @@ -177,7 +162,7 @@ func lock(): $LineCLearTimer.wait_time = 0.43 $MidiPlayer.unmute_channels(LINE_CLEAR_MIDI_CHANNELS) $LineCLearTimer.start() - if goal <= 0: + if $Stats.goal <= 0: new_level() new_piece() @@ -200,8 +185,8 @@ func resume(): playing = true $DropTimer.start() $LockDelay.start() - $Clock.start() - time = OS.get_system_time_secs() - time + $Stats.time = OS.get_system_time_secs() - $Stats.time + $Stats/Clock.start() $MidiPlayer.resume() $MidiPlayer.mute_channels(LINE_CLEAR_MIDI_CHANNELS) print_temp("RESUME") @@ -210,8 +195,8 @@ func pause(): playing = false $DropTimer.stop() $LockDelay.stop() - $Clock.stop() - time = OS.get_system_time_secs() - time + $Stats/Clock.stop() + $Stats.time = OS.get_system_time_secs() - $Stats.time $MidiPlayer.stop() print_temp("PAUSE") @@ -220,21 +205,14 @@ func game_over(): print_temp("GAME OVER") func _notification(what): - if what == MainLoop.NOTIFICATION_WM_FOCUS_OUT: - pause() - if what == MainLoop.NOTIFICATION_WM_FOCUS_IN: - resume() + 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) func print_temp(text): #$HUD/HBC/TempText.text = text - print(text) - -func _on_Clock_timeout(): - var time_elapsed = OS.get_system_time_secs() - time - var seconds = time_elapsed % 60 - var minutes = int(time_elapsed/60) % 60 - var hours = int(time_elapsed/3600) - $Stats/HBC/VBC1/Time.text = str(hours) + ":%02d"%minutes + ":%02d"%seconds + print(text) \ No newline at end of file diff --git a/Stats.gd b/Stats.gd new file mode 100644 index 0000000..070c8e3 --- /dev/null +++ b/Stats.gd @@ -0,0 +1,58 @@ +extends MarginContainer + +const password= "TETRIS 3000" + +var level +var goal +var score +var high_score +var time + +func _ready(): + var save_game = File.new() + if not save_game.file_exists("user://high_score.save"): + high_score = 0 + else: + save_game.open_encrypted_with_pass("user://high_score.save", File.READ, password) + high_score = int(save_game.get_line()) + $HBC/VBC1/HighScore.text = str(high_score) + save_game.close() + +func new_game(): + level = 0 + goal = 0 + score = 0 + time = 0 + +func new_level(): + level += 1 + goal += 5 * level + if level > 15: + $LockDelay.wait_time = 0.5 * pow(0.9, level-15) + $HBC/VBC1/Level.text = str(level) + $HBC/VBC1/Goal.text = str(goal) + +func update_score(new_score): + score += 100 * new_score + $HBC/VBC1/Score.text = str(score) + goal -= new_score + $HBC/VBC1/Goal.text = str(goal) + if score > high_score: + high_score = score + $HBC/VBC1/HighScore.text = str(high_score) + +func _on_Clock_timeout(): + var time_elapsed = OS.get_system_time_secs() - time + var seconds = time_elapsed % 60 + var minutes = int(time_elapsed/60) % 60 + var hours = int(time_elapsed/3600) + $HBC/VBC1/Time.text = str(hours) + ":%02d"%minutes + ":%02d"%seconds + + +func _notification(what): + if what == MainLoop.NOTIFICATION_WM_QUIT_REQUEST: + var save_game = File.new() + save_game.open_encrypted_with_pass("user://high_score.save", File.WRITE, password) + save_game.store_line(str(high_score)) + save_game.close() + get_tree().quit() \ No newline at end of file diff --git a/Stats.tscn b/Stats.tscn index de925b1..e20a584 100644 --- a/Stats.tscn +++ b/Stats.tscn @@ -1,30 +1,40 @@ -[gd_scene load_steps=3 format=2] +[gd_scene load_steps=5 format=2] -[ext_resource path="res://impact.ttf" type="DynamicFontData" id=1] +[ext_resource path="res://Stats.gd" type="Script" id=1] +[ext_resource path="res://impact.ttf" type="DynamicFontData" id=2] + +[sub_resource type="DynamicFont" id=2] + +size = 16 +use_mipmaps = false +use_filter = false +font_data = ExtResource( 2 ) +_sections_unfolded = [ "Font", "Settings" ] [sub_resource type="DynamicFont" id=1] -size = 12 +size = 14 use_mipmaps = false use_filter = false -font_data = ExtResource( 1 ) +font_data = ExtResource( 2 ) _sections_unfolded = [ "Font", "Settings" ] -[node name="Stats" type="MarginContainer"] +[node name="Stats" type="MarginContainer" index="0"] anchor_left = 0.0 -anchor_top = 1.0 +anchor_top = 0.5 anchor_right = 0.0 -anchor_bottom = 1.0 +anchor_bottom = 0.5 margin_left = 20.0 -margin_top = -132.0 -margin_right = 78.0 +margin_right = 134.0 +margin_bottom = 51.5 rect_pivot_offset = Vector2( 0, 0 ) rect_clip_content = false mouse_filter = 0 mouse_default_cursor_shape = 0 size_flags_horizontal = 0 size_flags_vertical = 0 +script = ExtResource( 1 ) _sections_unfolded = [ "Anchor", "Margin", "Size Flags" ] [node name="HBC" type="HBoxContainer" parent="." index="0"] @@ -34,8 +44,8 @@ anchor_top = 0.0 anchor_right = 0.0 anchor_bottom = 0.0 margin_left = 16.0 -margin_right = 112.0 -margin_bottom = 112.0 +margin_right = 134.0 +margin_bottom = 93.0 rect_pivot_offset = Vector2( 0, 0 ) rect_clip_content = false mouse_filter = 1 @@ -51,16 +61,17 @@ anchor_left = 0.0 anchor_top = 0.0 anchor_right = 0.0 anchor_bottom = 0.0 -margin_right = 54.0 -margin_bottom = 112.0 +margin_right = 64.0 +margin_bottom = 93.0 rect_pivot_offset = Vector2( 0, 0 ) rect_clip_content = false mouse_filter = 1 mouse_default_cursor_shape = 0 size_flags_horizontal = 0 size_flags_vertical = 0 +custom_constants/separation = 0 alignment = 0 -_sections_unfolded = [ "Anchor", "Margin", "Size Flags" ] +_sections_unfolded = [ "Anchor", "Margin", "Size Flags", "custom_constants" ] [node name="Label" type="Label" parent="HBC/VBC0" index="0"] @@ -68,15 +79,15 @@ anchor_left = 0.0 anchor_top = 0.0 anchor_right = 0.0 anchor_bottom = 0.0 -margin_right = 54.0 -margin_bottom = 16.0 +margin_right = 64.0 +margin_bottom = 21.0 rect_pivot_offset = Vector2( 0, 0 ) rect_clip_content = false mouse_filter = 2 mouse_default_cursor_shape = 0 size_flags_horizontal = 1 size_flags_vertical = 4 -custom_fonts/font = SubResource( 1 ) +custom_fonts/font = SubResource( 2 ) custom_colors/font_color = Color( 0.517647, 0.756863, 1, 1 ) text = "Score:" percent_visible = 1.0 @@ -89,9 +100,9 @@ anchor_left = 0.0 anchor_top = 0.0 anchor_right = 0.0 anchor_bottom = 0.0 -margin_top = 24.0 -margin_right = 54.0 -margin_bottom = 40.0 +margin_top = 21.0 +margin_right = 64.0 +margin_bottom = 39.0 rect_pivot_offset = Vector2( 0, 0 ) rect_clip_content = false mouse_filter = 2 @@ -111,9 +122,9 @@ anchor_left = 0.0 anchor_top = 0.0 anchor_right = 0.0 anchor_bottom = 0.0 -margin_top = 48.0 -margin_right = 54.0 -margin_bottom = 64.0 +margin_top = 39.0 +margin_right = 64.0 +margin_bottom = 57.0 rect_pivot_offset = Vector2( 0, 0 ) rect_clip_content = false mouse_filter = 2 @@ -133,9 +144,9 @@ anchor_left = 0.0 anchor_top = 0.0 anchor_right = 0.0 anchor_bottom = 0.0 -margin_top = 72.0 -margin_right = 54.0 -margin_bottom = 88.0 +margin_top = 57.0 +margin_right = 64.0 +margin_bottom = 75.0 rect_pivot_offset = Vector2( 0, 0 ) rect_clip_content = false mouse_filter = 2 @@ -155,9 +166,9 @@ anchor_left = 0.0 anchor_top = 0.0 anchor_right = 0.0 anchor_bottom = 0.0 -margin_top = 96.0 -margin_right = 54.0 -margin_bottom = 112.0 +margin_top = 75.0 +margin_right = 64.0 +margin_bottom = 93.0 rect_pivot_offset = Vector2( 0, 0 ) rect_clip_content = false mouse_filter = 2 @@ -177,17 +188,18 @@ anchor_left = 0.0 anchor_top = 0.0 anchor_right = 0.0 anchor_bottom = 0.0 -margin_left = 62.0 -margin_right = 96.0 -margin_bottom = 112.0 +margin_left = 72.0 +margin_right = 118.0 +margin_bottom = 93.0 rect_pivot_offset = Vector2( 0, 0 ) rect_clip_content = false mouse_filter = 1 mouse_default_cursor_shape = 0 size_flags_horizontal = 0 size_flags_vertical = 0 +custom_constants/separation = 0 alignment = 0 -_sections_unfolded = [ "Anchor", "Grow Direction", "Margin", "Size Flags", "Visibility" ] +_sections_unfolded = [ "Anchor", "Grow Direction", "Margin", "Size Flags", "Visibility", "custom_constants" ] [node name="Score" type="Label" parent="HBC/VBC1" index="0"] @@ -195,15 +207,15 @@ anchor_left = 0.0 anchor_top = 0.0 anchor_right = 0.0 anchor_bottom = 0.0 -margin_right = 34.0 -margin_bottom = 16.0 +margin_right = 46.0 +margin_bottom = 21.0 rect_pivot_offset = Vector2( 0, 0 ) rect_clip_content = false mouse_filter = 2 mouse_default_cursor_shape = 0 size_flags_horizontal = 1 size_flags_vertical = 4 -custom_fonts/font = SubResource( 1 ) +custom_fonts/font = SubResource( 2 ) custom_colors/font_color = Color( 0.517647, 0.756863, 1, 1 ) text = "0" percent_visible = 1.0 @@ -216,9 +228,9 @@ anchor_left = 0.0 anchor_top = 0.0 anchor_right = 0.0 anchor_bottom = 0.0 -margin_top = 24.0 -margin_right = 34.0 -margin_bottom = 40.0 +margin_top = 21.0 +margin_right = 46.0 +margin_bottom = 39.0 rect_pivot_offset = Vector2( 0, 0 ) rect_clip_content = false mouse_filter = 2 @@ -238,9 +250,9 @@ anchor_left = 0.0 anchor_top = 0.0 anchor_right = 0.0 anchor_bottom = 0.0 -margin_top = 48.0 -margin_right = 34.0 -margin_bottom = 64.0 +margin_top = 39.0 +margin_right = 46.0 +margin_bottom = 57.0 rect_pivot_offset = Vector2( 0, 0 ) rect_clip_content = false mouse_filter = 2 @@ -260,9 +272,9 @@ anchor_left = 0.0 anchor_top = 0.0 anchor_right = 0.0 anchor_bottom = 0.0 -margin_top = 72.0 -margin_right = 34.0 -margin_bottom = 88.0 +margin_top = 57.0 +margin_right = 46.0 +margin_bottom = 75.0 rect_pivot_offset = Vector2( 0, 0 ) rect_clip_content = false mouse_filter = 2 @@ -282,9 +294,9 @@ anchor_left = 0.0 anchor_top = 0.0 anchor_right = 0.0 anchor_bottom = 0.0 -margin_top = 96.0 -margin_right = 34.0 -margin_bottom = 112.0 +margin_top = 75.0 +margin_right = 46.0 +margin_bottom = 93.0 rect_pivot_offset = Vector2( 0, 0 ) rect_clip_content = false mouse_filter = 2 @@ -297,5 +309,15 @@ text = "0" percent_visible = 1.0 lines_skipped = 0 max_lines_visible = -1 +_sections_unfolded = [ "custom_fonts" ] + +[node name="Clock" type="Timer" parent="." index="1"] + +process_mode = 1 +wait_time = 1.0 +one_shot = false +autostart = false + +[connection signal="timeout" from="Clock" to="." method="_on_Clock_timeout"] diff --git a/Tetrominos/DynamicFont.tres b/Tetrominos/DynamicFont.tres deleted file mode 100644 index 5e333cd..0000000 --- a/Tetrominos/DynamicFont.tres +++ /dev/null @@ -1,12 +0,0 @@ -[gd_resource type="DynamicFont" load_steps=2 format=2] - -[ext_resource path="res://impact.ttf" type="DynamicFontData" id=1] - -[resource] - -size = 14 -use_mipmaps = false -use_filter = false -font_data = ExtResource( 1 ) -_sections_unfolded = [ "Font", "Settings" ] - diff --git a/Tetrominos/Mino/Mino.tscn b/Tetrominos/Mino/Mino.tscn index 0f3ef90..0754a35 100644 --- a/Tetrominos/Mino/Mino.tscn +++ b/Tetrominos/Mino/Mino.tscn @@ -162,8 +162,9 @@ subdivide_width = 0 subdivide_height = 0 subdivide_depth = 0 -[node name="Mino" type="Spatial" index="0"] +[node name="Mino" type="Spatial"] +transform = Transform( 0.997027, 0, 0, 0, 0.997027, 0, 0, 0, 0.997027, 0, 0, 0 ) _sections_unfolded = [ "Pause", "Transform", "Visibility" ] [node name="MinoMesh" parent="." index="0" instance=ExtResource( 1 )] diff --git a/Tetrominos/Mino/MinoMaterial.tres b/Tetrominos/Mino/MinoMaterial.tres index 41bde27..2184b7f 100644 --- a/Tetrominos/Mino/MinoMaterial.tres +++ b/Tetrominos/Mino/MinoMaterial.tres @@ -1,4 +1,6 @@ -[gd_resource type="SpatialMaterial" format=2] +[gd_resource type="SpatialMaterial" load_steps=2 format=2] + +[ext_resource path="res://Tetrominos/Mino/glass.jpg" type="Texture" id=1] [resource] @@ -24,9 +26,10 @@ params_billboard_mode = 0 params_grow = false params_use_alpha_scissor = false albedo_color = Color( 0.601563, 0.775878, 1, 0.162157 ) -metallic = 0.4 +metallic = 1.0 metallic_specular = 1.0 -metallic_texture_channel = 0 +metallic_texture = ExtResource( 1 ) +metallic_texture_channel = 4 roughness = 0.46 roughness_texture_channel = 0 emission_enabled = true @@ -55,5 +58,5 @@ uv2_triplanar_sharpness = 1.0 proximity_fade_enable = true proximity_fade_distance = 1.0 distance_fade_enable = false -_sections_unfolded = [ "Albedo", "Emission", "NormalMap", "Proximity Fade" ] +_sections_unfolded = [ "Albedo", "Emission", "Metallic", "NormalMap", "Proximity Fade" ] diff --git a/Tetrominos/Mino/glass.jpg b/Tetrominos/Mino/glass.jpg new file mode 100644 index 0000000..102394e Binary files /dev/null and b/Tetrominos/Mino/glass.jpg differ diff --git a/Tetrominos/Mino/glass.jpg.import b/Tetrominos/Mino/glass.jpg.import new file mode 100644 index 0000000..45d71f0 --- /dev/null +++ b/Tetrominos/Mino/glass.jpg.import @@ -0,0 +1,30 @@ +[remap] + +importer="texture" +type="StreamTexture" +path.s3tc="res://.import/glass.jpg-80b6305d22902972419fc8ecbe408eb8.s3tc.stex" +path.etc2="res://.import/glass.jpg-80b6305d22902972419fc8ecbe408eb8.etc2.stex" + +[deps] + +source_file="res://Tetrominos/Mino/glass.jpg" +dest_files=[ "res://.import/glass.jpg-80b6305d22902972419fc8ecbe408eb8.s3tc.stex", "res://.import/glass.jpg-80b6305d22902972419fc8ecbe408eb8.etc2.stex" ] + +[params] + +compress/mode=2 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/normal_map=0 +flags/repeat=true +flags/filter=true +flags/mipmaps=true +flags/anisotropic=false +flags/srgb=1 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +stream=false +size_limit=0 +detect_3d=false +svg/scale=1.0 diff --git a/WorldEnvironment.tscn b/WorldEnvironment.tscn index 8f036df..f4fc010 100644 --- a/WorldEnvironment.tscn +++ b/WorldEnvironment.tscn @@ -350,12 +350,7 @@ blend_times = [ ] [node name="Stats" parent="." index="13" instance=ExtResource( 6 )] -[node name="Clock" type="Timer" parent="." index="14"] - -process_mode = 1 -wait_time = 1.0 -one_shot = false -autostart = false +visible = false [connection signal="timeout" from="DropTimer" to="." method="_on_DropTimer_timeout"] @@ -367,6 +362,4 @@ autostart = false [connection signal="timeout" from="LineCLearTimer" to="." method="_on_LineCLearTimer_timeout"] -[connection signal="timeout" from="Clock" to="." method="_on_Clock_timeout"] -