示例#1
0
        public bool Initialize(int screenWidth, int screenHeight, Xasteroids parentForm, out string reason)
        {
            _parentForm = parentForm;
            Random = new Random();
            MousePos = new Point();
            ScreenSize = new Point(screenWidth, screenHeight);
            PlayerList = new PlayerList();

            ShipShader = GorgonLibrary.Graphics.FXShader.FromFile("ColorShader.fx", GorgonLibrary.Graphics.ShaderCompileOptions.OptimizationLevel3);

            if (!SpriteManager.Initialize(out reason))
            {
                return false;
            }
            if (!FontManager.Initialize(out reason))
            {
                return false;
            }

            _backgroundStars = new BackgroundStars();
            if (!_backgroundStars.Initialize(this, out reason))
            {
                return false;
            }

            Cursor = SpriteManager.GetSprite("Cursor", Random);
            if (Cursor == null)
            {
                reason = "Cursor is not defined in sprites.xml";
                return false;
            }

            PlayerManager = new PlayerManager(this);
            AsteroidManager = new AsteroidManager(this);
            ObjectManager = new ObjectManager(this);
            ShipSelectionWindow = new ShipSelectionWindow();
            if (!ShipSelectionWindow.Initialize(this, out reason))
            {
                return false;
            }
            ShipSelectionWindow.ShipSelected += OnShipSelected;

            _mainMenu = new MainMenu();
            if (!_mainMenu.Initialize(this, out reason))
            {
                return false;
            }

            _screenInterface = _mainMenu;
            _currentScreen = Screen.MainMenu;

            ChatText = new StringBuilder();
            NewChatMessage = false;

            return true;
        }
示例#2
0
 public void HandleBullets(Bullet bullet, ObjectManager objectManager, float frameDeltaTime)
 {
     if (bullet.Damage <= 0)
     {
         return;
     }
     foreach (var asteroid in _asteroidsInCell)
     {
         if (asteroid.HP <= 0 || asteroid.ImpactedBullets.Contains(bullet))
         {
             continue;
             //This asteroid was destroyed, or already impacted by this bullet, skip checking
         }
         float tx1 = bullet.PositionX + bullet.VelocityX * frameDeltaTime;
         float ty1 = bullet.PositionY + bullet.VelocityY * frameDeltaTime;
         float tx2 = asteroid.PositionX + asteroid.VelocityX * frameDeltaTime;
         float ty2 = asteroid.PositionY + asteroid.VelocityY * frameDeltaTime;
         float rx = tx2 - tx1;
         float ry = ty2 - ty1;
         if ((float)Math.Sqrt(rx * rx + ry * ry) < (asteroid.Radius)) //bullet impact!
         {
             float damageDone = asteroid.HP;
             asteroid.HP -= bullet.Damage;
             damageDone -= asteroid.HP;
             asteroid.ImpactedBullets.Add(bullet);
             if (asteroid.HP <= 0)
             {
                 damageDone += asteroid.HP;
                 //Give money to player who shot it
                 int value;
                 switch (asteroid.AsteroidType)
                 {
                     case AsteroidType.GENERIC:
                         value = 15;
                         break;
                     case AsteroidType.CLUMPY:
                         value = 10;
                         break;
                     case AsteroidType.MAGNETIC:
                         value = 50;
                         break;
                     case AsteroidType.REPULSER:
                         value = 30;
                         break;
                     case AsteroidType.GRAVITIC:
                         value = 40;
                         break;
                     case AsteroidType.DENSE:
                         value = 30;
                         break;
                     case AsteroidType.ZIPPY:
                         value = 15;
                         break;
                     case AsteroidType.EXPLOSIVE:
                         value = 40;
                         break;
                     case AsteroidType.BLACK:
                         value = 30;
                         break;
                     case AsteroidType.GOLD:
                         value = 200;
                         break;
                     default:
                         value = 50;
                         break;
                 }
                 if (PlayerIsOwedMoney != null)
                 {
                     PlayerIsOwedMoney(bullet.OwnerName, value * asteroid.Size);
                 }
             }
             bullet.Damage -= damageDone * (1 - (bullet.PenetratingLevel * 0.10f));
             objectManager.AddExplosion(bullet.PositionX, bullet.PositionY, asteroid.VelocityX, asteroid.VelocityY, 1);
         }
     }
 }