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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue