Example #1
0
        public override void Update(GameTime gametime)
        {
            switch (rocketState)
                {
                    case ROCKETSTATE.STILL:
                        this.Visible = false;
                        explosion.Visible = false;
                        break;
                    // Using Lerp here could use target - pos and normalise for direction and then apply
                    // Velocity
                    case ROCKETSTATE.FIRING:
                        this.Visible = true;
                        position = Vector2.SmoothStep(position, Target, 0.02f * RocketVelocity);
                        if (Vector2.Distance(position, Target) < 20)
                            rocketState = ROCKETSTATE.EXPOLODING;
                        break;
                    case ROCKETSTATE.EXPOLODING:
                        Visible = false;
                        explosion.position = Target;
                        explosion.Visible = true;
                        break;
                }
                // if the explosion is visible then just play the animation and count the timer
                if (explosion.Visible)
                {
                    explosion.Update(gametime);
                    ExplosionTimer += gametime.ElapsedGameTime.Milliseconds;
                }
                // if the timer goes off the explosion is finished
                if (ExplosionTimer > ExplosionVisibleLimit)
                {
                    explosion.Visible = false;
                    ExplosionTimer = 0;
                    rocketState = ROCKETSTATE.STILL;
                }

                base.Update(gametime);
        }
Example #2
0
 public void fire(Vector2 SiteTarget)
 {
     if (rocketState == ROCKETSTATE.STILL)
         {
             rocketState = ROCKETSTATE.FIRING;
             Target = SiteTarget;
             Vector2 direction = position - Target;
             //direction.Normalize(); // Magnitude does not matter for angle calculation
             angleOfRotation = (float)Math.Atan2(direction.Y, direction.X);
         }
 }