示例#1
0
        public override bool OnAttack(Car target)
        {
            sprite.RotateTowards(target.sprite.position);

            float deltaT = currentT - lastFired;

            deltaT *= Game1.timeScale;
            if (deltaT < 1.0f / fireRate)
            {
                return(false);
            }

            float angle = MathHelper.ToRadians(sprite.rotation);

            lastFired = currentT;
            Projectile_Bullet bullet = new Projectile_Bullet(
                null, sprite.position, sprite.rotation,
                1000.0f * new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)),
                damage);

            bullet.sprite.position += 35.0f * new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle));
            bullet.isFriendly       = false;
            bullet.sprite.color     = Color.Red;
            bullet.range            = attackRange;
            Game1.projectiles.Add(bullet);

            Effect_MuzzleFlash flash = new Effect_MuzzleFlash(bullet.sprite.position);

            flash.sprite.rotation = bullet.sprite.rotation;
            Game1.effects.Add(flash);

            return(true);
        }
示例#2
0
        public override bool OnPrimaryFire(GameTime gameTime)
        {
            float deltaT = (float)gameTime.TotalGameTime.TotalSeconds - lastFired;

            deltaT *= Game1.timeScale;

            if (deltaT < 1.0f / fireRate)
            {
                return(false);
            }

            if (isReloading)
            {
                return(false);
            }

            if (currentAmmo == 0)
            {
                OnReload(gameTime);
                return(false);
            }

            currentAmmo--;

            lastFired = (float)gameTime.TotalGameTime.TotalSeconds;
            float   angle     = MathHelper.ToRadians(sprite.rotation);
            Vector2 direction = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle));
            Vector2 perpend   = new Vector2(-direction.Y, direction.X);

            if (barrel == 1)
            {
                perpend *= -1.0f;
            }
            barrel++;
            barrel %= 2;

            Projectile_Bullet bullet = new Projectile_Bullet(
                this,
                sprite.position, 0.0f,
                bulletSpeed * direction,
                damage);

            bullet.sprite.position += length * direction;
            bullet.sprite.position += (barrelSpacing / 2.0f) * perpend;
            bullet.sprite.rotation  = MathHelper.ToDegrees(angle);

            Game1.projectiles.Add(bullet);
            Effect_MuzzleFlash flash = new Effect_MuzzleFlash(bullet.sprite.position);

            flash.sprite.rotation = bullet.sprite.rotation;
            Game1.effects.Add(flash);

            return(true);
        }
示例#3
0
        public override bool OnPrimaryFire(GameTime gameTime)
        {
            float deltaT = (float)gameTime.TotalGameTime.TotalSeconds - lastFired;

            deltaT *= Game1.timeScale;

            if (deltaT < 1.0f / fireRate)
            {
                return(false);
            }

            if (isReloading)
            {
                return(false);
            }

            if (currentAmmo == 0)
            {
                OnReload(gameTime);
                return(false);
            }

            currentAmmo--;

            lastFired = (float)gameTime.TotalGameTime.TotalSeconds;
            float   angle     = MathHelper.ToRadians(sprite.rotation);
            Vector2 direction = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle));

            Projectile_ExplosiveRound bullet = new Projectile_ExplosiveRound(
                this,
                sprite.position, 0.0f,
                bulletSpeed * direction,
                damage);

            bullet.sprite.position += 45.0f * direction;
            bullet.sprite.rotation  = MathHelper.ToDegrees(angle);

            Game1.projectiles.Add(bullet);
            Effect_MuzzleFlash flash = new Effect_MuzzleFlash(bullet.sprite.position);

            flash.sprite.rotation = bullet.sprite.rotation;
            Game1.effects.Add(flash);

            return(true);
        }
示例#4
0
        public override bool OnPrimaryFire(GameTime gameTime)
        {
            float deltaT = (float)gameTime.TotalGameTime.TotalSeconds - lastFired;

            deltaT *= Game1.timeScale;

            if (deltaT < 1.0f / fireRate)
            {
                return(false);
            }

            if (isReloading)
            {
                return(false);
            }

            if (currentAmmo == 0)
            {
                OnReload(gameTime);
                return(false);
            }

            currentAmmo--;

            if (!isSpinning)
            {
                isSpinning = true;
                if (lastFrameTime < 0.0f)
                {
                    lastFrameTime = (float)gameTime.TotalGameTime.TotalSeconds;
                }
            }

            float frameDeltaT = (float)gameTime.TotalGameTime.TotalSeconds - lastFrameTime;

            frameDeltaT *= Game1.timeScale;
            if (frameDeltaT >= 1.0f / speed)
            {
                lastFrameTime = (float)gameTime.TotalGameTime.TotalSeconds;
                frame++;
                frame %= 4;
            }

            sprite.textureRect = new Rectangle(150 * frame, 0, 150, 75);

            lastFired = (float)gameTime.TotalGameTime.TotalSeconds;
            float             angle  = MathHelper.ToRadians(sprite.rotation);
            Projectile_Bullet bullet = new Projectile_Bullet(
                this,
                sprite.position, 0.0f,
                bulletSpeed * new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)),
                damage);

            bullet.sprite.position += 100.0f * new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle));
            bullet.sprite.rotation  = MathHelper.ToDegrees(angle);

            Game1.projectiles.Add(bullet);

            Effect_MuzzleFlash flash = new Effect_MuzzleFlash(bullet.sprite.position);

            flash.sprite.rotation = bullet.sprite.rotation;
            Game1.effects.Add(flash);

            return(true);
        }