/// <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); } }
//Define items prototypes here: private Item CreatePineSapling() { IntRect bounds; StaticSprite itemIcon = new StaticSprite(textureAtlases.GetTexture("woodItem", out bounds), bounds, Drawable.DrawLayer.Item); return(new Item("Pine Sapling", itemIcon, "Pine Tree 1", 100)); }
public Recipe GrowWoodRecipe() { IntRect bounds; StaticSprite recipeIcon = new StaticSprite(textureAtlases.GetTexture("woodItem", out bounds), bounds, Drawable.DrawLayer.None); Recipe recipe = new Recipe("Grow Wood", new int[0], new string[0], new int[] { 1 }, new string[] { "Wood" }, 180, recipeIcon); recipe.canBeMadeIn = new string[] { "Greenhouse" }; return(recipe); }
public Tile CreateDeepWater(byte index) { Base.CollisionLayer collisionMask = Base.CollisionLayer.TerrainSolid; IntRect bounds; Texture tileSheet = textureAtlases.GetTexture("deepwaterTilesheet", out bounds); return(new Tile(tileSheet, bounds, index, "Deep Water", 0, defaultShade, new Color(0, 45, 200), collisionMask, 1.0f, 0.5f, 0.0f)); }
public override void InitializeEntity(Vector2 position, SurfaceContainer surface) { base.InitializeEntity(position, surface); IntRect bounds; radialLight = new LightSourceRadial(surface, 256.0f, textureAtlases.GetTexture("lightsource", out bounds), bounds); radialLight.on = true; radialLight.attachedEntity = this; directionalLight = new LightSourceDirectional(surface, 2000.0f, 1024, textureAtlases.GetTexture("directionallight", out bounds), bounds); directionalLight.on = true; directionalLight.attachedEntity = this; }
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(); }
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; }
private Entity CreatePineTree1() { IntRect bounds; StaticSprite trunk = new StaticSprite(textureAtlases.GetTexture("tree", out bounds), new IntRect(bounds.Left, bounds.Top, bounds.Width / 4, bounds.Height), new Vector2f(0, -64)); trunk.drawLayer = Drawable.DrawLayer.EntitySorted; Animation leaves = new Animation(textureAtlases.GetTexture("tree", out bounds), 128, bounds.Height, 1, bounds, new Vector2f(0, -64)); leaves.drawLayer = Drawable.DrawLayer.EntitySorted; Animation shadow = new Animation(textureAtlases.GetTexture("treeshadow", out bounds), 192, bounds.Height, 1, bounds, new Vector2f(32, 0)); shadow.drawLayer = Drawable.DrawLayer.Shadow; Tree pineTree1 = new Tree("Pine Tree 1", trunk, leaves, shadow); pineTree1.collisionMask = Base.CollisionLayer.EntityPhysical | Base.CollisionLayer.TerrainSolid; pineTree1.mapColor = new Color(32, 160, 0); pineTree1.miningProps = new EntityPhysical.MiningProps("Wood", 1, 90, 0, ""); pineTree1.miningSounds = new string[] { "Chop1", "Chop2", "Chop3" }; pineTree1.minable = true; pineTree1.collisionBox = new BoundingBox(16, 16); pineTree1.drawingBox = new BoundingBox(128, 192); pineTree1.selectionBox = new BoundingBox(32, 32); return(pineTree1); }
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; }