Beispiel #1
0
        /// <summary>
        /// Render unit, returns false if we are done with it.
        /// Has to be removed then. Else it updates just position and AI.
        /// </summary>
        /// <returns>True if done, false otherwise</returns>
        public bool Render(Mission mission)
        {
            #region Update movement with AI
            lifeTimeMs += BaseGame.ElapsedTimeThisFrameInMs;
            float moveSpeed = BaseGame.MoveFactorPerSecond;
            if (Player.GameOver)
                moveSpeed = 0;
            switch (movementPattern)
            {
                case MovementPattern.StraightDown:
                    position += new Vector2(0, -1) * maxSpeed * moveSpeed;
                    break;
                case MovementPattern.GetFasterAndMoveDown:
                    // Out of visible area? Then keep speed slow and wait.
                    if (position.Y - Mission.LookAtPosition.Y > 30)
                        lifeTimeMs = 300;
                    if (lifeTimeMs < 3000)
                        speed = lifeTimeMs / 3000;
                    position += new Vector2(0, -1) * speed * 1.5f * maxSpeed * moveSpeed;
                    break;
                case MovementPattern.SinWave1:
                    position += new Vector2(
                        (float)Math.Sin(lifeTimeMs / 759.0f),
                        -1) * maxSpeed * moveSpeed;
                    break;
                case MovementPattern.SinWave2:
                    position += new Vector2(
                        -(float)Math.Sin(lifeTimeMs / 759.0f),
                        -1) * maxSpeed * moveSpeed;
                    break;
                case MovementPattern.SinWave3:
                    position += new Vector2(
                        (float)Math.Sin(lifeTimeMs / 359.0f),
                        -1) * maxSpeed * moveSpeed;
                    break;
                case MovementPattern.CosWave1:
                    position += new Vector2(
                        (float)Math.Cos(lifeTimeMs / 759.0f),
                        -1) * maxSpeed * moveSpeed;
                    break;
                case MovementPattern.CosWave2:
                    position += new Vector2(
                        -(float)Math.Cos(lifeTimeMs / 759.0f),
                        -1) * maxSpeed * moveSpeed;
                    break;
                case MovementPattern.CosWave3:
                    position += new Vector2(
                        (float)Math.Cos(lifeTimeMs / 1759.0f),
                        -1) * maxSpeed * moveSpeed;
                    break;
                case MovementPattern.SweepLeft:
                    position += new Vector2(0, -1) * maxSpeed * moveSpeed;
                    if (lifeTimeMs > 1750)
                        position += new Vector2(-0.7f, 0) * maxSpeed * moveSpeed;
                    break;
                case MovementPattern.SweepRight:
                    position += new Vector2(0, -1) * maxSpeed * moveSpeed;
                    if (lifeTimeMs > 1750)
                        position += new Vector2(+0.7f, 0) * maxSpeed * moveSpeed;
                    break;
            } // switch(movementPattern)

            // Keep in bounds
            if (position.X < -Player.MaxXPosition)
                position.X = -Player.MaxXPosition;
            if (position.X > Player.MaxXPosition)
                position.X = Player.MaxXPosition;
            #endregion

            #region Skip if out of visible range
            float distance = Mission.LookAtPosition.Y - position.Y;
            const float MaxUnitDistance = 60;

            // Remove unit if it is out of visible range!
            if (distance > MaxUnitDistance)
                return true;
            bool visible = distance > -35;
            #endregion

            #region Render
            Vector3 shipPos = new Vector3(position, Mission.AllShipsZHeight);
            Mission.ShipModelTypes shipModelType =
                unitType == UnitTypes.Corvette ? Mission.ShipModelTypes.Corvette :
                unitType == UnitTypes.SmallTransporter ? Mission.ShipModelTypes.SmallTransporter :
                unitType == UnitTypes.Firebird ? Mission.ShipModelTypes.Firebird :
                unitType == UnitTypes.RocketFrigate ? Mission.ShipModelTypes.RocketFrigate :
                Mission.ShipModelTypes.Asteroid;
            float shipSize = Mission.ShipModelSize[(int)shipModelType];
            //Note: rotation could be implemented here, but game is fine without
            float shipRotation = 0;
            Matrix rotationMatrix = Matrix.CreateRotationZ(shipRotation);
            if (unitType == UnitTypes.Asteroid)
                rotationMatrix *=
                    Matrix.CreateRotationX(position.X / 10 + Player.gameTimeMs / 1539.0f) *
                    Matrix.CreateRotationY(position.Y / 20 + Player.gameTimeMs / 1839.0f);
            mission.AddModelToRender(
                mission.shipModels[(int)shipModelType],
                Matrix.CreateScale(shipSize) *
                rotationMatrix *
                Matrix.CreateTranslation(shipPos));
            // Add rocket smoke
            if (unitType != UnitTypes.Asteroid)
                EffectManager.AddRocketOrShipFlareAndSmoke(
                    shipPos + shipSize *
                    new Vector3(0, 0.6789f + ((int)unitType > 3 ? 0.25f : 0.0f), 0),
                    shipSize / 4.0f, 12 * maxSpeed);
            #endregion

            #region Shooting?
            if (Player.GameOver)
                return false;

            // Peng peng?
            bool fireProjectile = false;
            if (cooldownTime > 0 &&
                visible)
            {
                // Ready to shoot again?
                if (shootTime <= 0)
                {
                    fireProjectile = true;
                    shootTime += cooldownTime;
                } // if (shootTime)
            } // if (GameForm.Mouse.LeftButtonPressed)

            // Weapon needs cooldown time?
            if (shootTime > 0)
                shootTime -= BaseGame.ElapsedTimeThisFrameInMs;

            if (fireProjectile)
            {
                Vector3 shootPos = Vector3.Zero;
                Vector3 enemyUnitPos = Player.shipPos;
                switch (unitType)
                {
                    case UnitTypes.Corvette:
                        if ((int)(lifeTimeMs / 700) % 3 == 0)
                        {
                            // Just shoot straight ahead.
                            bool hitUnit = Math.Abs(Player.position.X - shipPos.X) < 4.5f &&
                                Player.shipPos.Y < shipPos.Y;
                            shootPos = shipPos +
                            new Vector3(-2.35f, -3.5f, +0.2f);
                            EffectManager.AddMgEffect(shootPos,
                                hitUnit ? enemyUnitPos : shootPos + new Vector3(0, -40, 0),
                                10, 12, hitUnit, false);//shootNum % 2 == 0);
                            shootPos = shipPos +
                            new Vector3(+2.35f, -3.5f, +0.2f);
                            EffectManager.AddMgEffect(shootPos,
                                hitUnit ? enemyUnitPos : shootPos + new Vector3(0, -40, 0),
                                10, 13, hitUnit, false);
                            EffectManager.PlaySoundEffect(
                                EffectManager.EffectSoundType.MgShootEnemy);
                            if (hitUnit)
                            {
                                Player.health -= damage / 1000.0f;
                            } // if
                        } // if
                        break;

                    case UnitTypes.Firebird:
                        shootPos = shipPos + new Vector3(0, -1.5f, 3);
                        Mission.AddWeaponProjectile(
                            Projectile.WeaponTypes.Fireball, shootPos, false);
                        EffectManager.AddFireFlash(shootPos);
                        EffectManager.PlaySoundEffect(
                            EffectManager.EffectSoundType.EnemyShoot);
                        break;

                    case UnitTypes.RocketFrigate:
                        shootPos = shipPos + new Vector3(
                            RandomHelper.GetRandomInt(2) == 0 ? -2.64f : +2.64f, 0, 0);
                        Mission.AddWeaponProjectile(
                            Projectile.WeaponTypes.Rocket, shootPos, false);
                        EffectManager.AddFireFlash(shootPos);
                        EffectManager.PlaySoundEffect(
                            EffectManager.EffectSoundType.RocketShoot);
                        break;
                } // switch
            } // if
            #endregion

            #region Explode if out of hitpoints
            // Destroy ship and damage player if colliding!
            // Near enough to our ship?
            Vector2 distVec =
                new Vector2(Player.shipPos.X, Player.shipPos.Y) -
                new Vector2(position.X, position.Y);
            if (distVec.Length() < 4.75f)//5.5f)
            {
                // Explode and do damage!
                EffectManager.AddFlameExplosion(Player.shipPos);
                Player.health -= explosionDamage / 1000.0f;
                hitpoints = 0;
            } // else

            if (maxHitpoints > 0 &&
                hitpoints <= 0)
            {
                // Explode and kill unit!
                float size = 10 + (int)unitType * 3;
                if (unitType == UnitTypes.Asteroid)
                    size = 12;
                EffectManager.AddExplosion(
                    new Vector3(position, Mission.AllShipsZHeight),
                    size * 0.425f);
                    //size * 0.55f);
                return true;
            } // if (hitpoints.X)
            #endregion

            // Don't remove unit from units list
            return false;
        }
