/// <summary> /// moves along with the tank, rotates towards the given target and shoots if active /// </summary> /// <param name="basePos">The position of the tank.</param> /// <param name="baseRotation">The rotation of the tank.</param> /// <param name="target">The target.</param> public virtual void Update(Vector2 basePos, float baseRotation, Vector2 target) { //calculates the position of the cannon based on the base position and rotation Pos = CalcPos(basePos, baseRotation); //rotates towards the target target -= Pos; target *= new Vector2(1, -1); Rotation = Tools.RotateTowardsVector(Rotation, target, rotateSpeed); //shoots if active, game is not frozen and the shoot timer is up if (shootTimer.IsTimeUp(Tools.GameTime) && Active && !GameScene.GameIsFrozen()) { //resets the time until next shot shootTimer.Reset(); //creates a new bullet and shoots it var newBullet = Bullet.Clone(Pos, Rotation); GameScene.AddBullet(newBullet); //if this cannon belongs to the player update the ammo if (newBullet.BulletOwner == Owner.Player) { //update te ammo GameScene.RemoveBullet(); } } }
/// <summary> /// chooses with loot to drop /// </summary> private void DropItem() { //randomly chase a number to decide which item to drop var chance = Tools.Rnd.Next(0, 210); switch (chance) { case int n when n < 20: //drop relocate/freeze game item GameScene.AddItem(new RelocateItem(BasePosition)); break; case int n when n < 40: //drop speed boost item GameScene.AddItem(new SpeedBoostItem(BasePosition)); break; case int n when n < 100: //drop coin item GameScene.AddItem(new CoinItem(BasePosition)); break; case int n when n < 130: //drop coin pile item GameScene.AddItem(new CoinPileItem(BasePosition)); break; case int n when n < 170: //drop ammo item GameScene.AddItem(new Ammo(BasePosition)); break; case int n when n < 210: //drop med kit GameScene.AddBullet(new MedKit(BasePosition)); break; } }