Example #1
0
        /// <summary>
        /// Actor class constructor.
        /// </summary>
        /// <param name="layer">Actor's layer</param>
        public Actor(Layer layer)
            : base(layer)
        {
            //Empties variables
            m_LastShip          = null;
            m_RotationX         = 0.0f;
            m_RotationY         = 0.0f;
            m_Movement	        = Vector3.Zero;
            m_SavedVelocity     = Vector3.Zero;
            m_SavedAcceleration = Vector3.Zero;

            //Initialize values
            m_Life      = 0;
            m_Jumping	= false;
            m_Forward	= new Vector3(0.0f, 0.0f, 1.0f);
            m_Sideway	= new Vector3(-1.0f, 0.0f, 0.0f);

            //Create light
            m_Light					= new PointLight();
            m_Light.Range			= 40.0f;
            m_Light.DiffuseColor	= new Vector3(1.0f, 1.0f, 1.0f);
            m_Light.SpecularColor	= new Vector3(0.3f, 0.3f, 0.3f);
        }
Example #2
0
        /// <summary>
        /// Updates the board and check next movement.
        /// </summary>
        private void UpdateBoard()
        {
            //Skip if board doesn't exist
            if (m_Board == null) return;

            //Checks winning condition if not editor
            if (m_Player != Player.Storm && m_Board[m_Data.Goal, 0] != null && m_Board[m_Data.Goal + 1, 0] != null)
                if (m_Board[m_Data.Goal, 0].IsKing() && m_Board[m_Data.Goal + 1, 0].IsKing()) {
                    //Wins
                    m_Victory	= true;
                    m_King		= m_Board[m_Data.Goal, 0];
                    m_King.Wins();

                    //Set camera as birdview
                    m_ActiveCamera = m_BirdsView;
                    UpdateCamera();

                    //No need to check the rest
                    return;
                }

            //For each ship
            foreach (Ship ship in m_Ships) {
                //Reset movement
                ship.ResetMovement();

                //Check each direction
                #region Movement availability checking
                //Is ship on top row?
                bool Available = (ship.GetRow() + ship.GetHeight()) < m_Board.GetLength(1);

                //Check against other ship if not on top row
                if (Available) {
                    for (int x = ship.GetColumn(); x < ship.GetColumn() + ship.GetWidth(); x++)
                        if (m_Board[x, ship.GetRow() + ship.GetHeight()] != null) Available = false;
                    if (Available) { ship.AddMovement(Direction.PositiveY); }
                }

                //Is ship on bottom row?
                Available = ship.GetRow() > 0;

                //Check against other ship if not on bottom row
                if (Available) {
                    for (int x = ship.GetColumn(); x < ship.GetColumn() + ship.GetWidth(); x++)
                        if (m_Board[x, ship.GetRow() - 1] != null) Available = false;
                    if (Available) { ship.AddMovement(Direction.NegativeY); }
                }

                //Is ship on left most row?
                Available = (ship.GetColumn() + ship.GetWidth()) < m_Board.GetLength(0);

                //Check against other ship if not on bottom row
                if (Available) {
                    for (int y = ship.GetRow(); y < ship.GetRow() + ship.GetHeight(); y++)
                        if (m_Board[ship.GetColumn() + ship.GetWidth(), y] != null) Available = false;
                    if (Available) { ship.AddMovement(Direction.PositiveX); }
                }

                //Is ship on right most row?
                Available = ship.GetColumn() > 0;

                //Check against other ship if not on bottom row
                if (Available) {
                    for (int y = ship.GetRow(); y < ship.GetRow() + ship.GetHeight(); y++)
                        if (m_Board[ship.GetColumn() - 1, y] != null) Available = false;
                    if (Available) { ship.AddMovement(Direction.NegativeX); }
                }
                #endregion
            }
        }
Example #3
0
        /// <summary>
        /// State Game class constructor.
        /// </summary>
        public StateGame(Player player, GameData data)
            : base(StateID.Game)
        {
            //Initialize variable
            m_Data			= data;
            m_Player		= player;
            m_Victory		= false;
            m_Initialized	= false;
            m_ReadyToUpdate	= false;
            m_BoardWidth    = 0;
            m_BoardHeight   = 0;
            m_IteratorStack	= new Stack<int>();
            m_ShipStack		= new Stack<Ship>();
            m_VisitedList	= new List<GameData>();

            //Empties variables
            m_Depth			= 0;
            m_MaxDepth		= 0;
            m_Sky			= null;
            m_Actor			= null;
            m_King			= null;
            m_Ships			= null;
            m_Board			= null;
            m_SkyLayer		= null;
            m_BirdsView		= null;
            m_ActiveCamera	= null;
            m_Controlled	= null;
            m_LifeBar		= null;
            m_Timer			= null;
        }
