portal object improvements :3
This commit is contained in:
parent
07eb3ed129
commit
5677971bf0
9 changed files with 218 additions and 50 deletions
|
@ -1,16 +1,71 @@
|
|||
@tool
|
||||
class_name Portal
|
||||
extends Node2D
|
||||
|
||||
@export var connected_portal: NodePath
|
||||
@onready var portal = get_node(connected_portal)
|
||||
var check_for_bodies = true
|
||||
|
||||
func _on_area_2d_body_entered(body: Node2D) -> void:
|
||||
if body is Player && check_for_bodies:
|
||||
body.global_position = portal.global_position
|
||||
body.launch(body.velocity * 1.25)
|
||||
portal.check_for_bodies = false
|
||||
|
||||
## color the portal is tinted as
|
||||
@export_color_no_alpha var color: Color = Color.PURPLE:
|
||||
set(value):
|
||||
color = value
|
||||
sprite.modulate = color
|
||||
if linked_portal and linked_portal.color != color:
|
||||
linked_portal.color = color
|
||||
queue_redraw()
|
||||
|
||||
func _on_area_2d_body_exited(body: Node2D) -> void:
|
||||
await get_tree().create_timer(0.1).timeout
|
||||
check_for_bodies = true
|
||||
## Other connected portal. The linked
|
||||
@export var linked_portal: Portal:
|
||||
set(new_portal):
|
||||
if new_portal == self:
|
||||
return
|
||||
if new_portal == null:
|
||||
linked_portal = null
|
||||
return
|
||||
if linked_portal:
|
||||
linked_portal.linked_portal = null
|
||||
linked_portal = new_portal
|
||||
if linked_portal:
|
||||
if linked_portal.linked_portal != self:
|
||||
linked_portal.linked_portal = self
|
||||
linked_portal.color = color
|
||||
queue_redraw()
|
||||
|
||||
## Multiplier to the player's velocity when they travel through the portal.
|
||||
@export var speed_multiplier: float = 1.25
|
||||
## Delay in seconds until an exited portal can be re-entered.
|
||||
@export var teleport_cooldown: float = 0.1
|
||||
|
||||
@export_group("Internal References")
|
||||
@export var sprite: Sprite2D
|
||||
|
||||
|
||||
var check_for_player: bool = true
|
||||
|
||||
|
||||
func _init() -> void:
|
||||
set_notify_transform(true)
|
||||
|
||||
func _notification(what: int) -> void:
|
||||
if what == NOTIFICATION_TRANSFORM_CHANGED:
|
||||
queue_redraw()
|
||||
if linked_portal:
|
||||
linked_portal.queue_redraw()
|
||||
|
||||
func _draw() -> void:
|
||||
if Engine.is_editor_hint():
|
||||
if linked_portal:
|
||||
draw_line(Vector2.ZERO, to_local(linked_portal.global_position), color, 1.5)
|
||||
|
||||
|
||||
func _on_player_detector_body_entered(body: Node2D) -> void:
|
||||
if check_for_player and body is Player and linked_portal:
|
||||
body.global_position = linked_portal.global_position
|
||||
body.launch(body.velocity * speed_multiplier)
|
||||
linked_portal.check_for_player = false
|
||||
create_tween().tween_property(
|
||||
linked_portal, ^"check_for_player", true, 0.0
|
||||
).set_delay(teleport_cooldown)
|
||||
|
||||
|
||||
func _on_player_detector_body_exited(body: Node2D) -> void:
|
||||
var tween = create_tween().set_process_mode(Tween.TWEEN_PROCESS_PHYSICS)
|
||||
tween.tween_property(self, ^"check_for_player", true, 0.0).set_delay(teleport_cooldown)
|
||||
|
|
|
@ -1,25 +1,12 @@
|
|||
[gd_scene load_steps=7 format=3 uid="uid://cypj35yv5auuc"]
|
||||
[gd_scene load_steps=10 format=3 uid="uid://cypj35yv5auuc"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://dbrblyk7xttpj" path="res://objects/portal/portal.gd" id="1_v7atq"]
|
||||
[ext_resource type="Texture2D" uid="uid://dtwp3ohanw2sn" path="res://assets/textures/portal/portal.png" id="2_ah4id"]
|
||||
[ext_resource type="Texture2D" uid="uid://cv7rv8wlhpbg1" path="res://assets/textures/portal/portal_normal.png" id="3_ah4id"]
|
||||
[ext_resource type="Texture2D" uid="uid://h45qkvmrh0ey" path="res://assets/textures/portal/portal_light.png" id="4_xxtm7"]
|
||||
|
||||
[sub_resource type="Animation" id="Animation_xxtm7"]
|
||||
resource_name = "spin"
|
||||
length = 0.5
|
||||
loop_mode = 1
|
||||
step = 0.25
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Sprite2D:rotation")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0, 0.5),
|
||||
"transitions": PackedFloat32Array(1, 1),
|
||||
"update": 0,
|
||||
"values": [0.0, 6.28319]
|
||||
}
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_v7atq"]
|
||||
size = Vector2(16, 16)
|
||||
|
||||
[sub_resource type="Animation" id="Animation_0po8f"]
|
||||
length = 0.001
|
||||
|
@ -35,6 +22,47 @@ tracks/0/keys = {
|
|||
"update": 0,
|
||||
"values": [0.0]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/path = NodePath("LightPivot:rotation")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 0,
|
||||
"values": [0.0]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_xxtm7"]
|
||||
resource_name = "spin"
|
||||
loop_mode = 1
|
||||
step = 0.25
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Sprite2D:rotation")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0, 1),
|
||||
"transitions": PackedFloat32Array(1, 1),
|
||||
"update": 0,
|
||||
"values": [0.0, 12.5664]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/path = NodePath("LightPivot:rotation")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/keys = {
|
||||
"times": PackedFloat32Array(0, 1),
|
||||
"transitions": PackedFloat32Array(1, 1),
|
||||
"update": 0,
|
||||
"values": [0.0, -6.28319]
|
||||
}
|
||||
|
||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_6y8yo"]
|
||||
_data = {
|
||||
|
@ -42,14 +70,21 @@ _data = {
|
|||
&"spin": SubResource("Animation_xxtm7")
|
||||
}
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_v7atq"]
|
||||
size = Vector2(16, 16)
|
||||
[sub_resource type="CanvasTexture" id="CanvasTexture_xxtm7"]
|
||||
diffuse_texture = ExtResource("2_ah4id")
|
||||
normal_texture = ExtResource("3_ah4id")
|
||||
|
||||
[node name="Portal" type="Node2D"]
|
||||
[node name="Portal" type="Node2D" node_paths=PackedStringArray("sprite")]
|
||||
script = ExtResource("1_v7atq")
|
||||
sprite = NodePath("Sprite2D")
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
texture = ExtResource("2_ah4id")
|
||||
[node name="PlayerDetector" type="Area2D" parent="."]
|
||||
collision_layer = 0
|
||||
collision_mask = 16
|
||||
monitorable = false
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="PlayerDetector"]
|
||||
shape = SubResource("RectangleShape2D_v7atq")
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
||||
libraries = {
|
||||
|
@ -57,11 +92,21 @@ libraries = {
|
|||
}
|
||||
autoplay = "spin"
|
||||
|
||||
[node name="Area2D" type="Area2D" parent="."]
|
||||
collision_mask = 16
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
modulate = Color(0.627451, 0.12549, 0.941176, 1)
|
||||
self_modulate = Color(1, 1, 1, 0.75)
|
||||
light_mask = 32
|
||||
texture = SubResource("CanvasTexture_xxtm7")
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
|
||||
shape = SubResource("RectangleShape2D_v7atq")
|
||||
[node name="LightPivot" type="Node2D" parent="."]
|
||||
position = Vector2(-4, 4)
|
||||
|
||||
[connection signal="body_entered" from="Area2D" to="." method="_on_area_2d_body_entered"]
|
||||
[connection signal="body_exited" from="Area2D" to="." method="_on_area_2d_body_exited"]
|
||||
[node name="PointLight2D" type="PointLight2D" parent="LightPivot"]
|
||||
position = Vector2(4, 0)
|
||||
range_item_cull_mask = 32
|
||||
texture = ExtResource("4_xxtm7")
|
||||
texture_scale = 2.0
|
||||
height = 4.0
|
||||
|
||||
[connection signal="body_entered" from="PlayerDetector" to="." method="_on_player_detector_body_entered"]
|
||||
[connection signal="body_exited" from="PlayerDetector" to="." method="_on_player_detector_body_exited"]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue