public Cell getBackgroundCell(int x, int y) { Cell cell; if (x >= chunkData.ChunkTilesWidth || y >= chunkData.ChunkTilesHeight) cell = new Cell(0); else cell = chunkData.ChunkBackGroundLayer[x, y]; return cell; }
public void Draw(SpriteBatch spriteBatch) { Vector2 firstSquare = new Vector2(Camara.Location.X / GroundTiles.TileWidth, Camara.Location.Y / GroundTiles.TileHeight); Vector2 squareOffset = new Vector2(Camara.Location.X % GroundTiles.TileWidth, Camara.Location.Y % GroundTiles.TileHeight); Vector2 origin = Vector2.Zero; int pixelPosX; int pixelPosY; int tilePosX; int tilePosY; Cell cell; for (int y = -10; y < 50; y++) { for (int x = -10; x < 50; x++) { Random rand = new Random(); int randPos = rand.Next(0, 0); pixelPosX = (x * GroundTiles.TileWidth) - (int)squareOffset.X; pixelPosY = (y * GroundTiles.TileHeight) - (int)squareOffset.Y; tilePosX = x + (int)firstSquare.X; tilePosY = y + (int)firstSquare.Y; Color cellColor; if ((cell = getCell(tilePosX, tilePosY)) == null) { cell = new Cell(0); } if (Game.debugMode) cellColor = cell.debugColor; else cellColor = cell.color; //Draw Cell GroundTiles.draw(spriteBatch, new Vector2(pixelPosX, pixelPosY), origin, cell.TileID, cellColor, .0001f); if (cell.TileEntityID > 0) { TileEntites.draw(spriteBatch, new Vector2(pixelPosX + (TileEntites.TileWidth / 2), pixelPosY + (TileEntites.TileHeight)), new Vector2(TileEntites.TileWidth / 2, TileEntites.TileHeight), cell.TileEntityID, cell.color); } if (cell.TileTreeID > 0) { TileTrees.draw(spriteBatch, new Vector2(pixelPosX + TileWidth/2, pixelPosY + TileHeight), new Vector2(TileTrees.TileWidth/2, TileTrees.TileHeight), cell.TileTreeID, cell.color); } if (Game.debugMode) { int Xpos = tilePosX - (int)(PlayerPos.X / TileWidth); int Ypos = tilePosY- (int)(PlayerPos.Y/TileHeight); if ((Math.Abs(tilePosX - (int)(PlayerPos.X / TileWidth)) < 5) & (Math.Abs(tilePosY - (int)(PlayerPos.Y / TileHeight)) < 5)) { spriteBatch.DrawString(fontTiny, cell.tilePosition.X + ", " + cell.tilePosition.Y, new Vector2(pixelPosX + 2, pixelPosY+2), Color.White, 0f, origin, 1f, SpriteEffects.None, 1); spriteBatch.DrawString(fontTiny, cell.tilePosition.X + ", " + cell.tilePosition.Y, new Vector2(pixelPosX + 3, pixelPosY+3), Color.Black, 0f, origin, 1f, SpriteEffects.None, .9f); spriteBatch.DrawString(fontTiny, cell.chunkID, new Vector2(pixelPosX + 2, pixelPosY + 10), Color.White, 0f, origin, 1f, SpriteEffects.None, 1); spriteBatch.DrawString(fontTiny, cell.chunkID, new Vector2(pixelPosX + 3, pixelPosY + 11), Color.Black, 0f, origin, 1f, SpriteEffects.None, .9f); } // spriteBatch.DrawString(fontTiny, " " + Camara.calculateDepth(new Vector2(pixelPosX, pixelPosY)), new Vector2(pixelPosX + 2, pixelPosY + 20), Color.White, 0f, origin, 1f, SpriteEffects.None, 1); } }// END X ForLoop } // END Y ForLoop }
public Cell[] getCellArray(Cell cell) { Cell[] CellArray = new Cell[4]; int X = (int)cell.tilePosition.X; int Y = (int)cell.tilePosition.Y; CellArray[0] = getCell(X + 1, Y); CellArray[1] = getCell(X - 1, Y); CellArray[2] = getCell(X, Y + 1); CellArray[3] = getCell(X, Y - 1); // CellArray[4] = getCell(X + 1, Y + 1); // CellArray[5] = getCell(X - 1, Y - 1); //CellArray[6] = getCell(X + 1, Y - 1); // CellArray[7] = getCell(X - 1, Y + 1); return CellArray; }
public PathNode(Cell mapCell, PathNode parent, int g, int h) { this.mapCell = mapCell; this.parent = parent; this.g = g; this.cost = g + h; }
private bool nodeInList(Cell cell, List<PathNode> nodes) { foreach (PathNode node in nodes) { if (cell == node.mapCell) return true; } return false; }
private PathNode getPathNodeByCell(Cell cell, List<PathNode> nodes) { foreach (PathNode node in nodes) { if (cell == node.mapCell) return node; } return null; }
public void update(GameTime gameTime, Player player) { if (HP() <= 0) { dead = true; } else { float distanceToPlayer = Vector2.Distance(player.Position, npcData.Position); Vector2 walktopos; if (distanceToPlayer <= npcData.visiblityRange) { CurrentState = state.walkingToPlayer; } if (distanceToPlayer <= attackRange) { CurrentState = state.attacking; } if (CurrentState == state.walkingToPlayer) { if (world.getCellFromPixelPos(player.Position) != currentPlayerCell) { randomStep = rand.Next(-15, 15); currentPlayerCell = world.getCellFromPixelPos(player.Position); cellPath = pathfinder.FindCellPath(npcData.Position, player.Position); if (cellPath != null) cellPath.RemoveAt(0); } if (cellPath != null && cellPath.Count > 0) { walktopos = new Vector2(cellPath[0].pixelPositionCenter.X + randomStep, cellPath[0].pixelPositionCenter.Y + randomStep); if (Vector2.Distance(walktopos, npcData.Position) > 1) { npcData.Direction = walktopos - npcData.Position; npcData.Direction.Normalize(); } else cellPath.RemoveAt(0); npcData.Position += npcData.Direction * ((float)gameTime.ElapsedGameTime.TotalSeconds * (npcData.speed + randomSpeed)); } } if (CurrentState == state.idle) { npcData.Direction = Vector2.Zero; } if (CurrentState == state.attacking) { npcData.Direction = Vector2.Zero; attackSpeedTimer = attackSpeedTimer - (float)gameTime.ElapsedGameTime.TotalSeconds; if (attackSpeedTimer <= 0) { player.attacked(attackRoll()); attackSpeedTimer = attackSpeed; } } } }
public void setBackgroundCell(int x, int y, Cell newCell) { chunkData.ChunkBackGroundLayer[x, y] = newCell; }