private void HandleBulletCollisions(GameTime gameTime)
        {
            for (int index = 0; index < battle.Bullets.Count; index++)
            {
                Bullet  bullet          = battle.Bullets[index];
                Vector2 positionInTiles = bullet.Position / GameSettings.TileSize;

                if (!battle.Map.IsOnMap((int)positionInTiles.X, (int)positionInTiles.Y)) // If the bullet is off the map
                {
                    battle.Bullets.RemoveAt(index);
                    index--;
                    continue;
                }

                foreach (Mech mech in battle.AllMechs)
                {
                    if (!mech.IsAlive || bullet.ShooterTeam.Mechs.Contains(mech))
                    {
                        continue;
                    }

                    if ((mech.Position - bullet.Position).LengthSquared() < GameSettings.TileSize * Math.Max(mech.Size.X, mech.Size.Y))
                    {
                        CollisionReport report = CollisionDetector.DetectCollision(bullet, mech, gameTime);
                        if (report.CollisionOccured == true)
                        {
                            ScrapWarsEventManager.GetManager().SendEvent(new BulletHitMechEvent(mech, bullet));
                            battle.Bullets.RemoveAt(index);
                            index--;
                            break;
                        }
                    }
                }
            }
        }
Example #2
0
 public void Damage(int damage)
 {
     currHp -= damage;
     if (!IsAlive)
     {
         ScrapWarsEventManager.GetManager().SendEvent(new MechDiedEvent(this));
     }
 }
Example #3
0
        public void Fire(Mech shooter, Vector2 position, Vector2 direction, int time)
        {
            if (time - timeLastFired > 1000 / rateOfFire)
            {
                timeLastFired = time;
                if (direction.LengthSquared() != 1)
                {
                    direction.Normalize();
                }

                Bullet bullet = new Bullet(shooter.Team, damage, range, bulletScale, bulletType, position, bulletSpeed, direction);
                ScrapWarsEventManager.GetManager().SendEvent(new BulletFiredEvent(bullet));
            }
        }
Example #4
0
        public bool AnalyzeCollision(BaseGameEvent theEvent)
        {
            BulletHitMechEvent bulletHit = (BulletHitMechEvent)theEvent;

            if (bulletHit.Mech.mechId == mechId)
            {
                currHp -= bulletHit.Bullet.Damage;
                if (!IsAlive)
                {
                    ScrapWarsEventManager.GetManager().SendEvent(new MechDiedEvent(this));
                }
            }

            return(false);
        }
Example #5
0
 internal void EndBattle()
 {
     ScrapWarsEventManager.GetManager().UpsubscribeFromAll(this);
     scrapWarsApp.RevertScreen(); // TODO: Make this show a battle report screen
 }
Example #6
0
 private void SubscribeToEvents()
 {
     ScrapWarsEventManager.GetManager().Subscribe(this, AddBullet, "BulletFired");
 }
 public SoundEffectPlayer( )
 {
     ScrapWarsEventManager.GetManager( ).Subscribe(this, MakeSound, "BulletHitMech");
 }
Example #8
0
 public void Subscribe()
 {
     ScrapWarsEventManager.GetManager().Subscribe(this, AnalyzeCollision, "BulletHitMech");
 }