示例#1
0
文件: Enemy.cs 项目: isaac109/engine
 public void checkIfIsColliding()
 {
     if (this._isColliding)
     {
         if (_horizontal)
         {
             if (direction == Direction.LEFT)
             {
                 direction = Direction.RIGHT;
                 this._isColliding = false;
             }
             else
             {
                 direction = Direction.LEFT;
                 this._isColliding = false;
             }
         }
         else
         {
             if (direction == Direction.UP)
             {
                 direction = Direction.DOWN;
                 this._isColliding = false;
             }
             else
             {
                 direction = Direction.UP;
                 this._isColliding = false;
             }
         }
     }
 }
示例#2
0
文件: Room.cs 项目: gbahns/MazeGame
		internal void RemoveConnector (Direction d)
		{
			IMapSite c = Neighbors[d];
			if (c is Connector)
			{
				Join(c.Neighbors[d],d);
			}
		}
示例#3
0
		//provide default implementations that do nothing

		protected Connector (Room r1, Direction d)
		{
			Room r2 = (Room)r1.Neighbors[d];

			r1.Neighbors[d] = this;
			Neighbors[d] = r2;

			r2.Neighbors[d.opposite] = this;
			Neighbors[d.opposite] = r1;
		}
示例#4
0
文件: Room.cs 项目: gbahns/MazeGame
		public RectangleF GetBorderLine (Direction d)
		{
			switch (d.direction)
			{
				case Compass.North: return new RectangleF(Bounds.Left,Bounds.Top,Bounds.Width,0);
				case Compass.South: return new RectangleF(Bounds.Left,Bounds.Bottom,Bounds.Width,0);
				case Compass.West: return new RectangleF(Bounds.Left,Bounds.Top,0,Bounds.Height);
				case Compass.East: return new RectangleF(Bounds.Right,Bounds.Top,0,Bounds.Height);
				default: return new RectangleF();
			}
		}
示例#5
0
		public void MovePlayer (Direction d)
		{
			if (_game.maze==null || _game.GameOver)
				return;

			if (MovePerson(_game.player, d))
			{
				_game.MoveCount++;
				if (!_monsterTimer.Enabled)
					_monsterTimer.Start();
			}
		}
示例#6
0
		private bool MovePerson (IPerson person, Direction d)
		{
			if (d == -1)
				return false;

			Room OldLocation = person.Location as Room;
			if (person.Move(d))
			{
				_view.Refresh(OldLocation);
				_view.Refresh(person.Location as Room);
				CheckEndGame();
				return true;
			}
			return false;
		}
示例#7
0
		//default implementation does nothing
		public virtual bool Leave(IPerson p, Direction d) {return false;}
示例#8
0
		/// <summary>
		/// attempts to leave the current location by moving the
		/// person in the specified direction
		/// </summary>
		/// <param name="d">direction the player wants to move</param>
		/// <returns>true if the Move operation succeeds</returns>
		public bool Move (Direction d)
		{
			return _location.Leave(this,d);
		}
示例#9
0
文件: Wall.cs 项目: gbahns/MazeGame
		public Wall (Room r1, Direction d) : base(r1,d) {}
示例#10
0
 public MapSite GetSide(Direction direction)
 {
     return sides[(int)direction];
 }
示例#11
0
文件: Room.cs 项目: gbahns/MazeGame
		public override PointF GetAdjacentCoords (Direction d)
		{
			switch (d.direction)
			{
				case Compass.North: return _coords + new Size(0,-1);
				case Compass.South: return _coords + new Size(0,+1);
				case Compass.West: return _coords + new Size(-1,0);
				case Compass.East: return _coords + new Size(+1,0);
				default: return new PointF(0,0);
			}
		}
示例#12
0
文件: Room.cs 项目: gbahns/MazeGame
		public override bool Leave (IPerson p, Direction d)
		{
			//ask the TargetSite for entry
			return (Neighbors[d] == null) ? false : Neighbors[d].Enter(p);
		}
