Merge pull request 'Arreglados los pickups' (#21) from feature/ia_automated_test into main
Android Debug APK / build (push) Successful in 41s
Android Debug APK / build (push) Successful in 41s
Reviewed-on: #21
This commit was merged in pull request #21.
This commit is contained in:
commit
45ee99b054
9 files changed
+41
-38
No files matched your search
@@ -1,4 +1,4 @@
|
|||||||
[gd_resource type="Resource" script_class="PickupDropTable" load_steps=5 format=3]
|
[gd_resource type="Resource" script_class="PickupDropTable" load_steps=7 format=3]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://pickups/pickup_drop.gd" id="1_drop"]
|
[ext_resource type="Script" path="res://pickups/pickup_drop.gd" id="1_drop"]
|
||||||
[ext_resource type="Script" path="res://pickups/pickup_drop_table.gd" id="2_table"]
|
[ext_resource type="Script" path="res://pickups/pickup_drop_table.gd" id="2_table"]
|
||||||
@@ -19,5 +19,5 @@ weight = 0.5
|
|||||||
script = ExtResource("2_table")
|
script = ExtResource("2_table")
|
||||||
drops = Array[ExtResource("1_drop")]([SubResource("Resource_beer"), SubResource("Resource_coffee")])
|
drops = Array[ExtResource("1_drop")]([SubResource("Resource_beer"), SubResource("Resource_coffee")])
|
||||||
drop_chance = 0.5
|
drop_chance = 0.5
|
||||||
min_drops = 0
|
min_drops = 1
|
||||||
max_drops = 1
|
max_drops = 1
|
||||||
@@ -6,6 +6,7 @@
|
|||||||
script = ExtResource("1_data")
|
script = ExtResource("1_data")
|
||||||
id = &"beer"
|
id = &"beer"
|
||||||
display_name = "Cerveza"
|
display_name = "Cerveza"
|
||||||
|
color = Color(1, 0.76, 0.18, 1)
|
||||||
effect_type = "heal"
|
effect_type = "heal"
|
||||||
value = 30.0
|
value = 30.0
|
||||||
duration = 0.0
|
duration = 0.0
|
||||||
@@ -5,7 +5,8 @@
|
|||||||
[resource]
|
[resource]
|
||||||
script = ExtResource("1_data")
|
script = ExtResource("1_data")
|
||||||
id = &"coffee"
|
id = &"coffee"
|
||||||
display_name = "Cafe"
|
display_name = "Café"
|
||||||
|
color = Color(0.56, 0.29, 0.14, 1)
|
||||||
effect_type = "speed_boost"
|
effect_type = "speed_boost"
|
||||||
value = 0.5
|
value = 0.5
|
||||||
duration = 120.0
|
duration = 120.0
|
||||||
+7
-3
@@ -15,12 +15,16 @@ var grounded: bool = false
|
|||||||
|
|
||||||
@onready var label: Label = $Label
|
@onready var label: Label = $Label
|
||||||
@onready var sprite: Sprite2D = $Sprite2D
|
@onready var sprite: Sprite2D = $Sprite2D
|
||||||
|
@onready var placeholder: ColorRect = $Sprite2D/ColorRect
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
add_to_group("pickup")
|
add_to_group("pickup")
|
||||||
if pickup_data != null:
|
if pickup_data != null:
|
||||||
label.text = pickup_data.display_name
|
label.text = pickup_data.display_name
|
||||||
|
sprite.texture = pickup_data.icon
|
||||||
|
placeholder.visible = pickup_data.icon == null
|
||||||
|
placeholder.color = pickup_data.color
|
||||||
start_y = position.y
|
start_y = position.y
|
||||||
body_entered.connect(_on_body_entered)
|
body_entered.connect(_on_body_entered)
|
||||||
|
|
||||||
@@ -47,7 +51,7 @@ func is_on_floor() -> bool:
|
|||||||
|
|
||||||
|
|
||||||
func _on_body_entered(body: Node2D) -> void:
|
func _on_body_entered(body: Node2D) -> void:
|
||||||
if body.is_in_group("player"):
|
if body.is_in_group("player") and body.has_method("collect_pickup"):
|
||||||
if pickup_data != null:
|
if body.collect_pickup(pickup_data):
|
||||||
picked_up.emit(self, pickup_data)
|
picked_up.emit(self, pickup_data)
|
||||||
queue_free()
|
queue_free()
|
||||||
+2
-2
@@ -12,7 +12,7 @@ collision_mask = 2
|
|||||||
script = ExtResource("1_pickup")
|
script = ExtResource("1_pickup")
|
||||||
|
|
||||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||||
modulate = Color(1, 0.4, 0.8, 1)
|
modulate = Color(1, 1, 1, 1)
|
||||||
scale = Vector2(0.5, 0.5)
|
scale = Vector2(0.5, 0.5)
|
||||||
|
|
||||||
[node name="ColorRect" type="ColorRect" parent="Sprite2D"]
|
[node name="ColorRect" type="ColorRect" parent="Sprite2D"]
|
||||||
@@ -20,7 +20,7 @@ offset_left = -16.0
|
|||||||
offset_top = -16.0
|
offset_top = -16.0
|
||||||
offset_right = 16.0
|
offset_right = 16.0
|
||||||
offset_bottom = 16.0
|
offset_bottom = 16.0
|
||||||
color = Color(1, 0.4, 0.8, 1)
|
color = Color(1, 1, 1, 1)
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||||
shape = SubResource("PickupShape")
|
shape = SubResource("PickupShape")
|
||||||
|
|||||||
@@ -5,6 +5,10 @@ class_name PickupData
|
|||||||
@export var id: StringName = &"pickup"
|
@export var id: StringName = &"pickup"
|
||||||
@export var display_name: String = "Item"
|
@export var display_name: String = "Item"
|
||||||
|
|
||||||
|
@export_category("Visuals")
|
||||||
|
@export var icon: Texture2D
|
||||||
|
@export var color: Color = Color(1.0, 0.7, 0.2)
|
||||||
|
|
||||||
@export_category("Effect")
|
@export_category("Effect")
|
||||||
@export_enum("heal", "speed_boost") var effect_type: String = "heal"
|
@export_enum("heal", "speed_boost") var effect_type: String = "heal"
|
||||||
@export var value: float = 0.0
|
@export var value: float = 0.0
|
||||||
|
|||||||
@@ -2,4 +2,4 @@ extends Resource
|
|||||||
class_name PickupDrop
|
class_name PickupDrop
|
||||||
|
|
||||||
@export var pickup: PickupData
|
@export var pickup: PickupData
|
||||||
@export_range(0.0, 1.0) var weight: float = 0.5
|
@export_range(0.0, 100.0, 0.1) var weight: float = 1.0
|
||||||
@@ -3,5 +3,5 @@ class_name PickupDropTable
|
|||||||
|
|
||||||
@export var drops: Array[PickupDrop] = []
|
@export var drops: Array[PickupDrop] = []
|
||||||
@export_range(0.0, 1.0) var drop_chance: float = 0.5
|
@export_range(0.0, 1.0) var drop_chance: float = 0.5
|
||||||
@export_range(0, 10, 1) var min_drops: int = 0
|
@export_range(0, 10, 1) var min_drops: int = 1
|
||||||
@export_range(0, 10, 1) var max_drops: int = 1
|
@export_range(0, 10, 1) var max_drops: int = 1
|
||||||
+21
-28
@@ -200,7 +200,6 @@ var jumps_remaining: int = 2
|
|||||||
|
|
||||||
var _speed_boost_timer: float = 0.0
|
var _speed_boost_timer: float = 0.0
|
||||||
var _speed_boost_multiplier: float = 0.0
|
var _speed_boost_multiplier: float = 0.0
|
||||||
var _original_move_speed: float = 0.0
|
|
||||||
|
|
||||||
var _floating_texts: Array = []
|
var _floating_texts: Array = []
|
||||||
|
|
||||||
@@ -226,7 +225,6 @@ func _ready() -> void:
|
|||||||
if character_data.sprite_frames != null:
|
if character_data.sprite_frames != null:
|
||||||
animated_sprite.sprite_frames = character_data.sprite_frames
|
animated_sprite.sprite_frames = character_data.sprite_frames
|
||||||
|
|
||||||
_original_move_speed = character_data.move_speed
|
|
||||||
jumps_remaining = max_jumps
|
jumps_remaining = max_jumps
|
||||||
|
|
||||||
_setup_attack_hitboxes()
|
_setup_attack_hitboxes()
|
||||||
@@ -234,7 +232,6 @@ func _ready() -> void:
|
|||||||
_update_animation()
|
_update_animation()
|
||||||
health_changed.emit(current_health, character_data.max_health)
|
health_changed.emit(current_health, character_data.max_health)
|
||||||
special_charge_changed.emit(special_charge, special_max_charge)
|
special_charge_changed.emit(special_charge, special_max_charge)
|
||||||
_connect_pickups()
|
|
||||||
# Conecta a los enemigos que ya estén en el árbol. Si se añaden más tarde,
|
# Conecta a los enemigos que ya estén en el árbol. Si se añaden más tarde,
|
||||||
# se conectarán cuando mueran mediante el grupo "enemy".
|
# se conectarán cuando mueran mediante el grupo "enemy".
|
||||||
_connect_to_enemies()
|
_connect_to_enemies()
|
||||||
@@ -253,7 +250,6 @@ func _physics_process(delta: float) -> void:
|
|||||||
_apply_gravity(delta)
|
_apply_gravity(delta)
|
||||||
_handle_horizontal_movement(delta)
|
_handle_horizontal_movement(delta)
|
||||||
_update_punch_damage()
|
_update_punch_damage()
|
||||||
_update_speed_boost(delta)
|
|
||||||
_update_floating_texts(delta)
|
_update_floating_texts(delta)
|
||||||
|
|
||||||
move_and_slide()
|
move_and_slide()
|
||||||
@@ -521,31 +517,28 @@ func _apply_special_attack(charge_used: int = special_max_charge) -> void:
|
|||||||
enemy.take_damage(damage, global_position)
|
enemy.take_damage(damage, global_position)
|
||||||
|
|
||||||
|
|
||||||
func _connect_pickups() -> void:
|
func collect_pickup(data: PickupData) -> bool:
|
||||||
for pickup in get_tree().get_nodes_in_group("pickup"):
|
if is_dead or data == null or character_data == null:
|
||||||
if is_instance_valid(pickup) and pickup.has_signal(&"picked_up"):
|
return false
|
||||||
pickup.picked_up.connect(_on_pickup_picked_up)
|
|
||||||
|
|
||||||
|
match data.effect_type:
|
||||||
func _on_pickup_picked_up(pickup: Node, data: PickupData) -> void:
|
"heal":
|
||||||
if is_dead or data == null:
|
var heal_amount: int = mini(int(data.value), character_data.max_health - current_health)
|
||||||
return
|
if heal_amount <= 0:
|
||||||
if data.effect_type == "heal":
|
return false
|
||||||
var heal_amount: int = int(data.value)
|
current_health += heal_amount
|
||||||
current_health = min(current_health + heal_amount, character_data.max_health)
|
health_changed.emit(current_health, character_data.max_health)
|
||||||
health_changed.emit(current_health, character_data.max_health)
|
_spawn_floating_text("+" + str(heal_amount), Color(0.2, 1.0, 0.3))
|
||||||
_spawn_floating_text("+" + str(heal_amount), Color(0.2, 1.0, 0.3))
|
"speed_boost":
|
||||||
elif data.effect_type == "speed_boost":
|
if data.value <= 0.0 or data.duration <= 0.0:
|
||||||
_speed_boost_multiplier = data.value
|
return false
|
||||||
_speed_boost_timer = data.duration
|
_speed_boost_multiplier = data.value
|
||||||
_spawn_floating_text("SPEED UP", Color(1.0, 0.8, 0.2))
|
_speed_boost_timer = data.duration
|
||||||
|
_spawn_floating_text("SPEED UP", Color(1.0, 0.8, 0.2))
|
||||||
|
_:
|
||||||
func _update_speed_boost(delta: float) -> void:
|
push_warning("Unknown pickup effect: %s" % data.effect_type)
|
||||||
if _speed_boost_timer > 0.0:
|
return false
|
||||||
_speed_boost_timer = max(_speed_boost_timer - delta, 0.0)
|
return true
|
||||||
else:
|
|
||||||
_speed_boost_multiplier = 0.0
|
|
||||||
|
|
||||||
|
|
||||||
func _spawn_floating_text(text: String, color: Color) -> void:
|
func _spawn_floating_text(text: String, color: Color) -> void:
|
||||||
|
|||||||
Reference in new issue
Block a user