예제 #1
0
        public Vector2 GetLocation(SpaceShip Ship, float Scalar)
        {
            SpaceShipUnit unit = Ship.Unit;

            if (unit == null || unit.Units.Count == 1 || unit.Units[0] == Ship)
            {
                return(Ship.Location);
            }

            int index = 0;

            while (index < unit.Units.Count && index <= slots.Count)
            {
                if (unit.Units[index] == Ship)
                {
                    break;
                }
                index++;
            }

            if (index < slots.Count)
            {
                return(unit.Units[0].Location + (slots[index].Rotate((float)unit.Units[0].Angle * DEG2RAD) * Scalar));
            }

            return(Ship.Location);
        }
예제 #2
0
        public static SpaceShipUnit FromXml(XmlResource Xml, SpaceShipUnit DstObject)
        {
            if (Xml == null)
            {
                throw new ArgumentNullException("Xml");
            }
            SpaceShipUnit Result = DstObject;

            if (DstObject == null)
            {
                Result = new SpaceShipUnit();
            }

            XmlNode obj = Xml.Xml.LastChild;

            string        baseName   = GetXmlText(obj, "Base", string.Empty);
            SpaceShipUnit baseObject = Result;

            if (!string.IsNullOrEmpty(baseName))
            {
                try
                {
                    baseObject = SpaceShipUnit.FromXml(ResourceManager.Get <XmlResource>(baseName), null);
                }
                catch (KeyNotFoundException e)
                {
                    baseObject = Result;
                    Console.WriteLine("XML Error: Failed to locate XML base " + baseName);
                }
            }

            List <SpaceObject> units = GetXmlNested(obj, "ships", null);

            if (units != null && units.Count > 0)
            {
                Result.Units.Clear();
                foreach (SpaceObject o in units)
                {
                    SpaceShip ss = o as SpaceShip;
                    if (ss != null)
                    {
                        Result.Add(ss);
                    }
                }
            }

            Result.UiImage = ResourceManager.Get <TextureResource>(GetXmlText(obj, "image", baseObject.UiImage.Name));

            return(Result);
        }
예제 #3
0
 public static void Add(SpaceShipUnit Unit)
 {
     Instantiate();
     if (!Instance.Units.Contains(Unit))
     {
         Instance.Units.Add(Unit);
     }
     foreach (SpaceShip ship in Unit.Units)
     {
         Add(ship);
         if (ship.Hardpoints != null)
         {
             foreach (SpaceShipHardpoint hp in ship.Hardpoints)
             {
                 Add(hp);
             }
         }
     }
 }
예제 #4
0
        private static int CommandSpawnUnit(List <string> arg)
        {
            if (arg == null || arg.Count < 1)
            {
                Debug.WriteLine("%WARNING%Usage: \"spawn-unit <xml name>\"");
                return(1);
            }

            SpaceShipUnit newUnit = new SpaceShipUnit();

            for (int i = 0; i < 7; i++)
            {
                SpaceShip newShip = SpaceShip.FromXml(ResourceManager.Get <XmlResource>(arg[0]), null);
                newShip.Location = new Vector2(0, 0);
                newShip.Faction  = 2;
                newShip.Hitbox   = new Hitbox(newShip.Texture.Texture.width);
                newUnit.Add(newShip);
            }
            newUnit.UiImage = ResourceManager.Get <TextureResource>(@"thumbnail\barb");
            GameManager.Add(newUnit);

            return(0);
        }
