magnetic skill
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
[gd_scene load_steps=17 format=3 uid="uid://bqi5s710xb1ju"]
|
[gd_scene load_steps=19 format=3 uid="uid://bqi5s710xb1ju"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://scripts/player.gd" id="1_8j4h4"]
|
[ext_resource type="Script" path="res://scripts/player.gd" id="1_8j4h4"]
|
||||||
[ext_resource type="Texture2D" uid="uid://b7gp0gqvkv8j4" path="res://sprites/MrBrick_base.png" id="2_bc55y"]
|
[ext_resource type="Texture2D" uid="uid://b7gp0gqvkv8j4" path="res://sprites/MrBrick_base.png" id="2_bc55y"]
|
||||||
@@ -14,6 +14,7 @@
|
|||||||
[ext_resource type="Script" path="res://scripts/components/stomp_damage_component.gd" id="12_payr4"]
|
[ext_resource type="Script" path="res://scripts/components/stomp_damage_component.gd" id="12_payr4"]
|
||||||
[ext_resource type="Script" path="res://scripts/components/flashing_component.gd" id="13_hrtyn"]
|
[ext_resource type="Script" path="res://scripts/components/flashing_component.gd" id="13_hrtyn"]
|
||||||
[ext_resource type="Script" path="res://scripts/components/invulnerability_component.gd" id="14_jopig"]
|
[ext_resource type="Script" path="res://scripts/components/invulnerability_component.gd" id="14_jopig"]
|
||||||
|
[ext_resource type="Script" path="res://scripts/components/magnetic_skill.gd" id="15_4df3h"]
|
||||||
|
|
||||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_hdsg1"]
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_hdsg1"]
|
||||||
size = Vector2(16, 31)
|
size = Vector2(16, 31)
|
||||||
@@ -21,6 +22,9 @@ size = Vector2(16, 31)
|
|||||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_vad0t"]
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_vad0t"]
|
||||||
size = Vector2(16, 32)
|
size = Vector2(16, 32)
|
||||||
|
|
||||||
|
[sub_resource type="CircleShape2D" id="CircleShape2D_ps31c"]
|
||||||
|
radius = 48.0
|
||||||
|
|
||||||
[node name="Brick Player" type="CharacterBody2D"]
|
[node name="Brick Player" type="CharacterBody2D"]
|
||||||
collision_layer = 4
|
collision_layer = 4
|
||||||
collision_mask = 11
|
collision_mask = 11
|
||||||
@@ -115,5 +119,18 @@ health_component = NodePath("../HealthComponent")
|
|||||||
script = ExtResource("14_jopig")
|
script = ExtResource("14_jopig")
|
||||||
flashing_component = NodePath("../FlashingComponent Base")
|
flashing_component = NodePath("../FlashingComponent Base")
|
||||||
|
|
||||||
|
[node name="MagneticSkillComponent" type="Node" parent="." node_paths=PackedStringArray("magnetic_area", "root")]
|
||||||
|
script = ExtResource("15_4df3h")
|
||||||
|
magnetic_area = NodePath("../MagneticArea")
|
||||||
|
root = NodePath("..")
|
||||||
|
magnetic_move_duration = 0.9
|
||||||
|
|
||||||
|
[node name="MagneticArea" type="Area2D" parent="."]
|
||||||
|
collision_layer = 0
|
||||||
|
collision_mask = 2
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="MagneticArea"]
|
||||||
|
shape = SubResource("CircleShape2D_ps31c")
|
||||||
|
|
||||||
[connection signal="on_death" from="HealthComponent" to="PlayerDeathComponent" method="_on_health_component_on_death"]
|
[connection signal="on_death" from="HealthComponent" to="PlayerDeathComponent" method="_on_health_component_on_death"]
|
||||||
[connection signal="on_health_change" from="HealthComponent" to="KnockbackComponent" method="_on_health_component_on_health_change"]
|
[connection signal="on_health_change" from="HealthComponent" to="KnockbackComponent" method="_on_health_component_on_health_change"]
|
||||||
|
@@ -10,7 +10,7 @@ radius = 9.0
|
|||||||
|
|
||||||
[node name="Coin" type="Area2D"]
|
[node name="Coin" type="Area2D"]
|
||||||
collision_layer = 2
|
collision_layer = 2
|
||||||
collision_mask = 20
|
collision_mask = 4
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||||
shape = SubResource("CircleShape2D_3ask2")
|
shape = SubResource("CircleShape2D_3ask2")
|
||||||
|
@@ -387,7 +387,7 @@ texture_region_size = Vector2i(8, 8)
|
|||||||
tile_size = Vector2i(8, 8)
|
tile_size = Vector2i(8, 8)
|
||||||
sources/1 = SubResource("TileSetAtlasSource_eoyis")
|
sources/1 = SubResource("TileSetAtlasSource_eoyis")
|
||||||
|
|
||||||
[node name="Node2D" type="Node2D"]
|
[node name="World" type="Node2D"]
|
||||||
|
|
||||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||||
position = Vector2(331.75, -48.5)
|
position = Vector2(331.75, -48.5)
|
||||||
|
63
scripts/components/magnetic_skill.gd
Normal file
63
scripts/components/magnetic_skill.gd
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
class_name MagneticSkillComponent
|
||||||
|
extends Node
|
||||||
|
|
||||||
|
@export var magnetic_area: Area2D
|
||||||
|
@export var root: Node2D
|
||||||
|
@export var magnetic_move_duration: float = 1.25
|
||||||
|
|
||||||
|
var collectables_to_pickup: Array = []
|
||||||
|
|
||||||
|
|
||||||
|
func has_component_in_children(node: Node, component_name: String) -> bool:
|
||||||
|
if not node:
|
||||||
|
return false
|
||||||
|
|
||||||
|
if node.has_node(component_name):
|
||||||
|
return true
|
||||||
|
|
||||||
|
for child in node.get_children():
|
||||||
|
if has_component_in_children(child, component_name):
|
||||||
|
return true
|
||||||
|
|
||||||
|
return false
|
||||||
|
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
if not magnetic_area:
|
||||||
|
printerr("No magnetic_area assigned!")
|
||||||
|
return
|
||||||
|
|
||||||
|
magnetic_area.body_entered.connect(on_magnetic_area_body_entered)
|
||||||
|
magnetic_area.area_entered.connect(on_magnetic_area_area_entered)
|
||||||
|
|
||||||
|
|
||||||
|
func _process(_delta: float) -> void:
|
||||||
|
for collectable in collectables_to_pickup:
|
||||||
|
if not is_instance_valid(collectable):
|
||||||
|
collectables_to_pickup.erase(collectable)
|
||||||
|
continue
|
||||||
|
|
||||||
|
move_collectable_to_root(collectable)
|
||||||
|
|
||||||
|
|
||||||
|
func on_magnetic_area_body_entered(_body: Node2D) -> void:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
func on_magnetic_area_area_entered(area: Area2D) -> void:
|
||||||
|
if not has_component_in_children(area, "Collectable"):
|
||||||
|
return
|
||||||
|
|
||||||
|
if not collectables_to_pickup.has(area):
|
||||||
|
collectables_to_pickup.append(area)
|
||||||
|
|
||||||
|
|
||||||
|
func move_collectable_to_root(collectable: Node2D) -> void:
|
||||||
|
if not is_instance_valid(collectable):
|
||||||
|
return
|
||||||
|
|
||||||
|
var direction: Vector2 = (root.global_position - collectable.global_position).normalized()
|
||||||
|
var speed: float = direction.length() / magnetic_move_duration
|
||||||
|
|
||||||
|
collectable.global_position += direction.normalized() * speed
|
||||||
|
|
Reference in New Issue
Block a user