/// <summary> /// Gets minimap textures for a specified surface. The position is the centered location. The range is the number of chunks x/y away from center to get. /// </summary> /// <param name="surface"></param> /// <param name="position"></param> /// <param name="ranges"></param> public void GenerateMinimapTextures(SurfaceContainer surface, Vector2 position, int xRange, int yRange, List <VertexArray> vertexArrays) { int[] chunkIndices = SurfaceContainer.WorldToChunkCoords(position); vertexArrays.Clear(); for (int i = chunkIndices[0] - xRange; i <= chunkIndices[0] + xRange; i++) { for (int j = chunkIndices[1] - yRange; j <= chunkIndices[1] + yRange; j++) { Chunk chunk = surface.GetChunk((i * surface.worldSize) + j, false); if (chunk != null) { VertexArray vA; if (!minimapVertexArrays.TryGetValue(i * surface.worldSize + j, out vA)) { vA = tileCollection.GenerateTerrainMinimap(chunk, (i * surface.worldSize) + j, surface.worldSize); minimapVertexArrays.Add(i * surface.worldSize + j, vA); } vertexArrays.Add(vA); //next get entities //This is very dynamic so there is no point caching it List <Entity> entityList = chunk.entityList; VertexArray entityArray = new VertexArray(PrimitiveType.Triangles); int oX = i * Props.chunkSize; int oY = j * Props.chunkSize; for (int l = 0; l < entityList.Count; l++) { EntityPhysical e = entityList[l] as EntityPhysical; if (e == null) { continue; } int[] pos = surface.WorldToAbsoluteTileCoords(e.position.x, e.position.y); float halfWidth = e.tileWidth; float halfHeight = e.tileHeight; entityArray.Append(new Vertex(new Vector2f(pos[0] - halfWidth, pos[1] - halfHeight), e.mapColor)); entityArray.Append(new Vertex(new Vector2f(pos[0] + halfWidth, pos[1] - halfHeight), e.mapColor)); entityArray.Append(new Vertex(new Vector2f(pos[0] - halfWidth, pos[1] + halfHeight), e.mapColor)); entityArray.Append(new Vertex(new Vector2f(pos[0] + halfWidth, pos[1] - halfHeight), e.mapColor)); entityArray.Append(new Vertex(new Vector2f(pos[0] + halfWidth, pos[1] + halfHeight), e.mapColor)); entityArray.Append(new Vertex(new Vector2f(pos[0] - halfWidth, pos[1] + halfHeight), e.mapColor)); } if (entityArray.VertexCount > 0) { vertexArrays.Add(entityArray); } } } } }
public void HandleInput(InputManager input) { //TODO: Debug code (move dis) if (inventory == null) { inventory = new List <ItemStack>(); for (int i = 0; i < 10; i++) { inventory.Add(new ItemStack(input.itemCollection.GetItem("Pine Sapling"), 100)); } inventory[8] = new ItemStack(input.itemCollection.GetItem("Greenhouse"), 10); inventory.Add(new ItemStack(input.itemCollection.GetItem("Furnace"), 50)); } //Movement if (playerState == PlayerState.Idle || playerState == PlayerState.Moving) { if (input.GetKeyHeld(InputBindings.moveUp, false)) { velocity.Add(0, -playerVelocity); } if (input.GetKeyHeld(InputBindings.moveDown, false)) { velocity.Add(0, playerVelocity); } if (input.GetKeyHeld(InputBindings.moveLeft, false)) { velocity.Add(-playerVelocity, 0); } if (input.GetKeyHeld(InputBindings.moveRight, false)) { velocity.Add(playerVelocity, 0); } playerState = PlayerState.Moving; } //Determining Selected Entity Vector2f mousePosf; BoundingBox box = new BoundingBox(-2, -2, 2, 2); Vector2 mousePosV; input.GetMousePosition(out mousePosV); bool mouse = input.GetMousePosition(out mousePosf); if (mouse) { List <Entity> list = BoundingBox.CheckSelectionOfType <Entity>(new Vector2(mousePosf), box, surface); if (list.Count > 0) { if (!ReferenceEquals(list[0], selectedEntity)) { miningProgress = 0; selectedEntity = list[0]; if (playerState == PlayerState.Mining) { playerState = PlayerState.Idle; } } } else { miningProgress = 0; selectedEntity = null; } } else { selectedEntity = null; } float[] mousePos; bool mousefloat = input.GetMousePositionAsFloat(out mousePos); //Switch to mining state if suitable if (selectedEntity != null && mousefloat && input.GetMouseHeld(InputBindings.secondary, true) && selectedEntity.minable == true && selectedEntity.position.GetDistance(position) < selectionRange) { playerState = PlayerState.Mining; } EntityPhysical entity = selectedEntity as EntityPhysical; //Check for onClick if (entity != null && input.GetMouseClicked(InputBindings.primary, true)) { entity.OnClick(this, input.menuFactory, input.recipeCollection); input.ConsumeMousePosition(); } //Check for placement ability if (mousefloat && heldItem != null) { if (heldItem.item.placeResult != null && mousePosV.GetDistance(position) < selectionRange) { Entity prototype = input.entityCollection.GetPrototype(heldItem.item.placeResult); float[] tileAligned; if (prototype.tileAligned == true) { tileAligned = new float[] { (int)(mousePos[0] - mousePos[0] % Props.tileSize + (prototype.tileWidth % 2) * 16), (int)(mousePos[1] - mousePos[1] % Props.tileSize + (prototype.tileHeight % 2 + 1) * 16) }; } else { tileAligned = new float[] { mousePos[0], mousePos[1] }; } BoundingBox placeBox = new BoundingBox(prototype.collisionBox); //Use prototype animation to construct entityghost if (!BoundingBox.CheckForPlacementCollision(placeBox, new Vector2(tileAligned[0], tileAligned[1]), surface, prototype.collisionMask)) { placeable = true; if (input.GetMouseHeld(InputBindings.primary, true)) { Entity placeItem = input.entityCollection.InstantiatePrototype(heldItem.item.placeResult, new Vector2(tileAligned[0], tileAligned[1]), surface); heldItem = heldItem.Subtract(1); } } else { placeable = false; } } else { placeable = false; } //Check for dropping item if (input.GetKeyPressed(InputBindings.dropItem, true)) { input.entityCollection.InstantiatePrototype(heldItem.item.name + "Item", new Vector2(mousePos[0], mousePos[1]), surface); heldItem = heldItem.Subtract(1); } } //Open Inventory if (input.GetKeyPressed(InputBindings.showInventory, true)) { input.menuFactory.CreatePlayerInventory(this, inventory); } //Return item to inventory if (input.GetKeyPressed(InputBindings.returnItem, true) && heldItem != null) { ItemStack leftover = InsertIntoInventory(heldItem, false); if (leftover == null) { heldItem = null; } } }