Пример #1
0
 public void PlayExplosion(Player p, Rocket r)
 {
     float volume = (-(FAbs(r.X - p.X) / 400f) + 1) / 5;
     explosion.Play(volume > 0.0f ? volume : 0.0f, 0.0f, r.X - p.X > 0 ? 0.25f : -0.25f);
 }
Пример #2
0
        public void Update(Player p, GameTime theGameTime, ExplosionHandler explosions, SoundHandler sounds, Camera c)
        {
            foreach (Rocket r in rockets)
                if (r.Visible)
                    r.Update(theGameTime, new Vector2((p.X + 21 * p.Scale) - r.X, (p.Y + 3 * p.Scale) - r.Y)); //(p.x+21); (p.y+3) so it doesn't aim at player.origin

            if (reloadTime < initRealoadTime)
                reloadTime += (float)theGameTime.ElapsedGameTime.TotalSeconds;

            //this.Animate();
            this.RemoveRocket(explosions, sounds, p);

            this.OnScreen = this.X - c.origin.X < 800 ? true : false;

            if (!OnScreen)
                return;

            float dx = this.Position.X - p.X;
            float dy = this.Position.Y - p.Y;
            float dist = dx * dx + dy * dy;     //distance from player to tower

            if (dx > 64 && dist < vision * vision && (dy < 100 && dy > -30)) //if distance.X < 64 and distance y < 100 && > 30 then Rotate - facing player
            {
                this.Rotation = FAtan((dy + 2) / dx); //(y+2) so it doesn't aim at very top of head
                lightColor = 2;
                this.SeePlayer = true;
            }
            else
            {
                lightColor = 0;
                this.SeePlayer = false;
            }

            if (reloadTime > initRealoadTime && SeePlayer)
            {
                rocketDirection = new Vector2((p.X + 21 * p.Scale) - this.X, (p.Y + 3 * p.Scale) - this.Y); //(p.Y + 3) so it doesn't shoot on top of head
                rocketDirection.Normalize();

                float xx = this.X + FCos(Rotation) * Fsqrt((32 * 32 * Scale * Scale) + (9 * 9 * Scale * Scale)); //x coordinate of new rocket

                newRocket = new Rocket(new Vector2(xx, Y + 5 * Scale), rocketDirection, this.Rotation);
                newRocket.LoadContent(contentManager);
                rockets.Add(newRocket);
                newRocket = null;
                reloadTime = 0f;
            }
        }