private static Message ChaseTarget(Tile target, Tile chaser) { // The chaser will try to go in the directions that is closest to the player. // TODO: diff is a bad name but I can't think of a better on var diff = chaser.Location.NormalizedVector(target.Location); // diff suggests either go vertically or horizontally. Which is better? var verticalMove = chaser.Location + new Point(0, diff.Y); var horizontalMove = chaser.Location + new Point(diff.X, 0); if ( GetVectorLengthPointPoint(verticalMove, target.Location) < GetVectorLengthPointPoint(horizontalMove, target.Location) ) { // TODO: should this check for a collision on this move? If there is collision should monster try the horizontal move? return chaser.BuildMoveMessage(verticalMove); } if (GetVectorLengthPointPoint(horizontalMove, target.Location) < GetVectorLengthPointPoint(verticalMove, target.Location) ) { // TODO: should this check for a collision on this move? If there is collision should monster try the vertical move? return chaser.BuildMoveMessage(horizontalMove); } // if either is as good then, y is preferable to x // TODO: Make this better, it's pretty atbitrary. var direction = diff.Y != 0 ? new Point(0, diff.Y) : new Point(diff.X, 0); return chaser.BuildMoveMessage(chaser.Location + direction); }
private static Message ChaseTarget(Tile target, Tile chaser, TileSet statics) { var movementVector = chaser.Location.NormalizedVector(target.Location); var bestMove = new[]{ chaser.Location + new Point(0, movementVector.Y), //vertical chaser.Location + new Point(movementVector.X, 0)} //horizontal .OrderBy(m => m.Distance(target.Location)) // order on distance from player .FirstOrDefault(m => !statics.CollisionDetection(chaser, m).Collision); //pick first where there is no collision return bestMove != default(Point) ? chaser.BuildMoveMessage(bestMove) : null; }
private void ResolveReaction(Message message, char reationType) { if (message.To != GameConstants.NULL) { var point = message.To.ToPoint(); var stack = _mobiles.GetStack(point.X, point.Y); var offset = new Point(0, 0, stack.Count()); var tile = new Tile { IsTraversible = true, Token = reationType, Location = message.To.ToPoint() + offset }; _mobiles.Tiles.Add(tile); } else { var point = message.From.ToPoint(); var stack = _mobiles.GetStack(point.X, point.Y); _mobiles.Tiles.Remove(stack.Last()); } }
public CollisionInfo CollisionDetection(Tile mobile, Point destination) { var target = this[destination]; var collisionInfo = new CollisionInfo{ Tile = mobile, Vector = mobile.Location.NormalizedVector(destination)}; if (target != null) { collisionInfo.Collision = _collisionRules.All(r => r(mobile, target)); collisionInfo.Object = target; } if (collisionInfo.Tile != null && collisionInfo.Object != null && collisionInfo.Object != collisionInfo.Tile) { if (collisionInfo.Tile.OnCollision != null) collisionInfo.Messages.AddRange(collisionInfo.Tile.GetCollisionResponse(collisionInfo)); if (collisionInfo.Object.OnCollision != null) collisionInfo.Messages.AddRange(collisionInfo.Object.GetCollisionResponse(collisionInfo)); } return collisionInfo; }
private Message MovePlayer(Tile player, ControllerMessage message) { if (player.IsActive) { var destination = InputMap.Transform(message.Body, player.Location, 1); return player.BuildMoveMessage(destination); } return null; }
private static void Draw(Tile tile) { var sprite = SpriteSheet.Sprites[tile.Token]; Console.ForegroundColor = sprite.Item2; Console.Write(sprite.Item1); }
public bool WasReciever(Tile tile) { return Object.Name == tile.Name; }
public static bool FellInHole(this CollisionInfo info, Tile tile) { return info.Involves(GameConstants.HOLE, tile.Type); }
public static bool WasEatenByAMonster(this CollisionInfo info, Tile tile) { return info.Involves(GameConstants.STRONG_MONSTER, tile.Type); }
public static bool WasCrushedByBolder(this CollisionInfo info,Tile tile) { return info.InitiatorReceiverCheck(GameConstants.BOULDER, tile.Type); }