Player: remove GetPose, add VisionRange and VisionRay.
Fixes #21. GitOrigin-RevId: 720972d1c8bd989edc38289f2e66e91290cf0134
This commit is contained in:
parent
c94ae6eb25
commit
66f895fab8
@ -23,20 +23,13 @@ namespace SemiColinGames {
|
|||||||
|
|
||||||
public void Update(Player player, AABB[] collisionTargets) {
|
public void Update(Player player, AABB[] collisionTargets) {
|
||||||
Vector2 eyePos = player.EyePosition;
|
Vector2 eyePos = player.EyePosition;
|
||||||
|
float visionRange = player.VisionRange;
|
||||||
|
Vector2 ray = player.VisionRay;
|
||||||
|
|
||||||
float visionRange = 150;
|
|
||||||
float visionRangeSq = visionRange * visionRange;
|
float visionRangeSq = visionRange * visionRange;
|
||||||
float fov = FMath.DegToRad(120);
|
float fov = FMath.DegToRad(120);
|
||||||
float fovStep = fov / (numEdgeVertices - 1);
|
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);
|
coneVertices[0] = new VertexPositionColor(new Vector3(player.EyePosition, 0), color);
|
||||||
for (int i = 0; i < numEdgeVertices; i++) {
|
for (int i = 0; i < numEdgeVertices; i++) {
|
||||||
float angle = -fov / 2 + fovStep * i;
|
float angle = -fov / 2 + fovStep * i;
|
||||||
|
@ -5,7 +5,7 @@ using System.Collections.Generic;
|
|||||||
|
|
||||||
namespace SemiColinGames {
|
namespace SemiColinGames {
|
||||||
class Player {
|
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 moveSpeed = 180;
|
||||||
private const int jumpSpeed = -600;
|
private const int jumpSpeed = -600;
|
||||||
@ -41,10 +41,6 @@ namespace SemiColinGames {
|
|||||||
|
|
||||||
public int Facing { get; private set; } = 1;
|
public int Facing { get; private set; } = 1;
|
||||||
|
|
||||||
public Pose GetPose {
|
|
||||||
get { return pose; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public Point Position { get { return position; } }
|
public Point Position { get { return position; } }
|
||||||
|
|
||||||
public void Update(float modelTime, History<Input> input, AABB[] collisionTargets) {
|
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.
|
// Returns the desired (dx, dy) for the player to move this frame.
|
||||||
Vector2 HandleInput(float modelTime, History<Input> input) {
|
Vector2 HandleInput(float modelTime, History<Input> input) {
|
||||||
Vector2 result = new Vector2() {
|
Vector2 result = new Vector2() {
|
||||||
|
Loading…
Reference in New Issue
Block a user