예제 #1
0
        private void Gravity()
        {
            //player gravity
            //toggle for jetpack effect
            if (!_jump)
            {
                // get the current position in canvas
                Point currentPosition = _player.GetPositionInCanvas();

                //make a new position to move to.
                _newPosition = new Point(currentPosition.Top + _forceOnPlayer, currentPosition.Left);

                //checks to see that the player is not standing on a block
                if (!_player.IsCollidingWithMap(_map.GetBlocks(), _newPosition))
                {
                    //move the player down by the amount of force acting on him
                    _player.MoveDown(_forceOnPlayer);

                    //increase the force for next time
                    _forceOnPlayer++;
                }

                //player has hit the map so reset the force
                else
                {
                    _forceOnPlayer = 1;
                }
            }

            //enemies gravity
            //do for each enemy not going to be very visible to the player, mostly there to allow a more dynamic enemy positionining
            foreach (Enemy enemy in _map.GetEnemies())
            {
                //get the current position in canvas
                Point currentPostion = enemy.GetPositionInCanvas();

                //make a new position to move to.
                _newPosition = new Point(currentPostion.Top + _forceOnEnemies, currentPostion.Left);

                //checks to see that the enemy is not standing on a block
                if (!enemy.IsCollidingWithMap(_map.GetBlocks(), _newPosition))
                {
                    //move the enemy down by the amount of force acting on him
                    enemy.MoveDown(_forceOnEnemies);

                    //increase the force for next time
                    _forceOnEnemies++;
                }

                //enemy has hit the map so reset the force
                else
                {
                    _forceOnEnemies = 1;
                }
            }

            //boss
            if (_map.GetBoss() != null)
            {
                //get the current position in canvas
                Point currentPostion = _map.GetBoss().GetPositionInCanvas();

                //make a new position to move to.
                _newPosition = new Point(currentPostion.Top + _forceOnBoss, currentPostion.Left);

                //checks to see that the enemy is not standing on a block
                if (!_map.GetBoss().IsCollidingWithMap(_map.GetBlocks(), _newPosition))
                {
                    //move the enemy down by the amount of force acting on him
                    _map.GetBoss().MoveDown(_forceOnBoss);

                    //increase the force for next time
                    _forceOnBoss++;
                }
                else
                {
                    _forceOnBoss = 1;
                }
            }
        }