Player: remove GetPose, add VisionRange and VisionRay.

Fixes #21.

GitOrigin-RevId: 720972d1c8bd989edc38289f2e66e91290cf0134
This commit is contained in:
Colin McMillen 2020-02-15 14:56:42 -05:00
parent c94ae6eb25
commit 66f895fab8
2 changed files with 22 additions and 14 deletions

View File

@ -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;

View File

@ -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> 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> input) {
Vector2 result = new Vector2() {