public Enemy(Vector position, IMoveLogic moveLogic) : base(position) { sprite = new Sprite("sprites/sprites.png", new Point(3, 0)); this.moveLogic = moveLogic; maxSpeed = 65; }
public Vector MakeMove(Vector currentPosition, Vector targetPosition) { // Change direction every half second if (World.Instance.Time - lastUpdate > World.Instance.RandomNumber(400, 600)) { switch (World.Instance.RandomNumber(5)) { case 0: currentDirection = new Vector(1, 0); break; case 1: currentDirection = new Vector(0, 1); break; case 2: currentDirection = new Vector(-1, 0); break; case 3: currentDirection = new Vector(0, -1); break; default: currentDirection = new Vector(0, 0); break; } lastUpdate = World.Instance.Time; } return currentDirection; }
public static Direction DetermineDirection(Vector v) { if (Math.Abs(v.X) >= Math.Abs(v.Y)) { if (v.X >= 0) { return Direction.Right; } return Direction.Left; } else { if (v.Y >= 0) { return Direction.Down; } return Direction.Up; } }
public Vector MakeMove(Vector currentPosition, Vector targetPosition) { // Change direction every half second if (World.Instance.Time - lastUpdate > World.Instance.RandomNumber(400, 600)) { //go to player - Not working /* if(currentPosition.X >= targetPosition.X) { currentDirection = new Vector(1,0); } if(currentPosition.Y >= targetPosition.Y) { currentDirection = new Vector(0,1); } if(currentPosition.X <= targetPosition.X) { currentDirection = new Vector(-1,0); } if(currentPosition.Y <= targetPosition.Y) { currentDirection = new Vector(0,-1); } else { currentDirection = new Vector(1,0); }*/ switch (World.Instance.RandomNumber(4)) { case 0: currentDirection = new Vector(targetPosition.X-currentPosition.X, 0); break; case 1: currentDirection = new Vector(0, currentPosition.Y-targetPosition.Y); break; case 2: currentDirection = new Vector(-(targetPosition.X-currentPosition.X), 0); break; case 3: currentDirection = new Vector(0, -(currentPosition.Y-targetPosition.Y)); break; default: currentDirection = new Vector(0, 0); break; } lastUpdate = World.Instance.Time; } return currentDirection; }
public AIMove() { currentDirection = new Vector(); lastUpdate = World.Instance.Time; }
public MoveLogicRandom() { currentDirection = new Vector(); lastUpdate = World.Instance.Time; }
public Enemy(Vector position) { this.Position = position; this.Sprite = new Sprite("sprites/sprites.png", new Point(3, 0)); }
public void Update(float dt) { // Determine the action that is to be taken Move(); // Update the sprite state to reflect that we are moving or not if (direction.X != 0 || direction.Y != 0) { sprite.ChangeState(Sprite.State.Moving); } else { sprite.ChangeState(Sprite.State.Idle); } if (sprite.SpriteState == Sprite.State.Moving) { Direction spriteDirection = Util.DetermineDirection(direction); Vector newPosition = new Vector(position); switch (spriteDirection) { case Direction.Left: newPosition.X -= maxSpeed * dt; break; case Direction.Right: newPosition.X += maxSpeed * dt; break; case Direction.Up: newPosition.Y -= maxSpeed * dt; break; case Direction.Down: newPosition.Y += maxSpeed * dt; break; } int hss = Sprite.Size / 2; newPosition.X = Math.Max(hss, Math.Min(World.Instance.Size.Width - hss, newPosition.X)); newPosition.Y = Math.Max(hss, Math.Min(World.Instance.Size.Height - hss, newPosition.Y)); Vector feetPosition = (newPosition + new Vector(0, Sprite.Size / 2.2)); if (World.Instance.Map.Reachable(feetPosition)) { position = newPosition; } sprite.UpdateImage(spriteDirection); } }
public Vector(Vector v) : this(v.X, v.Y) { }
/// <summary> /// Returns true if the given position does not intersect an non-passable cell. /// </summary> public bool Reachable(Vector v) { return CellContentAtPoint(v) != CellContent.Wall; }
/// <summary> /// Converts a coordinate to a cell index. /// </summary> public Point PointToCell(Vector v) { return PointToCell(Convert.ToInt32(v.X), Convert.ToInt32(v.Y)); }
public CellContent CellContentAtPoint(Vector v) { Point p = PointToCell(Convert.ToInt32(v.X), Convert.ToInt32(v.Y)); return cells[p.X, p.Y]; }
public Player(Vector position) : base(position) { sprite = new Sprite("sprites/sprites.png", new Point(0, 0)); Hitpoints = 100; }
public Player(Vector position) { this.Position = position; this.Sprite = new Sprite("sprites/sprites.png", new Point(0, 0)); Hitpoints = 100; }
public Boots(Vector position) : base("Boots", position) { image = System.Drawing.Image.FromFile("sprites/boots.png"); }
public Item(string name, Vector position) { Name = name; Position = position; }
public Key(Vector position) : base("Key", position) { image = System.Drawing.Image.FromFile("sprites/key.png"); }
public Helmet(Vector position) : base("Helmet", position) { image = System.Drawing.Image.FromFile("sprites/helmet.png"); }