public Tile CreateGrass(byte index) { Base.CollisionLayer collisionMask = Base.CollisionLayer.Terrain; IntRect bounds; Texture tileSheet = textureAtlases.GetTexture("grassTilesheet", out bounds); return(new Tile(tileSheet, bounds, index, "Grass", 1.1f, defaultShade, new Color(45, 128, 64), collisionMask, 0.5f, 0.2f, 0.25f)); }
public Tile CreateSnow(byte index) { Base.CollisionLayer collisionMask = Base.CollisionLayer.Terrain; IntRect bounds; Texture tileSheet = textureAtlases.GetTexture("snowTilesheet", out bounds); return(new Tile(tileSheet, bounds, index, "Snow", 0.9f, defaultShade, new Color(12, 12, 12), collisionMask, 0.6f, 0.2f, 0.5f)); }
public Tile CreateDesert(byte index) { Base.CollisionLayer collisionMask = Base.CollisionLayer.Terrain; IntRect bounds; Texture tileSheet = textureAtlases.GetTexture("desertTilesheet", out bounds); return(new Tile(tileSheet, bounds, index, "Desert", 0.85f, defaultShade, new Color(160, 64, 0), collisionMask, 0.75f, 0.25f, 0.75f)); }
public Tile CreateVoid(byte index) { Base.CollisionLayer collisionMask = Base.CollisionLayer.Void | Base.CollisionLayer.TerrainSolid; IntRect bounds; Texture tileSheet = textureAtlases.GetTexture("", out bounds); return(new Tile(tileSheet, bounds, index, "Void", 0, defaultShade, new Color(0, 0, 0), collisionMask, -1.0f, -1.0f, -1.0f)); }
public Tile CreateBeachSand(byte index) { Base.CollisionLayer collisionMask = Base.CollisionLayer.Terrain; IntRect bounds; Texture tileSheet = textureAtlases.GetTexture("sandTilesheet", out bounds); return(new Tile(tileSheet, bounds, index, "Beach Sand", 0.85f, defaultShade, new Color(160, 64, 0), collisionMask, 0.6f, 0.0f, 0.7f)); }
public Tile CreateShallowWater(byte index) { Base.CollisionLayer collisionMask = Base.CollisionLayer.TerrainSolid; IntRect bounds; Texture tileSheet = textureAtlases.GetTexture("shallowwaterTilesheet", out bounds); return(new Tile(tileSheet, bounds, index, "Shallow Water", 0, new Color(255, 255, 255), new Color(0, 0, 255), collisionMask, 1.0f, 0.25f, 0.0f)); }
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 static bool CheckForPlacementCollision(BoundingBox collisionBox, Vector2 position, SurfaceContainer surface, Base.CollisionLayer collisionMask) { int[] chunkList = BoundingBox.GetChunkBounds(collisionBox, position, surface); int[][] tileList = BoundingBox.GetTileBounds(collisionBox, position); for (int i = 0; i < chunkList.Length; i++) { Chunk chunk = surface.GetChunk(chunkList[i], false); if (chunk == null) { continue; } //entity collision checks List <Entity> collisionList = chunk.entityCollisionList; for (int j = 0; j < collisionList.Count; j++) { if ((collisionList[j].collisionMask & collisionMask) != 0) { if (BoundingBox.CheckCollision(collisionBox, collisionList[j].collisionBox, position, collisionList[j].position)) { return(true); } } } //tile collision checks //Perhaps switch to continually checking whether the player is colliding with a tile at his position until he isnt colliding with a tile? //Would fix the situation where getting stuck in water still allows movement within //TODO: try solution outline above for (int j = 0; j < tileList[i].Length; j++) { Tile tile = surface.tileCollection.GetTerrainTile(chunk.GetTile(tileList[i][j])); if ((collisionMask & tile.collisionMask) != 0) { Vector2 tilePos = surface.WorldToTileVector(chunkList[i], tileList[i][j]); if (BoundingBox.CheckCollision(collisionBox, surface.tileBox, position, tilePos)) { return(true); } } } } return(false); }
public PathNode GetPath(SurfaceContainer surface, Vector2 start, Vector2 target, int pathTimeout, Base.CollisionLayer unwalkableMask, Base.CollisionLayer collisionMask, float frictionFactor) { this.frictionFactor = frictionFactor; int frictionMask = (int)(collisionMask & Base.CollisionLayer.Terrain); //a nonzero value means the pathcost is higher for lower frictions frictionMask = frictionMask / (1 + frictionMask); //Normalize the frictionmask to 0 or 1 using +1 trick int[] startCoords = surface.WorldToAbsoluteTileCoords(start.x, start.y); int[] endCoords = surface.WorldToAbsoluteTileCoords(target.x, target.y); float heuristic = CalculateHeuristic(startCoords, endCoords); PathNode startNode = new PathNode(null, 0, 0, heuristic, startCoords); List <PathNode> openList = new List <PathNode>(); List <PathNode> closedList = new List <PathNode>(); PathNode endNode = null; openList.Add(startNode); while (openList.Count > 0 && pathTimeout > 0) { pathTimeout--; PathNode curNode = null; int removeIndex = 0; for (int i = 0; i < openList.Count; i++) { if (curNode == null || openList[i].cost < curNode.cost) { removeIndex = i; curNode = openList[i]; } } openList.RemoveAt(removeIndex); closedList.Add(curNode); if (pathTimeout == 0 || (curNode.coords[0] == endCoords[0] && curNode.coords[1] == endCoords[1])) { endNode = curNode; break; } for (int i = curNode.coords[0] - 1; i <= curNode.coords[0] + 1; i++) { for (int j = curNode.coords[1] - 1; j <= curNode.coords[1] + 1; j++) { bool ignore = false; if (i < 0 || j < 0) //Check if coords are outside worldSize { ignore = true; } if (ignore == false) //else check that coords are not already in closedList { for (int k = 0; k < closedList.Count; k++) { if (closedList[k].coords[0] == i && closedList[k].coords[1] == j) { ignore = true; break; } } } if (ignore == false) //else check that coords are not already in openList { for (int k = 0; k < openList.Count; k++) { if (openList[k].coords[0] == i && openList[k].coords[1] == j) { ignore = true; break; } } } if (!ignore) //if neither of the preceding conditiosn set ignore to false, add tile to open list on path search { Tile tile = tileCollection.GetTerrainTile(surface.GetTileFromWorldInt(i, j)); int solidMask = (int)((unwalkableMask & collisionMask) & tile.collisionMask); // a zero value when the tile is walkable if (solidMask == 0) { int[] coords = new int[] { i, j }; PathNode newNode = new PathNode(curNode, frictionMask * (frictionFactor * (1 / tile.frictionModifier)), curNode.begin + 1, CalculateHeuristic(coords, endCoords), coords); openList.Add(newNode); } } } } } return(endNode); }