コード例 #1
0
        public static void AddShot(
            EquipmentData shotData, //projectile data
            Vector2 initialLocation,
            float rotation,
            Vector2 inheritVelocity,
            FoF_Ident senderIdent)
        {
            bool everyOtherDummy = false;
            int dummyDivisor = 2;

            if (shotData.ShotsPerLaunch > 10 || shotData.RefireDelay < 5)
                everyOtherDummy = true;
            //if launching a lot of shots, cut back on collision detection
            //by making every other shot a dummy projectile, and also
            //double the damage to account for decreased DPS...

            int lastDummy = 0;

            for (int i = 0; i < shotData.ShotsPerLaunch; i++) //fire however many shots
            {
                Vector2 shotVel = Vector2.Multiply(rotation.RotationToVector(), shotData.Speed) + inheritVelocity;
                //get the scaled and inherited shot velocity

                if (shotData.Randomization != 0) //randomize the velocity by the provided factor
                {
                    float tempX = (float)Util.rnd.NextDouble(-shotData.Randomization, shotData.Randomization);
                    float tempY = (float)Util.rnd.NextDouble(-shotData.Randomization, shotData.Randomization);

                    shotVel.X += tempX;
                    shotVel.Y += tempY;
                }

                  Projectiles.Add(new Projectile( //and generate a new projectile according to shotData
                    shotData.Texture,
                    initialLocation,
                    shotVel,
                    rotation,
                    shotData.HitSoundIndex,
                    senderIdent,
                    shotData.MaxRange,
                    (everyOtherDummy ? shotData.Damage * dummyDivisor : shotData.Damage),
                    shotData.DetonateEffect,
                    shotData.TrackVelocity,
                    (everyOtherDummy ? (++lastDummy % dummyDivisor == 0) : false),
                    shotData.CollisionRadius));
                //EveryOtherDummy is incremented every generation,
                //and if it is enabled and not a clean divisor of two,
                //the projectile is a dummmy
            }

            if(shotData.LaunchSoundIndex != "" || shotData.LaunchSoundIndex != null)
                ContentHandler.PlaySFX(shotData.LaunchSoundIndex); //play the launch sound
        }
コード例 #2
0
ファイル: NPC.cs プロジェクト: JEJacobi/AsteroidsInc
        public NPC(
            string texturekey,
            string damagekey,
            string deathkey,
            AIState initialState,
            Vector2 initialPos,
            Vector2 initialVel,
            Vector2 initialTarget,
            Color tintColor,
            int startingHealth,
            EquipmentData equip,
            int colRadius,
            int activationRadius,
            float trailOffset,
            float weaponOffset,
            float maxSpeed,
            float trackSpeed,
            float maxAccelSpeed,
            float initialRot = 0f,
            float initialRotVel = 0f,
            int totalFrames = 0,
            int rows = 1,
            int columns = 1,
            int startingFrame = 0,
            float frameDelay = 0,
            FoF_Ident ident = FoF_Ident.Enemy,
            bool activated = false)
        {
            Ship = new GameObject(
                ContentHandler.Textures[texturekey],
                initialPos,
                initialVel,
                tintColor,
                false,
                initialRot,
                initialRotVel,
                1f,
                NPC_DEPTH,
                false,
                colRadius,
                0, 0,
                SpriteEffects.None,
                totalFrames,
                rows,
                columns,
                startingFrame,
                frameDelay);

            Shield = new GameObject(
                ContentHandler.Textures[texturekey + NPCManager.SHIELD_TEXTURE],
                Ship.WorldCenter,
                Ship.Velocity,
                Color.Transparent,
                false,
                Ship.Rotation,
                Ship.RotationalVelocity,
                Ship.Scale,
                Ship.Depth);

            CurrentState = initialState;
            LastState = initialState;
            DamageSoundKey = damagekey;
            DeathSoundKey = deathkey;
            Weapon = equip;
            if (equip != null) { firedelay = equip.RefireDelay; }
            ActivationRadius = activationRadius;
            Activated = activated;
            TrailOffset = trailOffset;
            WeaponOffset = weaponOffset;
            MaxSpeed = maxSpeed;
            TrackSpeed = trackSpeed;
            AccelerationSpeed = maxAccelSpeed;
            Target = Vector2.Normalize(initialTarget);

            Identification = ident;
            StartingHealth = startingHealth;
            Health = StartingHealth;

            trail = new ParticleEmitter( //initialize the engine trail particle emitter
                TRAIL_MAX_PARTICLES,
                GameObject.GetOffset(Ship, TrailOffset),
                ContentHandler.Textures[TRAIL_PARTICLE].ToTextureList(),
                TRAIL_COLORS.ToList<Color>(),
                TRAIL_FTL,
                false,
                true,
                -1,
                TRAIL_PPT,
                TRAIL_EJECTION_SPEED,
                TRAIL_RANDOM_MARGIN,
                Ship.RotationDegrees + 180,
                TRAIL_SPRAYWIDTH);

            //initialize the state logic
            switchState(initialState);

            //pick a slightly randomized evasion damage threshold
            dmgThreshold = Util.rnd.Next(
                EVADE_DMG_THRESHOLD_MIN,
                EVADE_DMG_THRESHOLD_MAX);

            reattackTime = Util.rnd.Next(
                REATTACK_TIME_MIN,
                REATTACK_TIME_MAX);

            evadeTime = Util.rnd.Next(
                EVADE_TIME_MIN,
                EVADE_TIME_MAX);

            shotsBeforeCooldown = Util.rnd.Next(
                COOLDOWN_MIN,
                COOLDOWN_MAX);
            shotsCounter = 0;
        }