Compare commits
2
Commits
ec1f211956
...
45ee99b054
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
45ee99b054 | ||
|
|
1fbfdf3f8a |
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_table.gd" id="2_table"]
|
||||
@@ -19,5 +19,5 @@ weight = 0.5
|
||||
script = ExtResource("2_table")
|
||||
drops = Array[ExtResource("1_drop")]([SubResource("Resource_beer"), SubResource("Resource_coffee")])
|
||||
drop_chance = 0.5
|
||||
min_drops = 0
|
||||
min_drops = 1
|
||||
max_drops = 1
|
||||
@@ -6,6 +6,7 @@
|
||||
script = ExtResource("1_data")
|
||||
id = &"beer"
|
||||
display_name = "Cerveza"
|
||||
color = Color(1, 0.76, 0.18, 1)
|
||||
effect_type = "heal"
|
||||
value = 30.0
|
||||
duration = 0.0
|
||||
@@ -5,7 +5,8 @@
|
||||
[resource]
|
||||
script = ExtResource("1_data")
|
||||
id = &"coffee"
|
||||
display_name = "Cafe"
|
||||
display_name = "Café"
|
||||
color = Color(0.56, 0.29, 0.14, 1)
|
||||
effect_type = "speed_boost"
|
||||
value = 0.5
|
||||
duration = 120.0
|
||||
+7
-3
@@ -15,12 +15,16 @@ var grounded: bool = false
|
||||
|
||||
@onready var label: Label = $Label
|
||||
@onready var sprite: Sprite2D = $Sprite2D
|
||||
@onready var placeholder: ColorRect = $Sprite2D/ColorRect
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
add_to_group("pickup")
|
||||
if pickup_data != null:
|
||||
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
|
||||
body_entered.connect(_on_body_entered)
|
||||
|
||||
@@ -47,7 +51,7 @@ func is_on_floor() -> bool:
|
||||
|
||||
|
||||
func _on_body_entered(body: Node2D) -> void:
|
||||
if body.is_in_group("player"):
|
||||
if pickup_data != null:
|
||||
if body.is_in_group("player") and body.has_method("collect_pickup"):
|
||||
if body.collect_pickup(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")
|
||||
|
||||
[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)
|
||||
|
||||
[node name="ColorRect" type="ColorRect" parent="Sprite2D"]
|
||||
@@ -20,7 +20,7 @@ offset_left = -16.0
|
||||
offset_top = -16.0
|
||||
offset_right = 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="."]
|
||||
shape = SubResource("PickupShape")
|
||||
|
||||
@@ -5,6 +5,10 @@ class_name PickupData
|
||||
@export var id: StringName = &"pickup"
|
||||
@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_enum("heal", "speed_boost") var effect_type: String = "heal"
|
||||
@export var value: float = 0.0
|
||||
|
||||
@@ -2,4 +2,4 @@ extends Resource
|
||||
class_name PickupDrop
|
||||
|
||||
@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_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
|
||||
+21
-28
@@ -200,7 +200,6 @@ var jumps_remaining: int = 2
|
||||
|
||||
var _speed_boost_timer: float = 0.0
|
||||
var _speed_boost_multiplier: float = 0.0
|
||||
var _original_move_speed: float = 0.0
|
||||
|
||||
var _floating_texts: Array = []
|
||||
|
||||
@@ -226,7 +225,6 @@ func _ready() -> void:
|
||||
if character_data.sprite_frames != null:
|
||||
animated_sprite.sprite_frames = character_data.sprite_frames
|
||||
|
||||
_original_move_speed = character_data.move_speed
|
||||
jumps_remaining = max_jumps
|
||||
|
||||
_setup_attack_hitboxes()
|
||||
@@ -234,7 +232,6 @@ func _ready() -> void:
|
||||
_update_animation()
|
||||
health_changed.emit(current_health, character_data.max_health)
|
||||
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,
|
||||
# se conectarán cuando mueran mediante el grupo "enemy".
|
||||
_connect_to_enemies()
|
||||
@@ -253,7 +250,6 @@ func _physics_process(delta: float) -> void:
|
||||
_apply_gravity(delta)
|
||||
_handle_horizontal_movement(delta)
|
||||
_update_punch_damage()
|
||||
_update_speed_boost(delta)
|
||||
_update_floating_texts(delta)
|
||||
|
||||
move_and_slide()
|
||||
@@ -521,31 +517,28 @@ func _apply_special_attack(charge_used: int = special_max_charge) -> void:
|
||||
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 collect_pickup(data: PickupData) -> bool:
|
||||
if is_dead or data == null or character_data == null:
|
||||
return false
|
||||
|
||||
|
||||
func _on_pickup_picked_up(pickup: Node, data: PickupData) -> void:
|
||||
if is_dead or data == null:
|
||||
return
|
||||
if data.effect_type == "heal":
|
||||
var heal_amount: int = int(data.value)
|
||||
current_health = min(current_health + heal_amount, 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))
|
||||
elif data.effect_type == "speed_boost":
|
||||
_speed_boost_multiplier = data.value
|
||||
_speed_boost_timer = data.duration
|
||||
_spawn_floating_text("SPEED UP", Color(1.0, 0.8, 0.2))
|
||||
|
||||
|
||||
func _update_speed_boost(delta: float) -> void:
|
||||
if _speed_boost_timer > 0.0:
|
||||
_speed_boost_timer = max(_speed_boost_timer - delta, 0.0)
|
||||
else:
|
||||
_speed_boost_multiplier = 0.0
|
||||
match data.effect_type:
|
||||
"heal":
|
||||
var heal_amount: int = mini(int(data.value), character_data.max_health - current_health)
|
||||
if heal_amount <= 0:
|
||||
return false
|
||||
current_health += heal_amount
|
||||
health_changed.emit(current_health, character_data.max_health)
|
||||
_spawn_floating_text("+" + str(heal_amount), Color(0.2, 1.0, 0.3))
|
||||
"speed_boost":
|
||||
if data.value <= 0.0 or data.duration <= 0.0:
|
||||
return false
|
||||
_speed_boost_multiplier = data.value
|
||||
_speed_boost_timer = data.duration
|
||||
_spawn_floating_text("SPEED UP", Color(1.0, 0.8, 0.2))
|
||||
_:
|
||||
push_warning("Unknown pickup effect: %s" % data.effect_type)
|
||||
return false
|
||||
return true
|
||||
|
||||
|
||||
func _spawn_floating_text(text: String, color: Color) -> void:
|
||||
|
||||
Reference in new issue
Block a user