/** * Get Tile at Location. * Return a tile with overridden properties from the Map. * * Very Hackish.. */ public GameTile getTile(int x, int y, GameWorld world, ref Engine.Mapfile.TileData tileData) { //Engine.Mapfile.TileData newTileData = tileData; TileSet genTile = generateTile(x, y); tileData.texture = genTile.random(); //newTileData.texture = genTile.random(); //Get the tile from the TileSet. //tileData.texture = newTileData.texture; GameTile gameTile = new GameTile(world, x, y, tileData); gameTile.type = genTile.name; return(gameTile); }
public override void run() { if (transformReady) { Tile current = world.getTileAt(actor.position); for (int i = -2; i <= 2; i++) { for (int j = -2; j <= 2; j++) { Tile checkTile = world.getTile(current.xIndex + i, current.yIndex + j); if (TeamDictionary.TeamDict[team].IsActive && teamValue >= 0 && SPAWN_RANDOM_ACTORS) { AnimalActor newActor = ((GameActorFactory)world.actorFactory).createRandomAnimalActor(new Vector2(checkTile.x, checkTile.y)); GameTile realTile = (GameTile)newActor.FindOpenTile(newActor, checkTile as GameTile); if (realTile != null) { // Move animal to valid position newActor.position.x = realTile.x; newActor.position.y = realTile.y; // Update old position so if a move is cancelled the animal doesn't go back to the invalid position newActor.oldPosition = newActor.position; // Avoid animals flying off of map when moved newActor.velocity = Vector2.Zero; if (newActor != null) { world.addActor(newActor); newActor.teamColor = teamColor; newActor.changeTeam(team); teamValue -= newActor.spawnCost; } } } } } transformReady = false; actor.removeMe = true; } }
private void UpdateInfoBox() { if (teamBoxCooldown == 0) { teamBox.texture = null; } else { teamBoxCooldown--; } Engine.GUI tempGUI = engine.graphicsComponent.gui; //setting a temporary gui again just to set a GUI highlightTile = (GameTile)getTileAt(engine.graphicsComponent.camera.screen2World(engine.inputComponent.getMousePosition())); //the tile that the mouse is hovering over if (highlightTile != null) { //locationBox.texture = highlightTile.texture; highLightPlayer = (this.getAnimalOnTile(highlightTile) as AnimalActor); //updates the Player Information box if (highLightPlayer != null) { //draws the image of the tile when it has one //the text shows the Name and Health of the actor healthInfoBox.text = " Health: " + (highLightPlayer as AnimalActor).life.health + " "; attackInfoBox.text = " Attack: " + (highLightPlayer as AnimalActor).attackDamage.ToString() + " "; attackInfoBox.text += "| Defense: " + (highLightPlayer as AnimalActor).defense.ToString() + " "; levelInfoBox.text = " Level: " + (highLightPlayer as AnimalActor).level.ToString() + " "; if ((highLightPlayer as AnimalActor).level != AnimalActor.maxLevel) { levelInfoBox.text += "| Exp: " + (highLightPlayer as AnimalActor).expPoints.ToString() + "/" + (highLightPlayer as AnimalActor).expLevel[(highLightPlayer as AnimalActor).level + 1].ToString(); } else { levelInfoBox.text += "| Exp: " + (highLightPlayer as AnimalActor).expLevel[(highLightPlayer as AnimalActor).level] + "/" + (highLightPlayer as AnimalActor).expLevel[(highLightPlayer as AnimalActor).level].ToString(); } var mousePos = engine.inputComponent.getMousePosition(); if (mousePos.x < engine.graphicsComponent.camera.screenWidth - 165) { playerInfoOutlineLabel.pos = mousePos + new Vector2(13, -2); playerInfoLabel.pos = mousePos + new Vector2(15, 0); healthInfoBox.pos = mousePos + new Vector2(15, 0); attackInfoBox.pos = mousePos + new Vector2(15, 15); levelInfoBox.pos = mousePos + new Vector2(15, 30); } else { playerInfoOutlineLabel.pos = mousePos + new Vector2(148, -2); playerInfoLabel.pos = mousePos - new Vector2(150, 0); healthInfoBox.pos = mousePos - new Vector2(150, 0); attackInfoBox.pos = mousePos + new Vector2(-150, 15); levelInfoBox.pos = mousePos + new Vector2(-150, 30); } playerInfoOutlineLabel.visible = true; playerInfoLabel.visible = true; healthInfoBox.visible = true; attackInfoBox.visible = true; levelInfoBox.visible = true; } else { playerInfoOutlineLabel.visible = false; playerInfoLabel.visible = false; healthInfoBox.visible = false; attackInfoBox.visible = false; levelInfoBox.visible = false; healthInfoBox.text = ""; attackInfoBox.text = ""; levelInfoBox.text = ""; } } }
/* * Searches for available tile to spawn and actor */ public GameTile FindOpenTile(AnimalActor actor, GameTile initialTile) { if (world.getActorOnTile(initialTile) == null && actor.movementType[initialTile.type] != 999) { return(initialTile); } GameTile possibleTile; int yOffset = 0; // Increase the radius of the search square for (int radius = 1; radius < Math.Max(world.width, world.height); radius++) { // Check each tile in the top row of the square if (initialTile.yIndex - radius > 0) { for (int i = -radius; i < radius; i++) { if (initialTile.xIndex + i > 0) { if (initialTile.xIndex + i > world.width) { break; } possibleTile = (world.getTile(initialTile.xIndex + i, initialTile.yIndex - radius) as GameTile); if (world.getActorOnTile(possibleTile) == null && actor.movementType[possibleTile.type] != 999) { return(possibleTile); } } } } else { yOffset = -(initialTile.yIndex - radius); } // Check each tile in the sides of the square for (int sideY = -radius + yOffset; sideY < radius; sideY++) { if (initialTile.xIndex - radius > 0) { possibleTile = (world.getTile(initialTile.xIndex - radius, initialTile.yIndex + sideY) as GameTile); if (possibleTile != null && world.getActorOnTile(possibleTile) == null && actor.movementType[possibleTile.type] != 999) { return(possibleTile); } } if (initialTile.xIndex + radius < world.width) { possibleTile = (world.getTile(initialTile.xIndex + radius, initialTile.yIndex + sideY) as GameTile); if (possibleTile != null && world.getActorOnTile(possibleTile) == null && actor.movementType[possibleTile.type] != 999) { return(possibleTile); } } } // Check each tile in the bottom row of the square if (initialTile.yIndex + radius < world.height) { for (int i = -radius; i < radius; i++) { if (initialTile.xIndex + i < world.width) { break; } possibleTile = (world.getTile(initialTile.xIndex + i, initialTile.yIndex + radius) as GameTile); if (world.getActorOnTile(possibleTile) == null && actor.movementType[possibleTile.type] != 999) { return(possibleTile); } } } } return(null); }