2019-12-19 21:24:40 +01:00
|
|
|
extends Node2D
|
2020-01-02 23:42:41 +01:00
|
|
|
# Wraps the ships' positions around the world border, and controls their rendering clones.
|
2019-12-19 21:24:40 +01:00
|
|
|
|
|
|
|
|
|
|
|
onready var ShipType: = preload("res://demos/pursue_vs_seek/Ship.gd")
|
2019-12-23 17:38:27 +01:00
|
|
|
onready var ships: = [$Player, $Pursuer, $Seeker]
|
2019-12-19 21:24:40 +01:00
|
|
|
|
|
|
|
var _clones: = {}
|
|
|
|
var _world_bounds: Vector2
|
|
|
|
|
|
|
|
|
|
|
|
func _ready() -> void:
|
|
|
|
_world_bounds = Vector2(
|
|
|
|
ProjectSettings["display/window/size/width"],
|
|
|
|
ProjectSettings["display/window/size/height"]
|
|
|
|
)
|
|
|
|
|
2019-12-23 17:38:27 +01:00
|
|
|
for i in range(ships.size()):
|
|
|
|
var ship: Node2D = ships[i]
|
2019-12-19 21:24:40 +01:00
|
|
|
var world_pos: = ship.position
|
|
|
|
|
|
|
|
for i in range(3):
|
2020-01-13 22:15:44 +01:00
|
|
|
var ship_clone: = ShipType.new()
|
2019-12-19 21:24:40 +01:00
|
|
|
|
|
|
|
ship_clone.position.x = world_pos.x if i == 1 else (world_pos.x - _world_bounds.x)
|
|
|
|
ship_clone.position.y = world_pos.y if i == 0 else (world_pos.y - _world_bounds.y)
|
|
|
|
ship_clone.rotation = ship.rotation
|
|
|
|
ship_clone.tag = i
|
2020-01-13 22:15:44 +01:00
|
|
|
ship_clone.name = ship.name + "Clone"
|
2019-12-19 21:24:40 +01:00
|
|
|
|
|
|
|
add_child(ship_clone)
|
2020-01-13 22:15:44 +01:00
|
|
|
ship_clone.generate_sprite(ship.get_node("Sprite"))
|
2019-12-19 21:24:40 +01:00
|
|
|
_clones[ship_clone] = ship
|
|
|
|
|
|
|
|
|
|
|
|
func _physics_process(delta: float) -> void:
|
|
|
|
for clone in _clones.keys():
|
|
|
|
var original: Node2D = _clones[clone]
|
|
|
|
var world_pos: Vector2 = original.position
|
|
|
|
|
|
|
|
if world_pos.y < 0:
|
|
|
|
original.position.y = _world_bounds.y + world_pos.y
|
|
|
|
elif world_pos.y > _world_bounds.y:
|
|
|
|
original.position.y = (world_pos.y - _world_bounds.y)
|
|
|
|
|
|
|
|
if world_pos.x < 0:
|
|
|
|
original.position.x = _world_bounds.x + world_pos.x
|
|
|
|
elif world_pos.x > _world_bounds.x:
|
|
|
|
original.position.x = (world_pos.x - _world_bounds.x)
|
|
|
|
|
|
|
|
var tag: int = clone.tag
|
|
|
|
if tag != 2:
|
|
|
|
if world_pos.x < _world_bounds.x/2:
|
|
|
|
clone.position.x = world_pos.x + _world_bounds.x
|
|
|
|
else:
|
|
|
|
clone.position.x = world_pos.x - _world_bounds.x
|
|
|
|
else:
|
|
|
|
clone.position.x = world_pos.x
|
|
|
|
|
|
|
|
if tag != 0:
|
|
|
|
if world_pos.y < _world_bounds.y/2:
|
|
|
|
clone.position.y = world_pos.y + _world_bounds.y
|
|
|
|
else:
|
|
|
|
clone.position.y = world_pos.y - _world_bounds.y
|
|
|
|
else:
|
|
|
|
clone.position.y = world_pos.y
|
|
|
|
clone.rotation = original.rotation
|