示例#13
0
文件: Room.cs 项目: gbahns/MazeGame
		//connect this site to the specified site
		//assume that the specified site is already connected and has valid 
		//coordinates within the map
		//direction d specifes the direction from "site" to "this"
		public virtual void Join (IMapSite site, Direction d)
		{
			Neighbors[d] = site;
			site.Neighbors[d.opposite] = this;
			_coords = site.GetAdjacentCoords(d.opposite);
		}
示例#14
0
		//default implementation returns (0,0)
		public virtual PointF GetAdjacentCoords(Direction d)
		{
			return new PointF ();
		}
示例#15
0
文件: Door.cs 项目: gbahns/MazeGame
		public Door (Room r1, Direction d) : base(r1,d) {}
示例#16
0
 public void SetSide(Direction direction, MapSite newSide)
 {
     sides[(int)direction] = newSide;
 }
示例#17
0
 public void moveObject(GameObject obj, Direction dir, int speed)
 {
     switch (dir)
     {
         case Direction.UP:
             obj._y -= speed;
             break;
         case Direction.DOWN:
             obj._y += speed;
             break;
         case Direction.LEFT:
             obj._x -= speed;
             break;
         case Direction.RIGHT:
             obj._x += speed;
             break;
     }
 }
示例#18
0
        public void checkIfCollision(GameObject obj, Direction dir, int speed)
        {
            int xmin = obj._x;
            int xmax = obj._x + obj._width;
            int ymin = obj._y;
            int ymax = obj._y + obj._height;

            //check if hitting border
            switch (dir)
            {
                case Direction.UP:
                    if (ymin - speed < 0)
                    {
                        moveObject(obj, dir, 0 + ymin - speed);
                        obj._isColliding = true;
                    }
                    break;
                case Direction.DOWN:
                    if (ymax + speed > Engine.TILE_HEIGHT * Engine.MAP_HEIGHT)
                    {
                        moveObject(obj, dir, (Engine.TILE_HEIGHT * Engine.MAP_HEIGHT) - ymax - speed);
                        obj._isColliding = true;
                    }
                    break;
                case Direction.LEFT:
                    if (xmin - speed < 0)
                    {
                        moveObject(obj, dir, 0 + xmin - speed);
                        obj._isColliding = true;
                    }
                    break;
                case Direction.RIGHT:
                    if (xmax + speed > Engine.TILE_WIDTH * Engine.MAP_LENGTH)
                    {
                        moveObject(obj, dir, (Engine.TILE_WIDTH * Engine.MAP_LENGTH) - xmax - speed);
                        obj._isColliding = true;
                    }
                    break;
            }

            //check if hitting collidable background
            for (int i = 0; i < map.GetLength(0); i++)
            {
                for (int j = 0; j < map.GetLength(1); j++)
                {
                    switch (dir)
                    {
                        case Direction.UP:
                            if (map[i, j]._collider)
                            {
                                if ((ymin - speed >= map[i, j]._y && ymin - speed <= map[i, j]._y + map[i, j]._height) &&
                                    ((xmin >= map[i, j]._x && xmin <= map[i, j]._x + map[i, j]._width) || 
                                    (xmax >= map[i, j]._x && xmax <= map[i, j]._x + map[i, j]._width)))
                                {
                                    moveObject(obj, dir, ymin - (map[i, j]._y + map[i, j]._height) - speed - 1);
                                    obj._isColliding = true;
                                }
                            }
                            break;
                        case Direction.DOWN:
                            if (map[i, j]._collider)
                            {
                                if ((ymax + speed >= map[i, j]._y && ymax + speed <= map[i, j]._y + map[i, j]._height) &&
                                    ((xmin >= map[i, j]._x && xmin <= map[i, j]._x + map[i, j]._width) || 
                                    (xmax >= map[i, j]._x && xmax <= map[i, j]._x + map[i, j]._width)))
                                {
                                    moveObject(obj, dir, (map[i, j]._y) - ymax - speed - 1);
                                    obj._isColliding = true;
                                }
                            }
                            break;
                        case Direction.LEFT:
                            if (map[i, j]._collider)
                            {
                                if ((xmin - speed >= map[i, j]._x && xmin - speed <= map[i, j]._x + map[i, j]._width) &&
                                    ((ymin >= map[i, j]._y && ymin <= map[i, j]._y + map[i, j]._height) || 
                                    (ymax >= map[i, j]._y && ymax <= map[i, j]._y + map[i, j]._height)))
                                {
                                    moveObject(obj, dir, xmin - (map[i, j]._x + map[i, j]._width) - speed - 1);
                                    obj._isColliding = true;
                                }
                            }
                            break;
                        case Direction.RIGHT:
                            if (map[i, j]._collider)
                            {
                                if ((xmax + speed >= map[i, j]._x && xmax + speed <= map[i, j]._x + map[i, j]._width) &&
                                    ((ymin >= map[i, j]._y && ymin <= map[i, j]._y + map[i, j]._height) || 
                                    (ymax >= map[i, j]._y && ymax <= map[i, j]._y + map[i, j]._height)))
                                {
                                    moveObject(obj, dir, (map[i, j]._x) - xmax - speed - 1);
                                    obj._isColliding = true;
                                }
                            }
                            break;
                    }
                }
            }

            //check if colliding with collidable gameobject
            for (int i = 0; i < gameObjects.Count; i++)
            {
                switch (dir)
                {
                    case Direction.UP:
                        if (gameObjects[i]._collider)
                        {
                            if ((ymin - speed >= gameObjects[i]._y && ymin - speed <= gameObjects[i]._y + gameObjects[i]._height) &&
                                ((xmin >= gameObjects[i]._x && xmin <= gameObjects[i]._x +gameObjects[i]._width) || 
                                (xmax >=gameObjects[i]._x && xmax <=gameObjects[i]._x +gameObjects[i]._width)))
                            {
                                moveObject(obj, dir, ymin - (gameObjects[i]._y +gameObjects[i]._height) - speed - 1);
                                obj._isColliding = true;
                            }
                        }
                        break;
                    case Direction.DOWN:
                        if (gameObjects[i]._collider)
                        {
                            if ((ymax + speed >=gameObjects[i]._y && ymax + speed <=gameObjects[i]._y +gameObjects[i]._height) &&
                                ((xmin >=gameObjects[i]._x && xmin <=gameObjects[i]._x +gameObjects[i]._width) || 
                                (xmax >=gameObjects[i]._x && xmax <=gameObjects[i]._x +gameObjects[i]._width)))
                            {
                                moveObject(obj, dir, (gameObjects[i]._y) - ymax - speed - 1);
                                obj._isColliding = true;
                            }
                        }
                        break;
                    case Direction.LEFT:
                        if (gameObjects[i]._collider)
                        {
                            if ((xmin - speed >=gameObjects[i]._x && xmin - speed <=gameObjects[i]._x +gameObjects[i]._width) &&
                                ((ymin >=gameObjects[i]._y && ymin <=gameObjects[i]._y +gameObjects[i]._height) || 
                                (ymax >=gameObjects[i]._y && ymax <=gameObjects[i]._y +gameObjects[i]._height)))
                            {
                                moveObject(obj, dir, xmin - (gameObjects[i]._x +gameObjects[i]._width) - speed - 1);
                                obj._isColliding = true;
                            }
                        }
                        break;
                    case Direction.RIGHT:
                        if (gameObjects[i]._collider)
                        {
                            if ((xmax + speed >=gameObjects[i]._x && xmax + speed <=gameObjects[i]._x +gameObjects[i]._width) &&
                                ((ymin >=gameObjects[i]._y && ymin <=gameObjects[i]._y +gameObjects[i]._height) || 
                                (ymax >=gameObjects[i]._y && ymax <=gameObjects[i]._y +gameObjects[i]._height)))
                            {
                                moveObject(obj, dir, (gameObjects[i]._x) - xmax - speed - 1);
                                obj._isColliding = true;
                            }
                        }
                        break;
                }
            }

            moveObject(obj, dir, speed);

        }