示例#1
0
文件: Enemy.cs 项目: Hugomka/SE2Game
 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;
        }
示例#3
0
文件: Util.cs 项目: Hugomka/SE2Game
 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;
     }
 }
示例#4
0
        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;
        }
示例#5
0
 public AIMove()
 {
     currentDirection = new Vector();
     lastUpdate = World.Instance.Time;
 }
 public MoveLogicRandom()
 {
     currentDirection = new Vector();
     lastUpdate = World.Instance.Time;
 }
示例#7
0
 public Enemy(Vector position)
 {
     this.Position = position;
     this.Sprite = new Sprite("sprites/sprites.png", new Point(3, 0));
 }
示例#8
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);
            }
        }
示例#9
0
 public Vector(Vector v)
     : this(v.X, v.Y)
 {
 }
示例#10
0
文件: Map.cs 项目: Hugomka/SE2Game
 /// <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;
 }
示例#11
0
文件: Map.cs 项目: Hugomka/SE2Game
 /// <summary>
 /// Converts a coordinate to a cell index.
 /// </summary>
 public Point PointToCell(Vector v)
 {
     return PointToCell(Convert.ToInt32(v.X), Convert.ToInt32(v.Y));
 }
示例#12
0
文件: Map.cs 项目: Hugomka/SE2Game
 public CellContent CellContentAtPoint(Vector v)
 {
     Point p = PointToCell(Convert.ToInt32(v.X), Convert.ToInt32(v.Y));
     return cells[p.X, p.Y];
 }
示例#13
0
 public Player(Vector position)
     : base(position)
 {
     sprite = new Sprite("sprites/sprites.png", new Point(0, 0));
     Hitpoints = 100;
 }
示例#14
0
 public Player(Vector position)
 {
     this.Position = position;
     this.Sprite = new Sprite("sprites/sprites.png", new Point(0, 0));
     Hitpoints = 100;
 }
示例#15
0
文件: Boots.cs 项目: Hugomka/SE2Game
 public Boots(Vector position)
     : base("Boots", position)
 {
     image = System.Drawing.Image.FromFile("sprites/boots.png");
 }
示例#16
0
文件: Item.cs 项目: Hugomka/SE2Game
 public Item(string name, Vector position)
 {
     Name = name;
     Position = position;
 }
示例#17
0
文件: Key.cs 项目: Hugomka/SE2Game
 public Key(Vector position)
     : base("Key", position)
 {
     image = System.Drawing.Image.FromFile("sprites/key.png");
 }
示例#18
0
文件: Helmet.cs 项目: Hugomka/SE2Game
 public Helmet(Vector position)
     : base("Helmet", position)
 {
     image = System.Drawing.Image.FromFile("sprites/helmet.png");
 }