예제 #5
0
        public static void Main()
        {
            ResourcesPath = System.IO.Directory.GetCurrentDirectory() + @"\..\..\..\..\resources\";

            /*
             * SetTargetFPS(120);
             * InitWindow(800, 600, "Loading");
             * BackgroundWorker loadingWorker = new BackgroundWorker();
             * loadingWorker.DoWork += LoadingWorker_DoWork;
             * loadingWorker.RunWorkerAsync();
             *
             * TextureResource bkg = null;
             * FontResource fnt = null;
             * Color bkgColor = Color.WHITE;
             * Color foreColor = Color.BLACK;
             * while (loadingWorker.IsBusy)
             * {
             *  if (ResourceManager.Instance != null && (bkg == null || fnt == null))
             *  {
             *      try { bkg = ResourceManager.GetTexture("_menu\\loading"); } catch { }
             *      try { fnt = ResourceManager.GetFont("Perfect_DOS_VGA_437_Win"); } catch { }
             *  }
             *
             *  BeginDrawing();
             *  Raylib.Raylib.ClearBackground(bkgColor);
             *  if (bkg != null)
             *  {
             *      Raylib.Raylib.DrawTexturePro(bkg.Texture, new Rectangle(0, 0, bkg.Texture.width, bkg.Texture.height), new Rectangle(0, 0, 800, 600), Vector2.Zero, 0.0f, Color.WHITE);
             *      bkgColor = Color.BLACK;
             *      foreColor = Color.WHITE;
             *  }
             *
             *  if (fnt != null) { Raylib.Raylib.DrawTextEx(fnt.Font, "Loading", new Vector2(20, 20), 16, 4, foreColor); }
             *  else { Raylib.Raylib.DrawText("Loading", 20, 20, 16, foreColor); }
             *  if (ResourceManager.Instance != null)
             *  {
             *      if (ResourceManager.Instance.Xml.Count > 0)
             *      {
             *          string txt = ResourceManager.Instance.Xml.Count + " XML files";
             *          if (fnt != null) { Raylib.Raylib.DrawTextEx(fnt.Font, txt, new Vector2(20, 50), 16, 4, foreColor); }
             *          else { Raylib.Raylib.DrawText(txt, 20, 50, 16, foreColor); }
             *      }
             *      if (ResourceManager.Instance.Fonts.Count > 0)
             *      {
             *          string txt = ResourceManager.Instance.Fonts.Count + " fonts";
             *          if (fnt != null) { Raylib.Raylib.DrawTextEx(fnt.Font, txt, new Vector2(20, 80), 16, 4, foreColor); }
             *          else { Raylib.Raylib.DrawText(txt, 20, 80, 16, foreColor); }
             *      }
             *      if (ResourceManager.Instance.Sounds.Count > 0)
             *      {
             *          string txt = ResourceManager.Instance.Sounds.Count + " sounds";
             *          if (fnt != null) { Raylib.Raylib.DrawTextEx(fnt.Font, txt, new Vector2(20, 110), 16, 4, foreColor); }
             *          else { Raylib.Raylib.DrawText(txt, 20, 110, 16, foreColor); }
             *      }
             *      if (ResourceManager.Instance.Scripts.Count > 0)
             *      {
             *          string txt = ResourceManager.Instance.Scripts.Count + " scripts";
             *          if (fnt != null) { Raylib.Raylib.DrawTextEx(fnt.Font, txt, new Vector2(20, 140), 16, 4, foreColor); }
             *          else { Raylib.Raylib.DrawText(txt, 20, 110, 16, foreColor); }
             *      }
             *      if (ResourceManager.Instance.Textures.Count > 0)
             *      {
             *          string txt = ResourceManager.Instance.Textures.Count + " textures";
             *          if (fnt != null) { Raylib.Raylib.DrawTextEx(fnt.Font, txt, new Vector2(20, 170), 16, 4, foreColor); }
             *          else { Raylib.Raylib.DrawText(txt, 20, 110, 16, foreColor); }
             *      }
             *  }
             *
             *  string line = Debug.ConsoleBuffer;
             *  if (fnt != null) { Raylib.Raylib.DrawTextEx(fnt.Font, line, new Vector2(20, 580), 16, 4, foreColor); }
             *  else { Raylib.Raylib.DrawText(line, 20, 580, 16, foreColor); }
             *  EndDrawing();
             * }
             * CloseWindow();
             */
            ResourceManager.Register(typeof(XmlResource), new string[] { ".xml" });
            ResourceManager.Register(typeof(ScriptResource), new string[] { ".cs" });
            ResourceManager.Load(ResourcesPath);
            GameManager.Instantiate();

            InitWindow((int)Math.Max(1024, Debug.GetFlag("ScreenWidth")), (int)Math.Max(768, Debug.GetFlag("ScreenHeight")), "SpaceGame");
            SetConfigFlags(ConfigFlag.FLAG_VSYNC_HINT | ConfigFlag.FLAG_MSAA_4X_HINT | ((Debug.GetFlag("Fullscreen") == 1) ? (ConfigFlag.FLAG_FULLSCREEN_MODE) : 0));

            for (int j = 0; j < 2; j++)
            {
                SpaceShipUnit unitEnemy = SpaceShipUnit.FromXml(ResourceManager.Get <XmlResource>(@"xml\unit\base_fighter_squadron"), null);
                unitEnemy.Location  = new Vector2(900, 900 - (j * 60));
                unitEnemy.Formation = new Formation();
                GameManager.Add(unitEnemy);
            }

            /*SpaceShip objPlayer = SpaceShip.FromXml(ResourceManager.Get<XmlResource>(@"xml\ship\base_cruiser"), null);
             * objPlayer.Faction = 1;
             * objPlayer.Location = new Vector2(1000, 300);
             * objPlayer.Hitbox = Hitbox.Automatic(objPlayer.Texture, (int)Math.Floor(objPlayer.Texture.Texture.height / 32.0));
             *
             * SpaceShipUnit unitPlayer = new SpaceShipUnit(objPlayer);
             * unitPlayer.UiImage = ResourceManager.Get<TextureResource>(@"images\thumbnail\kar ik vot 349");
             * GameManager.Add(unitPlayer);*/

            SpaceStructure station = new SpaceStructure()
            {
                Texture   = ResourceManager.Get <TextureResource>(@"images\planet\station2"),
                Location  = new Vector2(1500, 500),
                Scale     = 2.0f,
                Hitbox    = Hitbox.Automatic(ResourceManager.Get <TextureResource>(@"images\planet\station2"), 6),
                Faction   = 2,
                MaxHull   = 1000,
                Hull      = 1000,
                MaxShield = 1000,
                Shield    = 1000
            };

            GameManager.Add(station);

            const double TargetFps = 60;

            SetTargetFPS((int)TargetFps);
            while (!WindowShouldClose())
            {
                double fps   = Math.Clamp(GetFPS(), 25, 1000);
                double delta = TargetFps / fps;

                GameManager.Tick(delta);

                UiManager.Tick(delta);

                BeginDrawing();

                GameManager.Draw();

                UiManager.Draw();

                Debug.Draw();

                EndDrawing();

                ResourceManager.Cull();
            }

            CloseWindow();
        }