Mejoras en el manejo del personaje, enemigo de pruebas
This commit is contained in:
1 parent
1b797a3e90
commit
e93efc533b
21 files changed
+774
-85
No files matched your search
@@ -0,0 +1,29 @@
|
||||
extends CanvasLayer
|
||||
|
||||
|
||||
## Minimal player HUD.
|
||||
##
|
||||
## This is a CanvasLayer on purpose: its coordinates belong to the camera
|
||||
## viewport, not to the level. Therefore (18, 18) always means "18 pixels from
|
||||
## the top-left corner currently visible by the camera", even while the player
|
||||
## and Camera2D move through the world.
|
||||
|
||||
@onready var health_bar: ProgressBar = $HUD/HealthBar
|
||||
@onready var health_label: Label = $HUD/HealthBar/HealthLabel
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
var player: Node = get_parent()
|
||||
if player == null or not player.has_signal(&"health_changed"):
|
||||
push_error("PlayerHealthHUD must be a child of a Player with health_changed signal.")
|
||||
return
|
||||
|
||||
# Child _ready() runs before Player._ready(). We connect here first and the
|
||||
# Player will emit its initial health value a moment later during its _ready().
|
||||
player.connect(&"health_changed", _on_health_changed)
|
||||
|
||||
|
||||
func _on_health_changed(current_health: int, max_health: int) -> void:
|
||||
health_bar.max_value = float(max_health)
|
||||
health_bar.value = float(current_health)
|
||||
health_label.text = "HP %d / %d" % [current_health, max_health]
|
||||
@@ -0,0 +1 @@
|
||||
uid://djbmxa3ubj4yk
|
||||
@@ -0,0 +1,65 @@
|
||||
[gd_scene load_steps=4 format=3]
|
||||
|
||||
[ext_resource type="Script" path="res://ui/hud/player_health_hud.gd" id="1_hud"]
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="HealthBackground"]
|
||||
bg_color = Color(0.08, 0.08, 0.09, 0.82)
|
||||
border_width_left = 2
|
||||
border_width_top = 2
|
||||
border_width_right = 2
|
||||
border_width_bottom = 2
|
||||
border_color = Color(0.95, 0.95, 0.95, 0.75)
|
||||
corner_radius_top_left = 7
|
||||
corner_radius_top_right = 7
|
||||
corner_radius_bottom_right = 7
|
||||
corner_radius_bottom_left = 7
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="HealthFill"]
|
||||
bg_color = Color(0.72, 0.06, 0.06, 0.92)
|
||||
corner_radius_top_left = 5
|
||||
corner_radius_top_right = 5
|
||||
corner_radius_bottom_right = 5
|
||||
corner_radius_bottom_left = 5
|
||||
|
||||
[node name="PlayerHealthHUD" type="CanvasLayer"]
|
||||
layer = 90
|
||||
script = ExtResource("1_hud")
|
||||
|
||||
[node name="HUD" type="Control" parent="."]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
mouse_filter = 2
|
||||
|
||||
[node name="HealthBar" type="ProgressBar" parent="HUD"]
|
||||
layout_mode = 0
|
||||
offset_left = 18.0
|
||||
offset_top = 18.0
|
||||
offset_right = 278.0
|
||||
offset_bottom = 58.0
|
||||
mouse_filter = 2
|
||||
theme_override_styles/background = SubResource("HealthBackground")
|
||||
theme_override_styles/fill = SubResource("HealthFill")
|
||||
max_value = 5.0
|
||||
value = 5.0
|
||||
show_percentage = false
|
||||
|
||||
[node name="HealthLabel" type="Label" parent="HUD/HealthBar"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
mouse_filter = 2
|
||||
theme_override_colors/font_color = Color(1, 1, 1, 1)
|
||||
theme_override_colors/font_shadow_color = Color(0, 0, 0, 0.9)
|
||||
theme_override_constants/shadow_offset_x = 1
|
||||
theme_override_constants/shadow_offset_y = 1
|
||||
theme_override_font_sizes/font_size = 18
|
||||
text = "HP 5 / 5"
|
||||
horizontal_alignment = 1
|
||||
vertical_alignment = 1
|
||||
@@ -0,0 +1,50 @@
|
||||
extends CanvasLayer
|
||||
|
||||
|
||||
## Controles táctiles provisionales para jugar en móvil.
|
||||
##
|
||||
## Los botones no llaman directamente al Player. En su lugar pulsan y liberan
|
||||
## las mismas acciones del InputMap que ya usa el teclado. De esta forma la
|
||||
## lógica de movimiento/combate sigue teniendo una única fuente de entrada:
|
||||
##
|
||||
## teclado -> InputMap <- controles táctiles
|
||||
## |
|
||||
## Player
|
||||
##
|
||||
## Cuando llegue el arte definitivo, esta escena puede cambiar por completo sin
|
||||
## tocar player.gd mientras conserve estas cuatro acciones.
|
||||
|
||||
@onready var move_left_button: Button = $Controls/MoveLeft
|
||||
@onready var move_right_button: Button = $Controls/MoveRight
|
||||
@onready var jump_button: Button = $Controls/Jump
|
||||
@onready var attack_button: Button = $Controls/Attack
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
_bind_button(move_left_button, &"move_left")
|
||||
_bind_button(move_right_button, &"move_right")
|
||||
_bind_button(jump_button, &"jump")
|
||||
_bind_button(attack_button, &"attack")
|
||||
|
||||
|
||||
func _exit_tree() -> void:
|
||||
# Si la escena cambia mientras un dedo sigue apoyado, Godot puede no llegar
|
||||
# a emitir button_up. Liberamos las acciones para no dejar una tecla virtual
|
||||
# atascada al cargar la siguiente escena.
|
||||
Input.action_release(&"move_left")
|
||||
Input.action_release(&"move_right")
|
||||
Input.action_release(&"jump")
|
||||
Input.action_release(&"attack")
|
||||
|
||||
|
||||
func _bind_button(button: Button, action: StringName) -> void:
|
||||
button.button_down.connect(_press_action.bind(action))
|
||||
button.button_up.connect(_release_action.bind(action))
|
||||
|
||||
|
||||
func _press_action(action: StringName) -> void:
|
||||
Input.action_press(action)
|
||||
|
||||
|
||||
func _release_action(action: StringName) -> void:
|
||||
Input.action_release(action)
|
||||
@@ -0,0 +1 @@
|
||||
uid://2kbajcohyem7
|
||||
@@ -0,0 +1,122 @@
|
||||
[gd_scene load_steps=4 format=3]
|
||||
|
||||
[ext_resource type="Script" path="res://ui/mobile_controls/mobile_controls.gd" id="1_controls"]
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="ButtonNormal"]
|
||||
bg_color = Color(0.65, 0.04, 0.04, 0.28)
|
||||
border_width_left = 3
|
||||
border_width_top = 3
|
||||
border_width_right = 3
|
||||
border_width_bottom = 3
|
||||
border_color = Color(1, 0.15, 0.15, 0.72)
|
||||
corner_radius_top_left = 14
|
||||
corner_radius_top_right = 14
|
||||
corner_radius_bottom_right = 14
|
||||
corner_radius_bottom_left = 14
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="ButtonPressed"]
|
||||
bg_color = Color(0.95, 0.05, 0.05, 0.52)
|
||||
border_width_left = 4
|
||||
border_width_top = 4
|
||||
border_width_right = 4
|
||||
border_width_bottom = 4
|
||||
border_color = Color(1, 0.45, 0.45, 0.95)
|
||||
corner_radius_top_left = 14
|
||||
corner_radius_top_right = 14
|
||||
corner_radius_bottom_right = 14
|
||||
corner_radius_bottom_left = 14
|
||||
|
||||
[node name="MobileControls" type="CanvasLayer"]
|
||||
layer = 100
|
||||
script = ExtResource("1_controls")
|
||||
|
||||
[node name="Controls" type="Control" parent="."]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
mouse_filter = 2
|
||||
|
||||
[node name="MoveLeft" type="Button" parent="Controls"]
|
||||
layout_mode = 0
|
||||
anchor_top = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_left = 34.0
|
||||
offset_top = -132.0
|
||||
offset_right = 134.0
|
||||
offset_bottom = -32.0
|
||||
grow_vertical = 0
|
||||
focus_mode = 0
|
||||
keep_pressed_outside = true
|
||||
theme_override_colors/font_color = Color(1, 1, 1, 0.95)
|
||||
theme_override_colors/font_pressed_color = Color(1, 1, 1, 1)
|
||||
theme_override_font_sizes/font_size = 42
|
||||
theme_override_styles/normal = SubResource("ButtonNormal")
|
||||
theme_override_styles/hover = SubResource("ButtonNormal")
|
||||
theme_override_styles/pressed = SubResource("ButtonPressed")
|
||||
text = "<"
|
||||
|
||||
[node name="MoveRight" type="Button" parent="Controls"]
|
||||
layout_mode = 0
|
||||
anchor_top = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_left = 150.0
|
||||
offset_top = -132.0
|
||||
offset_right = 250.0
|
||||
offset_bottom = -32.0
|
||||
grow_vertical = 0
|
||||
focus_mode = 0
|
||||
keep_pressed_outside = true
|
||||
theme_override_colors/font_color = Color(1, 1, 1, 0.95)
|
||||
theme_override_colors/font_pressed_color = Color(1, 1, 1, 1)
|
||||
theme_override_font_sizes/font_size = 42
|
||||
theme_override_styles/normal = SubResource("ButtonNormal")
|
||||
theme_override_styles/hover = SubResource("ButtonNormal")
|
||||
theme_override_styles/pressed = SubResource("ButtonPressed")
|
||||
text = ">"
|
||||
|
||||
[node name="Jump" type="Button" parent="Controls"]
|
||||
layout_mode = 0
|
||||
anchor_left = 1.0
|
||||
anchor_top = 1.0
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_left = -264.0
|
||||
offset_top = -132.0
|
||||
offset_right = -154.0
|
||||
offset_bottom = -32.0
|
||||
grow_horizontal = 0
|
||||
grow_vertical = 0
|
||||
focus_mode = 0
|
||||
keep_pressed_outside = true
|
||||
theme_override_colors/font_color = Color(1, 1, 1, 0.95)
|
||||
theme_override_colors/font_pressed_color = Color(1, 1, 1, 1)
|
||||
theme_override_font_sizes/font_size = 22
|
||||
theme_override_styles/normal = SubResource("ButtonNormal")
|
||||
theme_override_styles/hover = SubResource("ButtonNormal")
|
||||
theme_override_styles/pressed = SubResource("ButtonPressed")
|
||||
text = "JUMP"
|
||||
|
||||
[node name="Attack" type="Button" parent="Controls"]
|
||||
layout_mode = 0
|
||||
anchor_left = 1.0
|
||||
anchor_top = 1.0
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_left = -138.0
|
||||
offset_top = -132.0
|
||||
offset_right = -28.0
|
||||
offset_bottom = -32.0
|
||||
grow_horizontal = 0
|
||||
grow_vertical = 0
|
||||
focus_mode = 0
|
||||
keep_pressed_outside = true
|
||||
theme_override_colors/font_color = Color(1, 1, 1, 0.95)
|
||||
theme_override_colors/font_pressed_color = Color(1, 1, 1, 1)
|
||||
theme_override_font_sizes/font_size = 22
|
||||
theme_override_styles/normal = SubResource("ButtonNormal")
|
||||
theme_override_styles/hover = SubResource("ButtonNormal")
|
||||
theme_override_styles/pressed = SubResource("ButtonPressed")
|
||||
text = "ATK"
|
||||
Reference in new issue
Block a user