camera bounds
parent
3fed7f1171
commit
33e47f640f
|
@ -2,26 +2,36 @@ using Godot;
|
|||
|
||||
namespace SupaLidlGame.BoundingBoxes;
|
||||
|
||||
public partial class CameraBounds : Node
|
||||
public partial class CameraBounds : Node2D
|
||||
{
|
||||
[Export]
|
||||
public Area2D Trigger { get; set; }
|
||||
|
||||
//[Export]
|
||||
//public Rect2I Bounds { get; set; }
|
||||
|
||||
[Export]
|
||||
public RectangleShape2D Bounds { get; set; }
|
||||
public Marker2D TopLeft { get; set; }
|
||||
|
||||
[Export]
|
||||
public Marker2D BottomRight { get; set; }
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
Trigger.BodyEntered += OnBodyEntered;
|
||||
Trigger.BodyExited += OnBodyExited;
|
||||
base._Ready();
|
||||
}
|
||||
|
||||
private void OnBodyEntered(Node2D body)
|
||||
{
|
||||
GD.Print("body entered " + body.Name);
|
||||
if (body is Characters.Player player)
|
||||
{
|
||||
var camera = player.Camera;
|
||||
var rect = new Rect2I();
|
||||
rect.Position = (Vector2I)TopLeft.GlobalPosition;
|
||||
rect.End = (Vector2I)BottomRight.GlobalPosition;
|
||||
camera.SetCameraBounds(rect);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -30,7 +40,10 @@ public partial class CameraBounds : Node
|
|||
if (body is Characters.Player player)
|
||||
{
|
||||
var camera = player.Camera;
|
||||
camera.LimitLeft = -1024;
|
||||
camera.LimitLeft = int.MinValue;
|
||||
camera.LimitTop = int.MinValue;
|
||||
camera.LimitRight = int.MaxValue;
|
||||
camera.LimitBottom = int.MaxValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
[gd_scene load_steps=3 format=3 uid="uid://malbos18dh7l"]
|
||||
|
||||
[ext_resource type="Script" path="res://BoundingBoxes/CameraBounds.cs" id="1_vaknk"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_b2lli"]
|
||||
size = Vector2(256, 272)
|
||||
|
||||
[node name="CameraBounds" type="Node2D" node_paths=PackedStringArray("Trigger")]
|
||||
position = Vector2(0, -89)
|
||||
script = ExtResource("1_vaknk")
|
||||
Trigger = NodePath("Area2D")
|
||||
|
||||
[node name="Area2D" type="Area2D" parent="."]
|
||||
collision_layer = 0
|
||||
collision_mask = 4
|
||||
monitorable = false
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
|
||||
shape = SubResource("RectangleShape2D_b2lli")
|
||||
debug_color = Color(0.631373, 0.345098, 1, 0.419608)
|
||||
|
||||
[node name="TopLeft" type="Marker2D" parent="."]
|
||||
position = Vector2(-256, -40)
|
||||
|
||||
[node name="BottomRight" type="Marker2D" parent="."]
|
||||
position = Vector2(256, 216)
|
File diff suppressed because one or more lines are too long
|
@ -46,4 +46,21 @@ public partial class PlayerCamera : Camera2D
|
|||
ret.Y = (rng.Randf() - 0.5f) * intensity;
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void SetCameraBoundsToMap(Scenes.Map map)
|
||||
{
|
||||
//var bounds = map.GetUsedRect();
|
||||
//LimitLeft = bounds.Position;
|
||||
|
||||
}
|
||||
|
||||
public void SetCameraBounds(Rect2I rect)
|
||||
{
|
||||
var start = rect.Position;
|
||||
var end = rect.End;
|
||||
LimitLeft = start.X;
|
||||
LimitTop = start.Y;
|
||||
LimitRight = end.X;
|
||||
LimitBottom = end.Y;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
[node name="Camera2D" type="Camera2D"]
|
||||
zoom = Vector2(2, 2)
|
||||
process_callback = 0
|
||||
limit_smoothed = true
|
||||
position_smoothing_speed = 32.0
|
||||
script = ExtResource("1_jabhk")
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
||||
|
|
Loading…
Reference in New Issue