|
|
|
|
@@ -1,30 +1,38 @@
|
|
|
|
|
class_name WrappingManager extends Node
|
|
|
|
|
|
|
|
|
|
@export var sprite: AnimatedSprite2D
|
|
|
|
|
@export var shape: Node # FIXME (also in refactor see below) this is bad.
|
|
|
|
|
|
|
|
|
|
# Mirrored sprites for periodic boundary
|
|
|
|
|
var mirrorSprite1: Node2D
|
|
|
|
|
var mirrorSprite2: Node2D
|
|
|
|
|
var mirrorSprite3: Node2D
|
|
|
|
|
|
|
|
|
|
var mirrors: Array
|
|
|
|
|
|
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
|
|
|
func _ready() -> void:
|
|
|
|
|
await owner.ready
|
|
|
|
|
mirrorSprite1 = sprite.duplicate()
|
|
|
|
|
mirrorSprite2 = sprite.duplicate()
|
|
|
|
|
mirrorSprite3 = sprite.duplicate()
|
|
|
|
|
|
|
|
|
|
owner.add_child(mirrorSprite1)
|
|
|
|
|
owner.add_child(mirrorSprite2)
|
|
|
|
|
owner.add_child(mirrorSprite3)
|
|
|
|
|
|
|
|
|
|
mirrors.append(Area2D.new())
|
|
|
|
|
mirrors.append(Area2D.new())
|
|
|
|
|
mirrors.append(Area2D.new())
|
|
|
|
|
|
|
|
|
|
# TODO: npc overhaul; make npc2d (and child classes) inherit from Node instead of Area2d.
|
|
|
|
|
# Each entity should have Area2d -> collisionshape2d + animatedsprite2d. We then duplicate this area2d instead of the bullshit thats happening here
|
|
|
|
|
# note taht the below bs also does not work, as the (freshly instantiated) area2ds have none of the signals connected. The above refactor will fix this.
|
|
|
|
|
for m in mirrors:
|
|
|
|
|
for i in owner.get_groups():
|
|
|
|
|
if not str(i).begins_with("_"):
|
|
|
|
|
m.add_to_group(i)
|
|
|
|
|
m.set_collision_layer(owner.get_collision_layer())
|
|
|
|
|
m.set_collision_mask(owner.get_collision_mask())
|
|
|
|
|
m.add_child(sprite.duplicate())
|
|
|
|
|
m.add_child(shape.duplicate())
|
|
|
|
|
owner.add_child(m)
|
|
|
|
|
|
|
|
|
|
_handle_wrapping()
|
|
|
|
|
|
|
|
|
|
func play_sprite(anim: String) -> void:
|
|
|
|
|
mirrorSprite1.play(anim)
|
|
|
|
|
mirrorSprite2.play(anim)
|
|
|
|
|
mirrorSprite3.play(anim)
|
|
|
|
|
mirrors[0].get_node("AnimatedSprite2D").play(anim)
|
|
|
|
|
mirrors[1].get_node("AnimatedSprite2D").play(anim)
|
|
|
|
|
mirrors[2].get_node("AnimatedSprite2D").play(anim)
|
|
|
|
|
|
|
|
|
|
func _process(delta: float) -> void:
|
|
|
|
|
_handle_wrapping()
|
|
|
|
|
@@ -49,34 +57,34 @@ func _handle_wrapping():
|
|
|
|
|
# Find corresponding section of the screen
|
|
|
|
|
if owner.position.x < GameManager.screen_size.x/2 and owner.position.y < GameManager.screen_size.y/2:
|
|
|
|
|
# Right
|
|
|
|
|
mirrorSprite1.global_position = owner.global_position + Vector2(GameManager.screen_size.x, 0)
|
|
|
|
|
mirrors[0].global_position = owner.global_position + Vector2(GameManager.screen_size.x, 0)
|
|
|
|
|
# Diag
|
|
|
|
|
mirrorSprite3.global_position = owner.global_position + Vector2(GameManager.screen_size.x, GameManager.screen_size.y)
|
|
|
|
|
mirrors[2].global_position = owner.global_position + Vector2(GameManager.screen_size.x, GameManager.screen_size.y)
|
|
|
|
|
# Bottom
|
|
|
|
|
mirrorSprite2.global_position = owner.global_position + Vector2(0, GameManager.screen_size.y)
|
|
|
|
|
mirrors[1].global_position = owner.global_position + Vector2(0, GameManager.screen_size.y)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
elif owner.position.x < GameManager.screen_size.x/2:
|
|
|
|
|
# Top
|
|
|
|
|
mirrorSprite1.global_position = owner.global_position + Vector2(0, - GameManager.screen_size.y)
|
|
|
|
|
mirrors[0].global_position = owner.global_position + Vector2(0, - GameManager.screen_size.y)
|
|
|
|
|
# Diag
|
|
|
|
|
mirrorSprite2.global_position = owner.global_position + Vector2(GameManager.screen_size.x, - GameManager.screen_size.y)
|
|
|
|
|
mirrors[1].global_position = owner.global_position + Vector2(GameManager.screen_size.x, - GameManager.screen_size.y)
|
|
|
|
|
# Right
|
|
|
|
|
mirrorSprite3.global_position = owner.global_position + Vector2(GameManager.screen_size.x, 0)
|
|
|
|
|
mirrors[2].global_position = owner.global_position + Vector2(GameManager.screen_size.x, 0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
elif owner.position.y < GameManager.screen_size.y/2:
|
|
|
|
|
# Left
|
|
|
|
|
mirrorSprite1.global_position = owner.global_position + Vector2(- GameManager.screen_size.x, 0)
|
|
|
|
|
mirrors[0].global_position = owner.global_position + Vector2(- GameManager.screen_size.x, 0)
|
|
|
|
|
# Bottom
|
|
|
|
|
mirrorSprite2.global_position = owner.global_position + Vector2(0, GameManager.screen_size.y)
|
|
|
|
|
mirrors[1].global_position = owner.global_position + Vector2(0, GameManager.screen_size.y)
|
|
|
|
|
# Diag
|
|
|
|
|
mirrorSprite3.global_position = owner.global_position + Vector2(- GameManager.screen_size.x, GameManager.screen_size.y)
|
|
|
|
|
mirrors[2].global_position = owner.global_position + Vector2(- GameManager.screen_size.x, GameManager.screen_size.y)
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
# Left
|
|
|
|
|
mirrorSprite1.global_position = owner.global_position + Vector2(- GameManager.screen_size.x, 0)
|
|
|
|
|
mirrors[0].global_position = owner.global_position + Vector2(- GameManager.screen_size.x, 0)
|
|
|
|
|
# Diag
|
|
|
|
|
mirrorSprite2.global_position = owner.global_position + Vector2(- GameManager.screen_size.x, - GameManager.screen_size.y)
|
|
|
|
|
mirrors[1].global_position = owner.global_position + Vector2(- GameManager.screen_size.x, - GameManager.screen_size.y)
|
|
|
|
|
# Top
|
|
|
|
|
mirrorSprite3.global_position = owner.global_position + Vector2(0, - GameManager.screen_size.y)
|
|
|
|
|
mirrors[2].global_position = owner.global_position + Vector2(0, - GameManager.screen_size.y)
|
|
|
|
|
|