Beispiel #2
0
        /// <summary>
        /// Render unit, returns false if we are done with it.
        /// Has to be removed then. Else it updates just position and AI.
        /// </summary>
        /// <returns>True if done, false otherwise</returns>
        public bool Render(Mission mission)
        {
            #region Skip if out of visible range
            float distance = Mission.LookAtPosition.Y - position.Y;
            const float MaxUnitDistance = 60;

            // Remove unit if it is out of visible range!
            if (distance > MaxUnitDistance)
                return true;
            #endregion

            #region Render
            float itemSize = Mission.ItemModelSize;
            float itemRotation = 0;
            Vector3 itemPos = new Vector3(position, Mission.AllShipsZHeight);
            mission.AddModelToRender(
                mission.itemModels[(int)itemType],
                Matrix.CreateScale(itemSize) *
                Matrix.CreateRotationZ(itemRotation) *
                Matrix.CreateTranslation(itemPos));
            // Add glow effect
            EffectManager.AddEffect(itemPos + new Vector3(0, 0, 1.01f),
                EffectManager.EffectType.LightInstant,
                7.5f, 0, 0);
            EffectManager.AddEffect(itemPos + new Vector3(0, 0, 1.02f),
                EffectManager.EffectType.LightInstant,
                5.0f, 0, 0);
            #endregion

            #region Collect
            // Collect item and give to player if colliding!
            Vector2 distVec =
                new Vector2(Player.shipPos.X, Player.shipPos.Y) -
                new Vector2(position.X, position.Y);
            if (distVec.Length() < 5.0f)
            {
                if (itemType == ItemTypes.Health)
                {
                    // Refresh health
                    Sound.Play(Sound.Sounds.Health);
                    Player.health = 1.0f;
                } // if
                else
                {
                    Sound.Play(Sound.Sounds.NewWeapon);
                    if (itemType == ItemTypes.Mg)
                        Player.currentWeapon = Player.WeaponTypes.MG;
                    else if (itemType == ItemTypes.Plasma)
                        Player.currentWeapon = Player.WeaponTypes.Plasma;
                    else if (itemType == ItemTypes.Gattling)
                        Player.currentWeapon = Player.WeaponTypes.Gattling;
                    else if (itemType == ItemTypes.Rockets)
                        Player.currentWeapon = Player.WeaponTypes.Rockets;
                    else if (itemType == ItemTypes.Emp &&
                        Player.empBombs < 5)
                        Player.empBombs++;
                } // else
                Player.score += 500;

                return true;
            } // else
            #endregion

            // Don't remove unit from items list
            return false;
        }
