Exemplo n.º 1
0
        public Projectile(
            Texture2D texture,
            Vector2 initialLocation,
            Vector2 velocity,
            float rotation,
            string hitSound,
            FoF_Ident ident,
            int range,
            int dmg,
            bool detEffect,
            bool trackVelocity,
            bool isDummy,
            int collisionRadius = 1)
            : base(texture, initialLocation, velocity, Color.White, false, rotation, 0f, 1f, PROJECTILE_DEPTH, false, collisionRadius)
        {
            Identification = ident;
            Damage = dmg;
            MaxRange = range;
            HitSound = hitSound;
            DetonateEffect = detEffect;
            TrackVelocity = trackVelocity;
            IsDummyProjectile = isDummy;

            DistanceTravelled = 0f;
            lastLoc = initialLocation;
        }
Exemplo n.º 2
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
        }
Exemplo n.º 3
0
        public static bool IsHit(GameObject obj, out Projectile shotHit, FoF_Ident alignment = FoF_Ident.Neutral)
        {
            foreach (Projectile shot in Projectiles) //loop through each shot to check if hit
            {
                if (shot.Identification != alignment && shot.IsDummyProjectile == false) //check if friendly & not a dummy
                {
                    if (obj.IsCircleColliding(shot)) //check if colliding
                    {
                        HitEffects.Add(new ParticleEmitter( //add a hit effect
                            EFFECT_MAX_PARTICLES,
                            obj.WorldCenter.Center(shot.WorldCenter),
                            ContentHandler.Textures["particle"].ToTextureList(),
                            EFFECT_COLORS.ToList<Color>(),
                            EFFECT_FRAMES_TO_LIVE,
                            true,
                            true,
                            EFFECT_TIME_TO_EMIT,
                            EFFECT_MAX_PARTICLES / DETONATE_TIME_TO_EMIT,
                            EFFECT_EJECTION_SPEED,
                            EFFECT_RANDOMIZATION,
                            shot.RotationDegrees + 180,
                            EFFECT_SPRAY_WIDTH));

                        shotHit = shot; //set the out param
                        shot.Active = false;

                        if (shot.DetonateEffect)
                            addDetonateEffect(shot.WorldCenter);

                        return true; //return true
                    }
                }
            }
            shotHit = null; //set the shot to null
            return false; //and return false
        }
Exemplo n.º 4
0
        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;
        }