Player: make Facing an int property.
Partial work toward #21. GitOrigin-RevId: 902c46d19abb7c1a2c3a2aa3bfb344d52fa6a970
This commit is contained in:
parent
faa45d6fea
commit
c94ae6eb25
@ -29,12 +29,12 @@ namespace SemiColinGames {
|
|||||||
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.GetFacing, 0);
|
Vector2 ray = new Vector2(visionRange * player.Facing, 0);
|
||||||
if (player.GetPose == Player.Pose.Stretching) {
|
if (player.GetPose == Player.Pose.Stretching) {
|
||||||
ray = ray.Rotate(player.GetFacing * FMath.DegToRad(-30));
|
ray = ray.Rotate(player.Facing * FMath.DegToRad(-30));
|
||||||
}
|
}
|
||||||
if (player.GetPose == Player.Pose.Crouching) {
|
if (player.GetPose == Player.Pose.Crouching) {
|
||||||
ray = ray.Rotate(player.GetFacing * FMath.DegToRad(30));
|
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);
|
||||||
|
@ -5,12 +5,6 @@ using System.Collections.Generic;
|
|||||||
|
|
||||||
namespace SemiColinGames {
|
namespace SemiColinGames {
|
||||||
class Player {
|
class Player {
|
||||||
// The player's Facing corresponds to the x-direction that they're looking.
|
|
||||||
enum Facing {
|
|
||||||
Left = -1,
|
|
||||||
Right = 1
|
|
||||||
};
|
|
||||||
|
|
||||||
public enum Pose { Walking, Standing, Crouching, Stretching, SwordSwing, Jumping };
|
public enum Pose { Walking, Standing, Crouching, Stretching, SwordSwing, Jumping };
|
||||||
|
|
||||||
private const int moveSpeed = 180;
|
private const int moveSpeed = 180;
|
||||||
@ -35,7 +29,6 @@ namespace SemiColinGames {
|
|||||||
private Vector2 eyeOffsetWalking = new Vector2(15, -7);
|
private Vector2 eyeOffsetWalking = new Vector2(15, -7);
|
||||||
|
|
||||||
private int jumps = 0;
|
private int jumps = 0;
|
||||||
private Facing facing = Facing.Right;
|
|
||||||
private Pose pose = Pose.Jumping;
|
private Pose pose = Pose.Jumping;
|
||||||
private double swordSwingTime = 0;
|
private double swordSwingTime = 0;
|
||||||
private int swordSwingNum = 0;
|
private int swordSwingNum = 0;
|
||||||
@ -46,10 +39,7 @@ namespace SemiColinGames {
|
|||||||
this.texture = texture;
|
this.texture = texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: just make Facing an int.
|
public int Facing { get; private set; } = 1;
|
||||||
public int GetFacing {
|
|
||||||
get { return (int) facing; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public Pose GetPose {
|
public Pose GetPose {
|
||||||
get { return pose; }
|
get { return pose; }
|
||||||
@ -139,9 +129,9 @@ namespace SemiColinGames {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (movement.X > 0) {
|
if (movement.X > 0) {
|
||||||
facing = Facing.Right;
|
Facing = 1;
|
||||||
} else if (movement.X < 0) {
|
} else if (movement.X < 0) {
|
||||||
facing = Facing.Left;
|
Facing = -1;
|
||||||
}
|
}
|
||||||
if (swordSwingTime > 0) {
|
if (swordSwingTime > 0) {
|
||||||
pose = Pose.SwordSwing;
|
pose = Pose.SwordSwing;
|
||||||
@ -163,7 +153,7 @@ namespace SemiColinGames {
|
|||||||
bool walking = pose == Pose.Walking || pose == Pose.Jumping;
|
bool walking = pose == Pose.Walking || pose == Pose.Jumping;
|
||||||
Vector2 eyeOffset = walking ? eyeOffsetWalking : eyeOffsetStanding;
|
Vector2 eyeOffset = walking ? eyeOffsetWalking : eyeOffsetStanding;
|
||||||
return Vector2.Add(
|
return Vector2.Add(
|
||||||
Position.ToVector2(), new Vector2(eyeOffset.X * (int) facing, eyeOffset.Y));
|
Position.ToVector2(), new Vector2(eyeOffset.X * Facing, eyeOffset.Y));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,7 +210,7 @@ namespace SemiColinGames {
|
|||||||
int index = SpriteIndex(pose);
|
int index = SpriteIndex(pose);
|
||||||
Rectangle textureSource = new Rectangle(index * spriteWidth, 0, spriteWidth, spriteHeight);
|
Rectangle textureSource = new Rectangle(index * spriteWidth, 0, spriteWidth, spriteHeight);
|
||||||
Vector2 spriteCenter = new Vector2(spriteWidth / 2, spriteHeight / 2 + spriteCenterYOffset);
|
Vector2 spriteCenter = new Vector2(spriteWidth / 2, spriteHeight / 2 + spriteCenterYOffset);
|
||||||
SpriteEffects effect = facing == Facing.Right ?
|
SpriteEffects effect = Facing == 1 ?
|
||||||
SpriteEffects.FlipHorizontally : SpriteEffects.None;
|
SpriteEffects.FlipHorizontally : SpriteEffects.None;
|
||||||
spriteBatch.Draw(texture, position.ToVector2(), textureSource, Color.White, 0f, spriteCenter,
|
spriteBatch.Draw(texture, position.ToVector2(), textureSource, Color.White, 0f, spriteCenter,
|
||||||
Vector2.One, effect, 0f);
|
Vector2.One, effect, 0f);
|
||||||
|
Loading…
Reference in New Issue
Block a user