diff --git a/Shared/LinesOfSight.cs b/Shared/LinesOfSight.cs index 9832444..40a20a1 100644 --- a/Shared/LinesOfSight.cs +++ b/Shared/LinesOfSight.cs @@ -23,20 +23,13 @@ namespace SemiColinGames { public void Update(Player player, AABB[] collisionTargets) { Vector2 eyePos = player.EyePosition; + float visionRange = player.VisionRange; + Vector2 ray = player.VisionRay; - float visionRange = 150; float visionRangeSq = visionRange * visionRange; float fov = FMath.DegToRad(120); float fovStep = fov / (numEdgeVertices - 1); - Vector2 ray = new Vector2(visionRange * player.Facing, 0); - if (player.GetPose == Player.Pose.Stretching) { - ray = ray.Rotate(player.Facing * FMath.DegToRad(-30)); - } - if (player.GetPose == Player.Pose.Crouching) { - ray = ray.Rotate(player.Facing * FMath.DegToRad(30)); - } - coneVertices[0] = new VertexPositionColor(new Vector3(player.EyePosition, 0), color); for (int i = 0; i < numEdgeVertices; i++) { float angle = -fov / 2 + fovStep * i; diff --git a/Shared/Player.cs b/Shared/Player.cs index 1f2fc6b..68cfe49 100644 --- a/Shared/Player.cs +++ b/Shared/Player.cs @@ -5,7 +5,7 @@ using System.Collections.Generic; namespace SemiColinGames { class Player { - public enum Pose { Walking, Standing, Crouching, Stretching, SwordSwing, Jumping }; + private enum Pose { Walking, Standing, Crouching, Stretching, SwordSwing, Jumping }; private const int moveSpeed = 180; private const int jumpSpeed = -600; @@ -41,10 +41,6 @@ namespace SemiColinGames { public int Facing { get; private set; } = 1; - public Pose GetPose { - get { return pose; } - } - public Point Position { get { return position; } } public void Update(float modelTime, History input, AABB[] collisionTargets) { @@ -157,6 +153,25 @@ namespace SemiColinGames { } } + public float VisionRange { + get { + return 150; + } + } + + public Vector2 VisionRay { + get { + Vector2 ray = new Vector2(VisionRange * Facing, 0); + if (pose == Pose.Stretching) { + ray = ray.Rotate(Facing * FMath.DegToRad(-30)); + } + if (pose == Pose.Crouching) { + ray = ray.Rotate(Facing * FMath.DegToRad(30)); + } + return ray; + } + } + // Returns the desired (dx, dy) for the player to move this frame. Vector2 HandleInput(float modelTime, History input) { Vector2 result = new Vector2() {