public Projectile(Game game, Vector2 userPosition, List <TileRef> projectiletRefs, List <TileRef> explosionRef, int frameWidth, int frameHeight, float layerDepth) : base(game, userPosition, projectiletRefs, frameWidth, frameHeight, layerDepth) { Target = Vector2.Zero; StartPosition = userPosition; ProjectileState = PROJECTILE_STATE.STILL; explosion = new AnimateSheetSprite(game, userPosition, explosionRef, frameWidth, FrameHeight, layerDepth); }
public void Fire(Vector2 directionIn) { Target = directionIn * new Vector2(1, 1) * RocketVelocity; projectileState = PROJECTILE_STATE.FIRING; //this.PixelPosition += direction * new Vector2(1, 1) * speed; }
public override void Update(GameTime gametime) { switch (projectileState) { case PROJECTILE_STATE.STILL: this.Visible = false; explosion.Visible = false; break; // Using Lerp here could use target - pos and normalise for direction and then apply // Velocity case PROJECTILE_STATE.FIRING: this.Visible = true; PixelPosition = Vector2.Lerp(PixelPosition, Target, 0.02f * RocketVelocity); // rotate towards the Target this.angleOfRotation = TurnToFace(PixelPosition, Target, angleOfRotation, 1f); if (Vector2.Distance(PixelPosition, Target) < 2) { projectileState = PROJECTILE_STATE.EXPOLODING; } break; case PROJECTILE_STATE.EXPOLODING: explosion.PixelPosition = 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 (soundEffectInstance.State != SoundState.Playing) { soundEffectInstance.Play(); } } // if the timer goes off the explosion is finished if (ExplosionTimer > ExplosionVisibleLimit) { explosion.Visible = false; ExplosionTimer = 0; projectileState = PROJECTILE_STATE.STILL; } base.Update(gametime); }
public override void Update(GameTime gametime) { switch (projectileState) { case PROJECTILE_STATE.STILL: this.Visible = false; explosion.Visible = false; break; // Using Lerp here could use target - pos and normalise for direction and then apply // Velocity case PROJECTILE_STATE.FIRING: this.Visible = true; Tileposition = Vector2.Lerp(Tileposition, Target, 0.02f * RocketVelocity); // rotate towards the Target this.angleOfRotation = TurnToFace(PixelPosition, Target, angleOfRotation, 1f); if (Vector2.Distance(PixelPosition, Target) < 2) projectileState = PROJECTILE_STATE.EXPOLODING; break; case PROJECTILE_STATE.EXPOLODING: explosion.Tileposition = 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; projectileState = PROJECTILE_STATE.STILL; } base.Update(gametime); }
public void fire(Vector2 SiteTarget) { projectileState = PROJECTILE_STATE.FIRING; Target = SiteTarget; }
public void Fire(Vector2 SiteTarget) { projectileState = PROJECTILE_STATE.FIRING; Target = SiteTarget; }
public override void Update(GameTime gametime) { switch (projectileState) { case PROJECTILE_STATE.STILL: this.Visible = false; explosion.Visible = false; explosionTime = TimeSpan.FromSeconds(2); break; // Using Lerp here could use target - pos and normalise for direction and then apply // Velocity case PROJECTILE_STATE.FIRING: this.Visible = true; //PixelPosition = Vector2.Lerp(PixelPosition, Target, 0.02f * RocketVelocity); PixelPosition += Target; // rotate towards the Target this.angleOfRotation = TurnToFace(PixelPosition, Target, angleOfRotation, 1f); if (Vector2.Distance(PixelPosition, Target) <= 2f) { //explosion.PixelPosition += new Vector2(PixelPosition.X, PixelPosition.Y); explosion.Visible = true; projectileState = PROJECTILE_STATE.EXPLODING; } break; case PROJECTILE_STATE.EXPLODING: explosion.Visible = true; explosion.PixelPosition = PixelPosition; //explosion.PixelPosition = explosionLocation; break; } if (projectileState == PROJECTILE_STATE.EXPLODING) { explosion.Update(gametime); explosionTime -= gametime.ElapsedGameTime; if (explosionTime <= TimeSpan.Zero) { explosion.Visible = false; projectileState = PROJECTILE_STATE.STILL; } } //// if the explosion is visible then just play the animation and count the timer //if (explosion != null) //{ // 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; // projectileState = PROJECTILE_STATE.STILL; //} base.Update(gametime); }