From 66f895fab81efe95f4aa67e4305b572ac77c000e Mon Sep 17 00:00:00 2001 From: Colin McMillen Date: Sat, 15 Feb 2020 14:56:42 -0500 Subject: [PATCH] Player: remove GetPose, add VisionRange and VisionRay. Fixes #21. GitOrigin-RevId: 720972d1c8bd989edc38289f2e66e91290cf0134 --- Shared/LinesOfSight.cs | 11 ++--------- Shared/Player.cs | 25 ++++++++++++++++++++----- 2 files changed, 22 insertions(+), 14 deletions(-) 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() {