Esempio n. 1
0
        public void InitializeResources()
        {
            //Loading text/splashscreen loading
            Image   icon           = new Image("Graphics/GUI/EngineeringCorpsIcon.png");
            Texture loadingTexture = new Texture(icon);
            Sprite  loadingTitle   = new Sprite(loadingTexture);
            Font    loadingFont    = new Font("Fonts/SairaRegular.ttf");
            Text    loadingText    = new Text("", loadingFont);

            loadingText.DisplayedString = "Constructing Texture Atlases...";
            loadingText.Origin          = new Vector2f(loadingText.GetGlobalBounds().Width / 2, loadingText.GetGlobalBounds().Height / 2);
            loadingText.Position        = new Vector2f(window.Size.X / 2, window.Size.Y / 2);
            loadingTitle.Origin         = new Vector2f(loadingTexture.Size.X / 2, loadingTexture.Size.Y / 2);
            loadingTitle.Position       = new Vector2f(window.Size.X / 2, window.Size.Y / 4);

            //Loading textures
            window.Clear(Color.Black);
            window.Draw(loadingTitle);
            window.Draw(loadingText);
            window.Display();
            textureAtlases = new TextureAtlases();
            textureAtlases.LoadTextures(Props.packTogether);

            //Loading fonts
            loadingText.DisplayedString = "Loading Fonts...";
            loadingText.Origin          = new Vector2f(loadingText.GetGlobalBounds().Width / 2, loadingText.GetGlobalBounds().Height / 2);
            window.Clear(Color.Black);
            window.Draw(loadingTitle);
            window.Draw(loadingText);
            window.Display();
            fontContainer = new FontContainer();
            fontContainer.LoadFonts();

            //Initializing Input
            //TODO: Investigate this cyclic couple of the menu system and input.  Input definitely needs access to menufactory.  Menucontainer may not need access to input.
            loadingText.DisplayedString = "Initializing Input...";
            loadingText.Origin          = new Vector2f(loadingText.GetGlobalBounds().Width / 2, loadingText.GetGlobalBounds().Height / 2);
            window.Clear(Color.Black);
            window.Draw(loadingTitle);
            window.Draw(loadingText);
            window.Display();
            input = new InputManager(window);

            //Initializing Rendering systems
            loadingText.DisplayedString = "Initializing Rendering...";
            loadingText.Origin          = new Vector2f(loadingText.GetGlobalBounds().Width / 2, loadingText.GetGlobalBounds().Height / 2);
            window.Clear(Color.Black);
            window.Draw(loadingTitle);
            window.Draw(loadingText);
            window.Display();
            menuContainer = new MenuContainer(input);
            camera        = new Camera();
            camera.SubscribeToInput(input);
            renderer            = new Renderer(window, menuContainer, textureAtlases.GetTexture("guiTilesheet", out _));
            menuFactory         = new MenuFactory(camera, menuContainer, renderer, this, textureAtlases, fontContainer);
            window.Resized     += camera.HandleResize;
            window.Resized     += renderer.HandleResize;
            window.Resized     += menuContainer.RepositionMenus;
            input.menuFactory   = menuFactory;
            input.menuContainer = menuContainer;

            //Loading prototypes
            loadingText.DisplayedString = "Initializing Collections...";
            loadingText.Origin          = new Vector2f(loadingText.GetGlobalBounds().Width / 2, loadingText.GetGlobalBounds().Height / 2);
            window.Clear(Color.Black);
            window.Draw(loadingTitle);
            window.Draw(loadingText);
            window.Display();
            Dictionary <System.Type, UpdateProperties> updateOrder = new Dictionary <Type, UpdateProperties>();

            updateOrder.Add(typeof(Machine), new UpdateProperties(typeof(Machine), 1, false));
            updateOrder.Add(typeof(Tree), new UpdateProperties(typeof(Tree), 600, false));
            updateOrder.Add(typeof(Resource), new UpdateProperties(typeof(Resource), 0, true));
            updateOrder.Add(typeof(Player), new UpdateProperties(typeof(Player), 1, false));
            entityUpdateSystem = new EntityUpdateSystem(updateOrder);
            tileCollection     = new TileCollection(textureAtlases);
            entityCollection   = new EntityCollection(textureAtlases, entityUpdateSystem);
            itemCollection     = new ItemCollection(textureAtlases);
            entityCollection.LoadPrototypes(itemCollection);
            recipeCollection = new RecipeCollection(textureAtlases);
            recipeCollection.LoadRecipes();
            input.entityCollection = entityCollection;
            input.itemCollection   = itemCollection;
            input.recipeCollection = recipeCollection;
        }
Esempio n. 2
0
 /// <summary>
 /// Used to enforce Updatability of entities
 /// </summary>
 /// <param name="entityCollection"></param>
 /// <param name="itemCollection"></param>
 virtual public void Update(EntityCollection entityCollection, ItemCollection itemCollection)
 {
 }
Esempio n. 3
0
 public override void Update(EntityCollection entityCollection, ItemCollection itemCollection)
 {
     if (machineState == MachineState.Working)
     {
         if (recipeProgress >= activeRecipe.recipeTime)
         {
             //Output products
             for (int i = 0; i < activeRecipe.itemsResults.Length; i++)
             {
                 if (result[i] == null)
                 {
                     result[i] = new ItemStack(itemCollection.GetItem(activeRecipe.itemsResults[i]), 0);
                 }
                 result[i].Add(activeRecipe.countsResult[i]);
             }
             recipeProgress = 0;
             machineState   = MachineState.Idle;
             if (idle != null)
             {
                 drawArray = new Drawable[] { idle, shadow };
             }
             if (lightSourceFlicker != null)
             {
                 lightSourceFlicker.on = false;
             }
         }
         else
         {
             recipeProgress += (int)Math.Ceiling(workingSpeed);
             working.Update();
             shadow.currentFrame = working.currentFrame;
         }
     }
     if (machineState == MachineState.Idle)
     {
         //Check that machine has recipe
         if (activeRecipe != null)
         {
             //Check that machine is not full
             bool full = false;
             for (int j = 0; j < activeRecipe.itemsResults.Length; j++)
             {
                 if (result[j] != null && result[j].count >= bufferAmount)
                 {
                     full = true;
                 }
             }
             if (full == false)
             {
                 //Check if input is valid
                 bool valid = true;
                 for (int i = 0; i < activeRecipe.itemsRequired.Length; i++)
                 {
                     if (input[i] == null || input[i].item.name != activeRecipe.itemsRequired[i] || input[i].count < activeRecipe.counts[i])
                     {
                         valid = false;
                     }
                 }
                 if (valid == true)
                 {
                     //Switch state to working and consume inputs
                     machineState = MachineState.Working;
                     drawArray    = new Drawable[] { working, shadow };
                     for (int i = 0; i < activeRecipe.itemsRequired.Length; i++)
                     {
                         input[i] = input[i].Subtract(activeRecipe.counts[i]);
                     }
                     if (lightSourceFlicker != null)
                     {
                         lightSourceFlicker.on = true;
                     }
                 }
             }
         }
     }
 }