Beispiel #3
0
        /// <summary>
        /// Render projectile, returns false if we are done with it.
        /// Has to be removed then. Else it updates just position.
        /// </summary>
        /// <returns>True if done, false otherwise</returns>
        public bool Render(Mission mission)
        {
            #region Update movement
            lifeTimeMs += BaseGame.ElapsedTimeThisFrameInMs;
            float moveSpeed = BaseGame.MoveFactorPerSecond;
            if (Player.GameOver)
                moveSpeed = 0;
            switch (weaponType)
            {
                case WeaponTypes.Fireball:
                    position += moveDirection * maxSpeed * moveSpeed;
                    break;
                case WeaponTypes.Rocket:
                    if (ownProjectile)
                        position += new Vector3(0, +1, 0) * maxSpeed * moveSpeed * 1.1f;
                    else
                    {
                        // Fly to player
                        Vector3 targetMovement = Player.shipPos - position;
                        targetMovement.Normalize();
                        moveDirection = moveDirection * 0.95f + targetMovement * 0.05f;
                        moveDirection.Normalize();
                        position += moveDirection * maxSpeed * moveSpeed;
                    } // else
                    break;
                case WeaponTypes.Plasma:
                    if (ownProjectile)
                        position += new Vector3(0, +1, 0) * maxSpeed * moveSpeed * 1.25f;
                    else
                        position += new Vector3(0, -1, 0) * maxSpeed * moveSpeed;
                    break;
                // Rest are items, they just stay around
            } // switch(movementPattern)
            #endregion

            #region Skip if out of visible range
            float distance = Mission.LookAtPosition.Y - position.Y;
            const float MaxUnitDistance = 35;

            // Remove unit if it is out of visible range!
            if (distance > MaxUnitDistance ||
                distance < -MaxUnitDistance * 2 ||
                position.Z < 0 ||
                lifeTimeMs > 6000)
                return true;
            #endregion

            #region Render
            switch (weaponType)
            {
                case WeaponTypes.Rocket:
                    float rocketRotation = MathHelper.Pi;
                    if (ownProjectile == false)
                        rocketRotation = MathHelper.PiOver2 + GetRotationAngle(moveDirection);
                    mission.AddModelToRender(
                        mission.shipModels[(int)Mission.ShipModelTypes.Rocket],
                        Matrix.CreateScale(
                        (ownProjectile ? 1.25f : 0.75f) *
                        Mission.ShipModelSize[(int)Mission.ShipModelTypes.Rocket]) *
                        Matrix.CreateRotationZ(rocketRotation) *
                        Matrix.CreateTranslation(position));
                    // Add rocket smoke
                    EffectManager.AddRocketOrShipFlareAndSmoke(position, 1.5f, 6 * maxSpeed);
                    break;
                case WeaponTypes.Plasma:
                    EffectManager.AddPlasmaEffect(position, effectRotation, 1.25f);
                    break;
                case WeaponTypes.Fireball:
                    EffectManager.AddFireBallEffect(position, effectRotation, 1.25f);
                    break;
            } // switch
            #endregion

            #region Explode if hitting unit
            // Own projectile?
            if (ownProjectile)
            {
                // Hit enemy units, check all of them
                for (int num = 0; num < Mission.units.Count; num++)
                {
                    Unit enemyUnit = Mission.units[num];
                    // Near enough to enemy ship?
                    Vector2 distVec =
                        new Vector2(enemyUnit.position.X, enemyUnit.position.Y) -
                        new Vector2(position.X, position.Y);
                    if (distVec.Length() < 7 &&
                        (enemyUnit.position.Y - Player.shipPos.Y) < 60)
                    {
                        // Explode and do damage!
                        EffectManager.AddFlameExplosion(position);
                        Player.score += (int)enemyUnit.hitpoints / 10;
                        enemyUnit.hitpoints -= damage;
                        return true;
                    } // if
                } // for
            } // if
            // Else this is an enemy projectile?
            else
            {
                // Near enough to our ship?
                Vector2 distVec =
                    new Vector2(Player.shipPos.X, Player.shipPos.Y) -
                    new Vector2(position.X, position.Y);
                if (distVec.Length() < 2.75f)//3)
                {
                    // Explode and do damage!
                    EffectManager.AddFlameExplosion(position);
                    Player.health -= damage / 1000.0f;
                    return true;
                } // if
            } // else
            #endregion

            // Don't remove unit from units list
            return false;
        }