Warp player to other side when reaching boundary

This commit is contained in:
DeathByDenim 2023-05-19 06:36:11 -04:00
parent b0d5b6d906
commit bf28e6ee01
Signed by: DeathByDenim
GPG Key ID: 4A475283D925365B
3 changed files with 15 additions and 1 deletions

View File

@ -38,7 +38,6 @@ script = ExtResource("2_ehys6")
polygon = PackedVector2Array(31, 0, -29, -28, -29, 28)
[node name="Camera2D" type="Camera2D" parent="."]
position_smoothing_enabled = true
[node name="Muzzle main" type="Marker2D" parent="."]
position = Vector2(42, 0)

View File

@ -144,3 +144,16 @@ func apply_options():
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass
func _on_map_boundaries_body_exited(body):
var width = int(options["mapwidth"])
var height = int(options["mapheight"])
if body.position.x < $"Map boundaries".position.x - 32*width:
body.position.x += 64 * width
elif body.position.x > $"Map boundaries".position.x + 32*width:
body.position.x -= 64 * width
if body.position.y < $"Map boundaries".position.y - 32*height:
body.position.y += 64 * height
elif body.position.y > $"Map boundaries".position.y + 32*height:
body.position.y -= 64 * height

View File

@ -180,3 +180,5 @@ shape = SubResource("RectangleShape2D_hjo0t")
_spawnable_scenes = PackedStringArray("res://World/PlayerShip.tscn")
spawn_path = NodePath("../Players")
spawn_limit = 4
[connection signal="body_exited" from="Map boundaries" to="." method="_on_map_boundaries_body_exited"]