Merge pull request 'Añadidos drops, ahora cae cerveza o cafe' (#18) from feature/ia_automated_test into main
Android Debug APK / build (push) Successful in 39s
Android Debug APK / build (push) Successful in 39s
Reviewed-on: #18
This commit was merged in pull request #18.
This commit is contained in:
commit
fe0a134b8a
11 files changed
+282
-1
No files matched your search
@@ -9,6 +9,7 @@ signal died
|
|||||||
# actually share instead of guessing an abstraction in advance.
|
# actually share instead of guessing an abstraction in advance.
|
||||||
|
|
||||||
const PLAYER_HURTBOX_MASK: int = 1 << 3
|
const PLAYER_HURTBOX_MASK: int = 1 << 3
|
||||||
|
const DROP_MANAGER := preload("res://pickups/drop_manager.gd")
|
||||||
|
|
||||||
|
|
||||||
enum AttackState {
|
enum AttackState {
|
||||||
@@ -88,6 +89,20 @@ enum AttackState {
|
|||||||
# RESPAWN
|
# RESPAWN
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
|
|
||||||
|
@export_category("Drops")
|
||||||
|
|
||||||
|
## Table defining what pickups can drop on death (by chance).
|
||||||
|
@export var drop_table: PickupDropTable
|
||||||
|
|
||||||
|
|
||||||
|
@export_category("Respawn")
|
||||||
|
|
||||||
|
@export_category("Drops")
|
||||||
|
|
||||||
|
## Table defining what pickups can drop on death (by chance).
|
||||||
|
@export var drop_table: PickupDropTable
|
||||||
|
|
||||||
|
|
||||||
@export_category("Respawn")
|
@export_category("Respawn")
|
||||||
|
|
||||||
## Enough downtime to make defeating an enemy meaningful before it comes back.
|
## Enough downtime to make defeating an enemy meaningful before it comes back.
|
||||||
@@ -161,7 +176,21 @@ func _ready() -> void:
|
|||||||
attack_hitbox.collision_mask = PLAYER_HURTBOX_MASK
|
attack_hitbox.collision_mask = PLAYER_HURTBOX_MASK
|
||||||
attack_hitbox.monitoring = true
|
attack_hitbox.monitoring = true
|
||||||
|
|
||||||
|
if drop_table == null:
|
||||||
|
var default_table = load("res://enemies/walker/walker_drop.tres")
|
||||||
|
if default_table != null:
|
||||||
|
drop_table = default_table
|
||||||
|
|
||||||
visibility_notifier.screen_entered.connect(_wake_up)
|
visibility_notifier.screen_entered.connect(_wake_up)
|
||||||
|
if default_table != null:
|
||||||
|
drop_table = default_table
|
||||||
|
|
||||||
|
visibility_notifier.screen_entered.connect(_wake_up)
|
||||||
|
|
||||||
|
if drop_table == null:
|
||||||
|
var default_table := load("res://enemies/walker/walker_drop.tres")
|
||||||
|
if default_table != null:
|
||||||
|
drop_table = default_table as PickupDropTable
|
||||||
|
|
||||||
_update_facing()
|
_update_facing()
|
||||||
_reset_attack_hitbox_position()
|
_reset_attack_hitbox_position()
|
||||||
@@ -474,6 +503,16 @@ func _die() -> void:
|
|||||||
is_dead = true
|
is_dead = true
|
||||||
died.emit()
|
died.emit()
|
||||||
|
|
||||||
|
if drop_table != null:
|
||||||
|
var drops = DROP_MANAGER.roll_drop(drop_table)
|
||||||
|
if not drops.is_empty():
|
||||||
|
var parent := get_tree().current_scene
|
||||||
|
if parent == null:
|
||||||
|
parent = get_tree().root.get_child(get_tree().root.get_child_count() - 1)
|
||||||
|
if parent == null:
|
||||||
|
parent = get_tree().root
|
||||||
|
DROP_MANAGER.spawn_drops(drops, parent, global_position)
|
||||||
|
|
||||||
velocity = Vector2.ZERO
|
velocity = Vector2.ZERO
|
||||||
visible = false
|
visible = false
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
[gd_resource type="Resource" script_class="PickupDropTable" load_steps=5 format=3]
|
||||||
|
|
||||||
|
[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="Resource" path="res://pickups/data/beer.tres" id="3_beer"]
|
||||||
|
[ext_resource type="Resource" path="res://pickups/data/coffee.tres" id="4_coffee"]
|
||||||
|
|
||||||
|
[sub_resource type="Resource" id="Resource_beer"]
|
||||||
|
script = ExtResource("1_drop")
|
||||||
|
pickup = ExtResource("3_beer")
|
||||||
|
weight = 0.5
|
||||||
|
|
||||||
|
[sub_resource type="Resource" id="Resource_coffee"]
|
||||||
|
script = ExtResource("1_drop")
|
||||||
|
pickup = ExtResource("4_coffee")
|
||||||
|
weight = 0.5
|
||||||
|
|
||||||
|
[resource]
|
||||||
|
script = ExtResource("2_table")
|
||||||
|
drops = Array[ExtResource("1_drop")]([SubResource("Resource_beer"), SubResource("Resource_coffee")])
|
||||||
|
drop_chance = 0.5
|
||||||
|
min_drops = 0
|
||||||
|
max_drops = 1
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
[gd_resource type="Resource" script_class="PickupData" load_steps=2 format=3]
|
||||||
|
|
||||||
|
[ext_resource type="Script" path="res://pickups/pickup_data.gd" id="1_data"]
|
||||||
|
|
||||||
|
[resource]
|
||||||
|
script = ExtResource("1_data")
|
||||||
|
id = &"beer"
|
||||||
|
display_name = "Cerveza"
|
||||||
|
effect_type = "heal"
|
||||||
|
value = 30.0
|
||||||
|
duration = 0.0
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
[gd_resource type="Resource" script_class="PickupData" load_steps=2 format=3]
|
||||||
|
|
||||||
|
[ext_resource type="Script" path="res://pickups/pickup_data.gd" id="1_data"]
|
||||||
|
|
||||||
|
[resource]
|
||||||
|
script = ExtResource("1_data")
|
||||||
|
id = &"coffee"
|
||||||
|
display_name = "Cafe"
|
||||||
|
effect_type = "speed_boost"
|
||||||
|
value = 0.5
|
||||||
|
duration = 120.0
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
extends Node
|
||||||
|
class_name DropManager
|
||||||
|
|
||||||
|
const PICKUP_SCENE := preload("res://pickups/pickup.tscn")
|
||||||
|
|
||||||
|
|
||||||
|
static func roll_drop(drop_table: PickupDropTable) -> Array[PickupData]:
|
||||||
|
var result: Array[PickupData] = []
|
||||||
|
if drop_table == null:
|
||||||
|
return result
|
||||||
|
|
||||||
|
if randf() > drop_table.drop_chance:
|
||||||
|
return result
|
||||||
|
|
||||||
|
var available: Array[PickupDrop] = drop_table.drops.duplicate()
|
||||||
|
available = available.filter(func(d): return d.pickup != null)
|
||||||
|
|
||||||
|
var count := randi_range(drop_table.min_drops, drop_table.max_drops)
|
||||||
|
if count < 0:
|
||||||
|
count = 0
|
||||||
|
if count > available.size():
|
||||||
|
count = available.size()
|
||||||
|
|
||||||
|
for i in range(count):
|
||||||
|
if available.is_empty():
|
||||||
|
break
|
||||||
|
var total_weight: float = 0.0
|
||||||
|
for d in available:
|
||||||
|
total_weight += max(d.weight, 0.0)
|
||||||
|
if total_weight <= 0.0:
|
||||||
|
break
|
||||||
|
var r := randf() * total_weight
|
||||||
|
var selected: PickupDrop = null
|
||||||
|
for d in available:
|
||||||
|
r -= max(d.weight, 0.0)
|
||||||
|
if r <= 0.0:
|
||||||
|
selected = d
|
||||||
|
break
|
||||||
|
if selected == null:
|
||||||
|
selected = available.back()
|
||||||
|
result.append(selected.pickup)
|
||||||
|
available.erase(selected)
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
static func spawn_drops(drops_data: Array[PickupData], parent: Node, position: Vector2) -> void:
|
||||||
|
for data in drops_data:
|
||||||
|
var pickup := PICKUP_SCENE.instantiate() as Pickup
|
||||||
|
pickup.pickup_data = data
|
||||||
|
parent.add_child(pickup)
|
||||||
|
pickup.global_position = position
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
extends Area2D
|
||||||
|
class_name Pickup
|
||||||
|
|
||||||
|
signal picked_up(pickup: Pickup, data: PickupData)
|
||||||
|
|
||||||
|
@export var pickup_data: PickupData
|
||||||
|
@export var fall_speed: float = 150.0
|
||||||
|
@export var bob_amplitude: float = 4.0
|
||||||
|
@export var bob_speed: float = 3.0
|
||||||
|
|
||||||
|
var velocity: Vector2 = Vector2.ZERO
|
||||||
|
var time: float = 0.0
|
||||||
|
var start_y: float = 0.0
|
||||||
|
var grounded: bool = false
|
||||||
|
|
||||||
|
@onready var label: Label = $Label
|
||||||
|
@onready var sprite: Sprite2D = $Sprite2D
|
||||||
|
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
add_to_group("pickup")
|
||||||
|
if pickup_data != null:
|
||||||
|
label.text = pickup_data.display_name
|
||||||
|
start_y = position.y
|
||||||
|
body_entered.connect(_on_body_entered)
|
||||||
|
|
||||||
|
|
||||||
|
func _physics_process(delta: float) -> void:
|
||||||
|
time += delta
|
||||||
|
if not grounded:
|
||||||
|
velocity.y += fall_speed * delta
|
||||||
|
position += velocity * delta
|
||||||
|
if is_on_floor():
|
||||||
|
grounded = true
|
||||||
|
velocity = Vector2.ZERO
|
||||||
|
start_y = position.y
|
||||||
|
else:
|
||||||
|
position.y = start_y + sin(time * bob_speed) * bob_amplitude
|
||||||
|
|
||||||
|
|
||||||
|
func is_on_floor() -> bool:
|
||||||
|
var space = get_world_2d().direct_space_state
|
||||||
|
var params = PhysicsRayQueryParameters2D.create(global_position, global_position + Vector2(0, 12))
|
||||||
|
params.collision_mask = 1
|
||||||
|
var result = space.intersect_ray(params)
|
||||||
|
return result.size() > 0
|
||||||
|
|
||||||
|
|
||||||
|
func _on_body_entered(body: Node2D) -> void:
|
||||||
|
if body.is_in_group("player"):
|
||||||
|
picked_up.emit(self, pickup_data)
|
||||||
|
queue_free()
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
[gd_scene load_steps=4 format=3]
|
||||||
|
|
||||||
|
[ext_resource type="Script" path="res://pickups/pickup.gd" id="1_pickup"]
|
||||||
|
[ext_resource type="FontFile" path="res://assets/fonts/PixelOperator8.ttf" id="2_font"]
|
||||||
|
|
||||||
|
[sub_resource type="RectangleShape2D" id="PickupShape"]
|
||||||
|
size = Vector2(16, 16)
|
||||||
|
|
||||||
|
[node name="Pickup" type="Area2D"]
|
||||||
|
collision_layer = 0
|
||||||
|
collision_mask = 2
|
||||||
|
script = ExtResource("1_pickup")
|
||||||
|
|
||||||
|
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||||
|
modulate = Color(1, 0.4, 0.8, 1)
|
||||||
|
scale = Vector2(0.5, 0.5)
|
||||||
|
|
||||||
|
[node name="ColorRect" type="ColorRect" parent="Sprite2D"]
|
||||||
|
offset_left = -16.0
|
||||||
|
offset_top = -16.0
|
||||||
|
offset_right = 16.0
|
||||||
|
offset_bottom = 16.0
|
||||||
|
color = Color(1, 0.4, 0.8, 1)
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||||
|
shape = SubResource("PickupShape")
|
||||||
|
|
||||||
|
[node name="Label" type="Label" parent="."]
|
||||||
|
offset_left = -32.0
|
||||||
|
offset_top = -28.0
|
||||||
|
offset_right = 32.0
|
||||||
|
offset_bottom = -12.0
|
||||||
|
theme_override_fonts/font = ExtResource("2_font")
|
||||||
|
theme_override_font_sizes/font_size = 8
|
||||||
|
text = "Item"
|
||||||
|
horizontal_alignment = 1
|
||||||
|
vertical_alignment = 1
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
extends Resource
|
||||||
|
class_name PickupData
|
||||||
|
|
||||||
|
@export_category("Identity")
|
||||||
|
@export var id: StringName = &"pickup"
|
||||||
|
@export var display_name: String = "Item"
|
||||||
|
|
||||||
|
@export_category("Effect")
|
||||||
|
@export_enum("heal", "speed_boost") var effect_type: String = "heal"
|
||||||
|
@export var value: float = 0.0
|
||||||
|
@export var duration: float = 0.0
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
extends Resource
|
||||||
|
class_name PickupDrop
|
||||||
|
|
||||||
|
@export var pickup: PickupData
|
||||||
|
@export_range(0.0, 1.0) var weight: float = 0.5
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
extends Resource
|
||||||
|
class_name PickupDropTable
|
||||||
|
|
||||||
|
@export var drops: Array[PickupDrop] = []
|
||||||
|
@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 max_drops: int = 1
|
||||||
+34
-1
@@ -198,6 +198,10 @@ var is_dead: bool = false
|
|||||||
|
|
||||||
var jumps_remaining: int = 2
|
var jumps_remaining: int = 2
|
||||||
|
|
||||||
|
var _speed_boost_timer: float = 0.0
|
||||||
|
var _speed_boost_multiplier: float = 1.0
|
||||||
|
var _original_move_speed: float = 0.0
|
||||||
|
|
||||||
# Tracks the highest point reached since leaving the ground, used to scale
|
# Tracks the highest point reached since leaving the ground, used to scale
|
||||||
# ground pound damage by jump height instead of fall distance.
|
# ground pound damage by jump height instead of fall distance.
|
||||||
var _jump_height_tracking: bool = false
|
var _jump_height_tracking: bool = false
|
||||||
@@ -220,6 +224,7 @@ 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()
|
||||||
@@ -227,6 +232,7 @@ 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()
|
||||||
@@ -245,6 +251,7 @@ 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)
|
||||||
|
|
||||||
move_and_slide()
|
move_and_slide()
|
||||||
|
|
||||||
@@ -281,7 +288,10 @@ func _handle_horizontal_movement(delta: float) -> void:
|
|||||||
facing_direction = signf(direction)
|
facing_direction = signf(direction)
|
||||||
_update_facing()
|
_update_facing()
|
||||||
|
|
||||||
var target_speed: float = direction * character_data.move_speed
|
var move_speed: float = character_data.move_speed
|
||||||
|
if _speed_boost_timer > 0.0:
|
||||||
|
move_speed *= (1.0 + _speed_boost_multiplier)
|
||||||
|
var target_speed: float = direction * move_speed
|
||||||
|
|
||||||
if ground_pound_active:
|
if ground_pound_active:
|
||||||
target_speed *= ground_pound_horizontal_control
|
target_speed *= ground_pound_horizontal_control
|
||||||
@@ -508,6 +518,27 @@ 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:
|
||||||
|
for pickup in get_tree().get_nodes_in_group("pickup"):
|
||||||
|
if is_instance_valid(pickup) and pickup.has_signal(&"picked_up"):
|
||||||
|
pickup.picked_up.connect(_on_pickup_picked_up)
|
||||||
|
|
||||||
|
|
||||||
|
func _on_pickup_picked_up(pickup: Node, data: PickupData) -> void:
|
||||||
|
if is_dead or data == null:
|
||||||
|
return
|
||||||
|
if data.effect_type == "heal":
|
||||||
|
current_health = min(current_health + int(data.value), character_data.max_health)
|
||||||
|
health_changed.emit(current_health, character_data.max_health)
|
||||||
|
elif data.effect_type == "speed_boost":
|
||||||
|
_speed_boost_multiplier = data.value
|
||||||
|
_speed_boost_timer = data.duration
|
||||||
|
|
||||||
|
|
||||||
|
func _update_speed_boost(_delta: float) -> void:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
func _connect_to_enemies() -> void:
|
func _connect_to_enemies() -> void:
|
||||||
for enemy in get_tree().get_nodes_in_group("enemy"):
|
for enemy in get_tree().get_nodes_in_group("enemy"):
|
||||||
if is_instance_valid(enemy) and enemy.has_signal(&"died"):
|
if is_instance_valid(enemy) and enemy.has_signal(&"died"):
|
||||||
@@ -589,6 +620,8 @@ func _update_timers(delta: float) -> void:
|
|||||||
attack_cooldown_timer = max(attack_cooldown_timer - delta, 0.0)
|
attack_cooldown_timer = max(attack_cooldown_timer - delta, 0.0)
|
||||||
ground_pound_debug_timer = max(ground_pound_debug_timer - delta, 0.0)
|
ground_pound_debug_timer = max(ground_pound_debug_timer - delta, 0.0)
|
||||||
invulnerability_timer = max(invulnerability_timer - delta, 0.0)
|
invulnerability_timer = max(invulnerability_timer - delta, 0.0)
|
||||||
|
if _speed_boost_timer > 0.0:
|
||||||
|
_speed_boost_timer = max(_speed_boost_timer - delta, 0.0)
|
||||||
|
|
||||||
|
|
||||||
func _update_animation() -> void:
|
func _update_animation() -> void:
|
||||||
|
|||||||
Reference in new issue
Block a user