Example #1
0
 public MenuFactory(Camera camera, MenuContainer menuContainer, Renderer renderer, Program program, TextureAtlases textureAtlases, FontContainer fontContainer)
 {
     this.menuContainer  = menuContainer;
     this.renderer       = renderer;
     this.program        = program;
     this.fontContainer  = fontContainer;
     this.textureAtlases = textureAtlases;
     this.camera         = camera;
 }
Example #2
0
        public Dictionary <string, Recipe> GetRecipes(TextureAtlases textureAtlases)
        {
            Dictionary <string, Recipe> recipeCollection = new Dictionary <string, Recipe>();

            this.textureAtlases = textureAtlases;
            Recipe recipe = GrowWoodRecipe();

            recipeCollection.Add(recipe.name, recipe);
            return(recipeCollection);
        }
Example #3
0
        public TileCollection(TextureAtlases textureAtlases)
        {
            TileFactory tileFactory = new TileFactory(textureAtlases);

            cliffTilesheet      = textureAtlases.GetTexture("cliffTilesheet", out cliffBounds);
            terrainTiles        = tileFactory.GetTerrainTiles();
            impassableTileTypes = new List <byte>();
            for (byte i = 0; i < terrainTiles.Count; i++)
            {
                if ((terrainTiles[i].collisionMask & Base.CollisionLayer.TerrainSolid) == Base.CollisionLayer.TerrainSolid)
                {
                    impassableTileTypes.Add(i);
                }
            }
            terrainPathTiles = tileFactory.GetTerrainPathTiles();
        }
Example #4
0
        public Player(TextureAtlases textureAtlases, string name)
        {
            this.name           = name;
            this.textureAtlases = textureAtlases;
            collisionBox        = new BoundingBox(16, 16);
            drawingBox          = new BoundingBox(-64, -64, 64, 64);
            velocity            = new Vector2(0, 0);
            IntRect bounds;
            Texture playerTexture = textureAtlases.GetTexture("orcrunning", out bounds);

            walking           = new AnimationRotated(playerTexture, 128, 128, bounds, new Vector2f(0, -32), 8, 8);
            walking.drawLayer = Drawable.DrawLayer.EntitySorted;
            walking.behavior  = AnimationRotated.AnimationBehavior.Forward;
            drawArray         = new Drawable[] { walking };
            collisionMask     = CollisionLayer.EntityPhysical | CollisionLayer.TerrainSolid;
            mapColor          = Color.Magenta;
        }
Example #5
0
 public TileFactory(TextureAtlases textureAtlases)
 {
     this.textureAtlases = textureAtlases;
     defaultShade        = new Color(255, 255, 255, 255);
 }
Example #6
0
        public ItemFactory(TextureAtlases textureAtlases)
        {
            itemCollection = new Dictionary <string, Item>();

            this.textureAtlases = textureAtlases;
        }
Example #7
0
 public RecipeCollection(TextureAtlases textureAtlases)
 {
     this.textureAtlases = textureAtlases;
 }
Example #8
0
 public ItemCollection(TextureAtlases textureAtlases)
 {
     itemFactory    = new ItemFactory(textureAtlases);
     itemCollection = itemFactory.GetItems();
 }
Example #9
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;
        }
Example #10
0
 public EntityCollection(TextureAtlases textureAtlases, EntityUpdateSystem entityUpdateSystem)
 {
     entityPrototypes        = new Dictionary <string, Entity>();
     this.textureAtlases     = textureAtlases;
     this.entityUpdateSystem = entityUpdateSystem;
 }
Example #11
0
        /// <summary>
        /// Renders the selection box of an entity for a player
        /// </summary>
        /// <param name="window"></param>
        /// <param name="input"></param>
        /// <param name="camera"></param>
        /// <param name="player"></param>
        /// <param name="textureAtlases"></param>
        public void RenderSelectionBox(RenderWindow window, Camera camera, Player player, TextureAtlases textureAtlases)
        {
            window.SetView(camera.GetGameView());
            if (player.selectedEntity != null)
            {
                VertexArray  selectionArray = new VertexArray(PrimitiveType.Triangles);
                RenderStates selectionState;
                IntRect      bounds;
                if ((player.selectedEntity.position - player.position).GetMagnitude() < player.selectionRange)
                {
                    selectionState = new RenderStates(textureAtlases.GetTexture("SelectionBox", out bounds));
                }
                else
                {
                    selectionState = new RenderStates(textureAtlases.GetTexture("SelectionBoxInvalid", out bounds));
                }
                float[]  points    = player.selectedEntity.selectionBox.GetPoints();
                Vector2f pos       = player.selectedEntity.position.internalVector;
                int      toX       = bounds.Left;
                int      toY       = bounds.Top;
                Vector2f posOrigin = new Vector2f(points[0], points[1]);
                Vector2f xInc      = new Vector2f(32, 0);
                Vector2f yInc      = new Vector2f(0, 32);
                xInc = xInc * player.selectedEntity.selectionBox.GetWidth() / 64;
                yInc = yInc * player.selectedEntity.selectionBox.GetHeight() / 64;
                //Top left
                selectionArray.Append(new Vertex(posOrigin + pos, new Vector2f(toX, toY)));
                selectionArray.Append(new Vertex(posOrigin + pos + xInc, new Vector2f(toX + 32, toY)));
                selectionArray.Append(new Vertex(posOrigin + pos + yInc, new Vector2f(toX, toY + 32)));

                //Top right
                posOrigin = new Vector2f(points[2], points[3]);
                selectionArray.Append(new Vertex(posOrigin + pos - xInc, new Vector2f(toX + 32, toY)));
                selectionArray.Append(new Vertex(posOrigin + pos, new Vector2f(toX + 64, toY)));
                selectionArray.Append(new Vertex(posOrigin + pos + yInc, new Vector2f(toX + 64, toY + 32)));

                //bottom left
                posOrigin = new Vector2f(points[6], points[7]);
                selectionArray.Append(new Vertex(posOrigin + pos - yInc, new Vector2f(toX, toY + 32)));
                selectionArray.Append(new Vertex(posOrigin + pos + xInc, new Vector2f(toX + 32, toY + 64)));
                selectionArray.Append(new Vertex(posOrigin + pos, new Vector2f(toX, toY + 64)));

                posOrigin = new Vector2f(points[4], points[5]);
                selectionArray.Append(new Vertex(posOrigin + pos - xInc, new Vector2f(toX + 32, toY + 64)));
                selectionArray.Append(new Vertex(posOrigin + pos - yInc, new Vector2f(toX + 64, toY + 32)));
                selectionArray.Append(new Vertex(posOrigin + pos, new Vector2f(toX + 64, toY + 64)));
                window.Draw(selectionArray, selectionState);
            }
        }