Example #4
0
        /// <summary>
        /// Initialize actor
        /// </summary>
        /// <param name="ship">The ship the character is on.</param>
        /// <param name="life"></param>
        public void Initialize(Ship ship, int life)
        {
            //Set character's life
            m_Life      = life;
            m_LastShip  = ship;

            //Get character's position
            Vector3 Position  = ship.GetCenterTop();
            Position.Y		 += 25.0f;

            //Calls parent initialization
            Initialize(Global.ACTOR_MODEL, true, Position.X, Position.Y, Position.Z);

            //Set model animation
            m_Model.CurrentAnimation = Global.ACTOR_ANIMATIONS[1];
            m_Camera.X = 0;
            m_Camera.Z = 0;

            //Set camera orientation
            m_Camera.RotationX = 0;
            m_Camera.RotationY = (float)Math.PI;
            m_Camera.RotationZ = 0;

            //Attach light
            m_Light.Position	= m_Model.Position;
            m_Light.Position.Y += 5.0f;
            m_Light.Position.Z += 5.0f;
            m_Light.AttachTo(m_Model, true);
        }
Example #5
0
        public void OnCollision(Ship ship)
        {
            //Determines should actor keep falling
            bool Falling = ship.GetBoundingBox().Max.Y > (GetBoundingBox().Min.Y + GetBoundingBox().Max.Y)/2;

            //If no longer falling
            if (!Falling) {
                //Stop jumping
                m_Jumping                   = false;
                m_Model.YVelocity           = 0.0f;
                m_Model.CurrentAnimation    = "Walking";

                //Set last ship visited
                m_LastShip = ship;

                //Place it on the ship
                m_Model.Y = ship.GetBoundingBox().Max.Y;
            }
        }
Example #6
0
        private void PutShipToBoard()
        {
            Vector2 BoardPosition = CalculatePositionFromRay();

            //Calculate Tile Position
            int TileColumn      = (int)BoardPosition.X / (int)(Global.GAMETILE_WIDTH + (Global.GAMEGAP_WIDTH * 2));
            int TileRow         = (int)BoardPosition.Y / (int)(Global.GAMETILE_HEIGHT + (Global.GAMEGAP_HEIGHT * 2));

            //Check if cursor position are on board
            if ((TileRow >= 0) && (TileRow < BoardRow)) {
                if ((TileColumn >= 0) && (TileColumn < BoardColumn)) {
                    //Get variable
                    bool Available = false;
                    bool Empty = true;

                    //Quick check board and size
                    if ((TileRow + SelectedHeight <= BoardRow) && (TileColumn + SelectedWidth <= BoardColumn)) Available = true;

                    //Ensure ship's space is empty
                    if (Available) {
                        for (int x = TileColumn; x < TileColumn + SelectedWidth; x++) for (int y = TileRow; y < TileRow + SelectedHeight; y++)
                                if (m_Board[x, y] != null) Empty = false;
                    }

                    //Place the ship if empty
                    if (Available && Empty){
                        Ship ship = new Ship(m_Layer, TileRow, TileColumn, SelectedWidth, SelectedHeight);
                        m_Ships.Add(ship);
                        ship.Initialize();

                        //Put into board
                        for (int x = TileColumn; x < TileColumn + ship.GetWidth(); x++) for (int y = TileRow; y < TileRow + ship.GetHeight(); y++)
                                m_Board[x, y] = ship;
                    }
                }
            }
        }
Example #7
0
        private void PutKingShip()
        {
            Ship ship = new Ship(m_Layer, 0, m_Data.Goal, 2, 2);
            ship.Initialize();
            m_Ships.Add(ship);

            //Put into board
            for (int x = m_Data.Goal; x < m_Data.Goal + ship.GetWidth(); x++) for (int y = 0; y < 0 + ship.GetHeight(); y++)
                    m_Board[x, y] = ship;
        }
Example #8
0
 /// <summary>
 /// Stores ship data.
 /// </summary>
 /// <param name="ship">The ship which data will be stored</param>
 public void AddShip(Ship ship)
 {
     //Add each data individually
     AddShip(ship.GetRow(), ship.GetColumn(), ship.GetWidth(), ship.GetHeight());
 }