ft: wrapping manager overhaul
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
class_name WrappingManager extends Node
|
||||
|
||||
@export var sprite: AnimatedSprite2D
|
||||
@export var shape: Node # FIXME (also in refactor see below) this is bad.
|
||||
@export var dupFlags: int = 15
|
||||
|
||||
# Mirrored sprites for periodic boundary
|
||||
var mirrors: Array
|
||||
@@ -10,29 +9,22 @@ var mirrors: Array
|
||||
func _ready() -> void:
|
||||
await owner.ready
|
||||
|
||||
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.call_deferred("add_child", m)
|
||||
# add mirrors
|
||||
for _i in range(3):
|
||||
var dup = owner.collision.duplicate(dupFlags)
|
||||
mirrors.append(dup)
|
||||
owner.call_deferred("add_child", dup)
|
||||
#for i in owner.get_groups():
|
||||
# if not str(i).begins_with("_"):
|
||||
# m.add_to_group(i)
|
||||
if dup.has_method("duplicate_init"):
|
||||
dup.duplicate_init()
|
||||
|
||||
_handle_wrapping()
|
||||
|
||||
func play_sprite(anim: String) -> void:
|
||||
mirrors[0].get_node("AnimatedSprite2D").play(anim)
|
||||
mirrors[1].get_node("AnimatedSprite2D").play(anim)
|
||||
mirrors[2].get_node("AnimatedSprite2D").play(anim)
|
||||
for m in mirrors:
|
||||
m.get_node("Sprite").play(anim)
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
_handle_wrapping()
|
||||
@@ -52,39 +44,42 @@ func _process(delta: float) -> void:
|
||||
# NOTE: For this to look correctly the camera size should be smaller than half the screen port (in
|
||||
# any one dimension. Ideally, the difference between camera size and half the screen port is
|
||||
# at least the size of the prey sprite)
|
||||
func _handle_wrapping():
|
||||
func _handle_wrapping():
|
||||
for m in mirrors:
|
||||
m.global_rotation = owner.collision.global_rotation
|
||||
|
||||
# TODO: Assume viewport size << screen size and only draw according to GameManager.viewport_size
|
||||
# Find corresponding section of the screen
|
||||
if owner.position.x < GameManager.screen_size.x/2 and owner.position.y < GameManager.screen_size.y/2:
|
||||
if owner.collision.position.x < GameManager.screen_size.x/2 and owner.collision.position.y < GameManager.screen_size.y/2:
|
||||
# Right
|
||||
mirrors[0].global_position = owner.global_position + Vector2(GameManager.screen_size.x, 0)
|
||||
mirrors[0].global_position = owner.collision.global_position + Vector2(GameManager.screen_size.x, 0)
|
||||
# Diag
|
||||
mirrors[2].global_position = owner.global_position + Vector2(GameManager.screen_size.x, GameManager.screen_size.y)
|
||||
mirrors[2].global_position = owner.collision.global_position + Vector2(GameManager.screen_size.x, GameManager.screen_size.y)
|
||||
# Bottom
|
||||
mirrors[1].global_position = owner.global_position + Vector2(0, GameManager.screen_size.y)
|
||||
mirrors[1].global_position = owner.collision.global_position + Vector2(0, GameManager.screen_size.y)
|
||||
|
||||
|
||||
elif owner.position.x < GameManager.screen_size.x/2:
|
||||
elif owner.collision.position.x < GameManager.screen_size.x/2:
|
||||
# Top
|
||||
mirrors[0].global_position = owner.global_position + Vector2(0, - GameManager.screen_size.y)
|
||||
mirrors[0].global_position = owner.collision.global_position + Vector2(0, - GameManager.screen_size.y)
|
||||
# Diag
|
||||
mirrors[1].global_position = owner.global_position + Vector2(GameManager.screen_size.x, - GameManager.screen_size.y)
|
||||
mirrors[1].global_position = owner.collision.global_position + Vector2(GameManager.screen_size.x, - GameManager.screen_size.y)
|
||||
# Right
|
||||
mirrors[2].global_position = owner.global_position + Vector2(GameManager.screen_size.x, 0)
|
||||
mirrors[2].global_position = owner.collision.global_position + Vector2(GameManager.screen_size.x, 0)
|
||||
|
||||
|
||||
elif owner.position.y < GameManager.screen_size.y/2:
|
||||
elif owner.collision.position.y < GameManager.screen_size.y/2:
|
||||
# Left
|
||||
mirrors[0].global_position = owner.global_position + Vector2(- GameManager.screen_size.x, 0)
|
||||
mirrors[0].global_position = owner.collision.global_position + Vector2(- GameManager.screen_size.x, 0)
|
||||
# Bottom
|
||||
mirrors[1].global_position = owner.global_position + Vector2(0, GameManager.screen_size.y)
|
||||
mirrors[1].global_position = owner.collision.global_position + Vector2(0, GameManager.screen_size.y)
|
||||
# Diag
|
||||
mirrors[2].global_position = owner.global_position + Vector2(- GameManager.screen_size.x, GameManager.screen_size.y)
|
||||
mirrors[2].global_position = owner.collision.global_position + Vector2(- GameManager.screen_size.x, GameManager.screen_size.y)
|
||||
|
||||
else:
|
||||
# Left
|
||||
mirrors[0].global_position = owner.global_position + Vector2(- GameManager.screen_size.x, 0)
|
||||
mirrors[0].global_position = owner.collision.global_position + Vector2(- GameManager.screen_size.x, 0)
|
||||
# Diag
|
||||
mirrors[1].global_position = owner.global_position + Vector2(- GameManager.screen_size.x, - GameManager.screen_size.y)
|
||||
mirrors[1].global_position = owner.collision.global_position + Vector2(- GameManager.screen_size.x, - GameManager.screen_size.y)
|
||||
# Top
|
||||
mirrors[2].global_position = owner.global_position + Vector2(0, - GameManager.screen_size.y)
|
||||
mirrors[2].global_position = owner.collision.global_position + Vector2(0, - GameManager.screen_size.y)
|
||||
|
||||
Reference in New Issue
Block a user