diff --git a/Camera2DScript.gd b/Camera2DScript.gd new file mode 100644 index 0000000..4caaf08 --- /dev/null +++ b/Camera2DScript.gd @@ -0,0 +1,17 @@ +extends Camera2D + +const TARGET_MIN_DIM = 800.0 + +# Called when the node enters the scene tree for the first time. +func _ready(): + pass # Replace with function body. + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + var viewport_size = get_viewport_rect().size + var min_xy = viewport_size.x if viewport_size.x < viewport_size.y else viewport_size.y + var ratio = min_xy / TARGET_MIN_DIM + zoom.x += (ratio - zoom.x) * 0.005 + zoom.y = zoom.x + print_debug(scale) diff --git a/PlayerCharacterBody2D.gd b/PlayerCharacterBody2D.gd index 2eeed1b..7113e6b 100644 --- a/PlayerCharacterBody2D.gd +++ b/PlayerCharacterBody2D.gd @@ -18,11 +18,11 @@ var gravity = ProjectSettings.get_setting("physics/2d/default_gravity") var health = 5 var hurt_timer = 0.0 -@onready var text_label = $RichTextLabel +@onready var text_label = $TimerLabel var text_timer = 0.0 var text_format = "%.1f" -@onready var health_label = $RichTextLabel2 +@onready var health_label = $HPLabel var health_text_format = "%d" @onready var self_sprite = $Sprite2D @@ -39,11 +39,21 @@ var title_timer = 5.0 @onready var touch_left = $LeftTouchButton @onready var touch_right = $RightTouchButton +@onready var jump_label = $JumpTouchButton/JumpLabel +@onready var left_label = $LeftTouchButton/LeftLabel +@onready var right_label = $RightTouchButton/RightLabel + func _ready(): self_sprite.self_modulate = DEFAULT_COLOR - health_label.add_text(health_text_format % health) + health_label.text = health_text_format % health title_text.add_theme_font_size_override("normal_font_size", 40) title_text.add_text("LD54 - Box Survival\nBy: BurnedKirby\nMade in Godot\nWAD or Touch to move") + var somewhat_transparent_color = Color(1, 1, 1, 0.3) + text_label.label_settings.font_color = somewhat_transparent_color + health_label.label_settings.font_color = somewhat_transparent_color + jump_label.label_settings.font_color = somewhat_transparent_color + left_label.label_settings.font_color = somewhat_transparent_color + right_label.label_settings.font_color = somewhat_transparent_color func _physics_process(delta): if title_timer > 0.0: @@ -51,13 +61,18 @@ func _physics_process(delta): if title_timer < 0.0: title_timer = 0.0 title_text.get_parent().remove_child(title_text) + var white = Color(1, 1, 1, 1) + text_label.label_settings.font_color = white + health_label.label_settings.font_color = white + jump_label.label_settings.font_color = white + left_label.label_settings.font_color = white + right_label.label_settings.font_color = white if health <= 0: return text_timer += delta - text_label.clear() - text_label.add_text(text_format % text_timer) + text_label.text = text_format % text_timer # Add the gravity. if not is_on_floor(): @@ -101,8 +116,7 @@ func damaged(projectile): spawn_particle(projectile_color) if hurt_timer == 0.0: health -= 1 - health_label.clear() - health_label.add_text(health_text_format % health) + health_label.text = health_text_format % health self_sprite.self_modulate = HURT_COLOR hurt_timer = HURT_TIME hit_sfx.play() diff --git a/player.tscn b/player.tscn index ad1884c..5b44a77 100644 --- a/player.tscn +++ b/player.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=8 format=3 uid="uid://dv8hwks0xe3c0"] +[gd_scene load_steps=14 format=3 uid="uid://dv8hwks0xe3c0"] [ext_resource type="Script" path="res://PlayerCharacterBody2D.gd" id="1_8l13s"] +[ext_resource type="Script" path="res://Camera2DScript.gd" id="2_hpvt4"] [ext_resource type="AudioStream" uid="uid://b88dh38cr8v6o" path="res://res/jump.ogg" id="2_ix2ut"] [ext_resource type="AudioStream" uid="uid://jfrsvixicrf" path="res://res/hit.ogg" id="3_gq63f"] @@ -10,16 +11,30 @@ size = Vector2(40, 40) [sub_resource type="CanvasTexture" id="CanvasTexture_ruce8"] [sub_resource type="Gradient" id="Gradient_v7mm3"] -colors = PackedColorArray(1, 1, 1, 0.454902, 1, 1, 1, 0) +offsets = PackedFloat32Array(0.524194, 1) +colors = PackedColorArray(1, 1, 1, 0, 1, 1, 1, 0.117647) [sub_resource type="GradientTexture2D" id="GradientTexture2D_iin72"] gradient = SubResource("Gradient_v7mm3") -width = 128 -height = 128 +width = 256 +height = 256 fill = 1 fill_from = Vector2(0.5, 0.5) fill_to = Vector2(1, 0.5) +[sub_resource type="LabelSettings" id="LabelSettings_2gn5h"] +font_size = 30 + +[sub_resource type="LabelSettings" id="LabelSettings_wp0cg"] +font_size = 30 + +[sub_resource type="LabelSettings" id="LabelSettings_wxt3j"] +font_size = 30 + +[sub_resource type="LabelSettings" id="LabelSettings_oauio"] + +[sub_resource type="LabelSettings" id="LabelSettings_vkr7b"] + [node name="CharacterBody2D" type="CharacterBody2D"] position = Vector2(590, 561) collision_layer = 3 @@ -34,55 +49,60 @@ scale = Vector2(40, 40) texture = SubResource("CanvasTexture_ruce8") [node name="JumpTouchButton" type="TouchScreenButton" parent="."] -position = Vector2(-64, -159) +position = Vector2(-127, -279) texture_normal = SubResource("GradientTexture2D_iin72") action = "jump" -[node name="Label" type="Label" parent="JumpTouchButton"] -offset_left = 42.0 -offset_top = 52.0 -offset_right = 83.0 -offset_bottom = 75.0 +[node name="JumpLabel" type="Label" parent="JumpTouchButton"] +offset_left = 89.0 +offset_top = 105.0 +offset_right = 165.0 +offset_bottom = 147.0 text = "Jump" +label_settings = SubResource("LabelSettings_2gn5h") [node name="RightTouchButton" type="TouchScreenButton" parent="."] -position = Vector2(53, -60) +position = Vector2(23, -20) texture_normal = SubResource("GradientTexture2D_iin72") action = "right" -[node name="Label" type="Label" parent="RightTouchButton"] -offset_left = 43.0 -offset_top = 53.0 -offset_right = 84.0 -offset_bottom = 76.0 +[node name="RightLabel" type="Label" parent="RightTouchButton"] +offset_left = 90.0 +offset_top = 106.0 +offset_right = 165.0 +offset_bottom = 148.0 text = "Right" +label_settings = SubResource("LabelSettings_wp0cg") [node name="LeftTouchButton" type="TouchScreenButton" parent="."] -position = Vector2(-184, -60) +position = Vector2(-279, -20) texture_normal = SubResource("GradientTexture2D_iin72") action = "left" -[node name="Label" type="Label" parent="LeftTouchButton"] -offset_left = 47.0 -offset_top = 53.0 -offset_right = 88.0 -offset_bottom = 76.0 +[node name="LeftLabel" type="Label" parent="LeftTouchButton"] +offset_left = 100.0 +offset_top = 99.0 +offset_right = 156.0 +offset_bottom = 141.0 text = "Left" +label_settings = SubResource("LabelSettings_wxt3j") [node name="Camera2D" type="Camera2D" parent="."] -zoom = Vector2(1.4, 1.4) +script = ExtResource("2_hpvt4") -[node name="RichTextLabel" type="RichTextLabel" parent="."] -offset_left = 35.0 -offset_top = 36.0 -offset_right = 151.0 -offset_bottom = 76.0 +[node name="TimerLabel" type="Label" parent="."] +offset_left = -23.0 +offset_top = 50.0 +offset_right = 70.0 +offset_bottom = 122.0 +label_settings = SubResource("LabelSettings_oauio") -[node name="RichTextLabel2" type="RichTextLabel" parent="."] -offset_left = -61.0 -offset_top = -62.0 -offset_right = -21.0 -offset_bottom = -22.0 +[node name="HPLabel" type="Label" parent="."] +offset_left = -8.0 +offset_top = 23.0 +offset_right = 7.0 +offset_bottom = 47.0 +label_settings = SubResource("LabelSettings_vkr7b") [node name="JumpSFX" type="AudioStreamPlayer" parent="."] stream = ExtResource("2_ix2ut") diff --git a/project.godot b/project.godot index f401e06..92646c3 100644 --- a/project.godot +++ b/project.godot @@ -21,8 +21,8 @@ driver/output_latency.web=100 [display] -window/size/viewport_width=550 -window/size/viewport_height=550 +window/size/viewport_width=800 +window/size/viewport_height=800 window/size/mode=2 window/size/resizable=false