Ugly but working solution to being able to actually lose the game now

master
BraydonKains 5 years ago
parent 51f5d963cd
commit d7cc841ad8

@ -19,7 +19,7 @@ namespace SeeNoEvil.Character {
}
}
private void ChooseAnimation(Direction direction) {
public void ChooseAnimation(Direction direction) {
switch(direction) {
case Direction.Up:
AnimationController.ChangeAnimation(3);

@ -10,6 +10,7 @@ namespace SeeNoEvil.Character {
public Vector2 Position {get; private set;}
private Texture2D SpriteSheet;
protected Vector2 StartingPosition;
protected AnimationController AnimationController;
protected int Width;
protected int Height;
@ -23,6 +24,7 @@ namespace SeeNoEvil.Character {
public Character(Vector2 position) {
Position = position;
StartingPosition = position;
Destination = Vector2.Zero;
Velocity = Vector2.Zero;
}
@ -52,7 +54,7 @@ namespace SeeNoEvil.Character {
public virtual void Move(Direction direction) {
if(!Moving) {
int velocity = 1;
int velocity = 16;
int x = 0, y = 0;
switch(direction) {
case Direction.Up:
@ -72,9 +74,16 @@ namespace SeeNoEvil.Character {
if(Field.TryWalk(tryPosition)) {
Destination = Vector2.Add(Position, new Vector2(Width*x, Height*y));
Velocity = new Vector2(x*velocity, y*velocity);
Facing = direction;
}
}
}
public void Reset() {
Position = StartingPosition;
Destination = Vector2.Zero;
Velocity = Vector2.Zero;
}
}
public enum Direction {
Up,

@ -28,8 +28,12 @@ namespace SeeNoEvil.Character {
public void MoveGhosts() =>
Ghosts.ForEach(ghost => ghost.DecideMove());
public bool AreGhostsHere(IEnumerable<Vector2> lineOfSight) =>
Ghosts.Any(ghost => lineOfSight.Contains(ghost.Position));
public bool AreGhostsHere(Vector2 playerPosition, Direction direction) =>
Ghosts.Any(ghost => ghost.IsInSight(playerPosition, direction));
// public bool AreGhostsHere(Vector2 playerPosition, Direction direction, out Ghost ghost) {
// ghost = Ghosts.FirstOrDefault(ghost => ghost.IsInSight(playerPosition, direction));
// return ghost != null;
// }
}
public class Ghost : Character {
@ -61,5 +65,21 @@ namespace SeeNoEvil.Character {
base.Move(randomDirection);
}
// FIXME This shit is ugly
public bool IsInSight(Vector2 playerPosition, Direction direction) {
if(direction == Direction.Up)
return playerPosition.X == Position.X &&
(playerPosition.Y > Position.Y) && (Position.Y > playerPosition.Y-32*9);
else if(direction == Direction.Down)
return playerPosition.X == Position.X &&
(playerPosition.Y < Position.Y) && (Position.Y < playerPosition.Y+32*9);
else if(direction == Direction.Left)
return playerPosition.Y == Position.Y &&
(playerPosition.X > Position.X) && (Position.X > playerPosition.X-32*9);
else
return playerPosition.Y == Position.Y &&
(playerPosition.X < Position.X) && (Position.X < playerPosition.X+32*9);
}
}
}

@ -17,10 +17,6 @@ namespace SeeNoEvil.Level {
public bool TryWalk(Vector2 newLocation) =>
Tiles.Any(tile => tile.location.Equals(newLocation) && tile.tile.gid != 0);
public IEnumerable<Vector2> GetLineOfSight(Direction facing, Vector2 position) {
return new List<Vector2>();
}
private bool Between(float pos1, float pos2, float bound) =>
(bound - pos1) >= (pos2 - pos1);
}

@ -21,12 +21,15 @@ namespace SeeNoEvil
GhostController enemyController;
PlayField playField;
bool scared;
int scaredTimer = 0;
Ghost debugGhost;
public SeeNoEvilGame()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
IsMouseVisible = true;
debugGhost = null;
}
protected override void Initialize()
@ -55,29 +58,39 @@ namespace SeeNoEvil
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
Exit();
if(Keyboard.GetState().IsKeyDown(Keys.Down)) {
player.Move(Direction.Down);
enemyController.MoveGhosts();
}
if(Keyboard.GetState().IsKeyDown(Keys.Up)) {
player.Move(Direction.Up);
enemyController.MoveGhosts();
}
if(Keyboard.GetState().IsKeyDown(Keys.Left)) {
player.Move(Direction.Left);
enemyController.MoveGhosts();
}
if(Keyboard.GetState().IsKeyDown(Keys.Right)) {
player.Move(Direction.Right);
enemyController.MoveGhosts();
}
player.Update();
enemyController.UpdateAll();
camera.Update(player.Position);
if(!player.Moving)
scared = enemyController.AreGhostsHere(playField.GetLineOfSight(player.Facing, player.Position));
if(scared)
player.Scared();
if(scaredTimer == 0) {
if(Keyboard.GetState().IsKeyDown(Keys.Down)) {
player.Move(Direction.Down);
enemyController.MoveGhosts();
}
if(Keyboard.GetState().IsKeyDown(Keys.Up)) {
player.Move(Direction.Up);
enemyController.MoveGhosts();
}
if(Keyboard.GetState().IsKeyDown(Keys.Left)) {
player.Move(Direction.Left);
enemyController.MoveGhosts();
}
if(Keyboard.GetState().IsKeyDown(Keys.Right)) {
player.Move(Direction.Right);
enemyController.MoveGhosts();
}
player.Update();
enemyController.UpdateAll();
camera.Update(player.Position);
if(!player.Moving) {
scared = enemyController.AreGhostsHere(player.Position, player.Facing);
}
if(scared) {
player.Scared();
scaredTimer = 60;
}
} else if(scaredTimer == 1) {
scared = false;
player.Reset();
player.ChooseAnimation(player.Facing);
scaredTimer = 0;
} else scaredTimer--;
base.Update(gameTime);
}

Loading…
Cancel
Save