/// <summary> /// constructor. /// </summary> /// <param name="position">position of the items model</param> /// <param name="healPrecentage">precentage of health the potion will heal (between 1 and 100)</param> /// <param name="potionTile">The tile the potion is on.</param> public Potion(Vector3 position, float healPrecentage, Tile potionTile) { // Add this to the collidables list ArenaScene.instance.collidables.Add(this); HealPercent = healPrecentage; Position = position; PotionTile = potionTile; }
public MysteryBox(Vector3 position, Tile MysteryBoxTile) { // Add this to the collidables list ArenaScene.instance.collidables.Add(this); scale = 0.2f; ModelPos = position; modelRotation = 0f; MBtile = MysteryBoxTile; BoxAmbience = BOX_DARK_AMBIENCE; setupOutcomes(); }
/// <summary> /// This is the default constructor for the arena skybox. /// </summary> /// <param name="createTile">The tile to centre on</param> /// <param name="Content">The content manager for loading</param> public ArenaSkybox(Tile createTile, ContentManager Content) { _currentTile = createTile; _Position = new Vector3(_currentTile.getModelPos().X, 0, _currentTile.getModelPos().Z); //should start in the middle of the start tile (X, Y, Z); //_Position = Vector3.Zero; scale = 80f; modelPosition = new Vector3(_currentTile.getModelPos().X, 0, _currentTile.getModelPos().Z);//models position appears on the start tile. myModel = Content.Load<Model>("Models/skybox"); texture = Content.Load<Texture2D>("Models/skyboxBG"); }
/// <summary> /// This is the default constructor for the arena table. /// </summary> /// <param name="createTile">The tile to start on</param> /// <param name="Content">The content manager for loading</param> public ArenaTable(Tile createTile, ContentManager Content) { _currentTile = createTile; _Position = new Vector3(_currentTile.getModelPos().X, -20, _currentTile.getModelPos().Z); //should start in the middle of the start tile (X, Y, Z); //_Position = Vector3.Zero; _forward = ForwardDir.UP; scale = 2f; modelPosition = new Vector3(_currentTile.getModelPos().X, -40, _currentTile.getModelPos().Z);//models position appears on the start tile. myModel = Content.Load<Model>("Models/table"); myTexture = Content.Load<Texture2D>("Models/UVMap-Table"); }
/// <summary> /// default constructor. /// </summary> public Character() { _StartTile = ArenaScene.instance.getStartTile(); _currentTile = _StartTile; _Position = new Vector3(_StartTile.getModelPos().X, 0, _StartTile.getModelPos().Z); //should start in the middle of the start tile (X, Y, Z); _forward = ForwardDir.UP; rotAngle = MathHelper.ToRadians(180); scale = 0.5f; modelRotation = rotAngle; myModel = null; stepsTaken = 0; }
/// <summary> /// The base Tile constructor. This is responsible for loading the tile art and setting its position on the 'board'. /// </summary> /// <param name="parent">The tile's parent (creator)</param> /// <param name="xPos">The x position of the tile in the array</param> /// <param name="yPos">The y position of the tile in the array</param> public Tile(Tile parent, int xPos, int yPos) { this.parent = parent; // Set the position in the array pos = new Vector2(xPos, yPos); // Set the world position based on the position in the array drawPos = new Vector2(xPos * TILE_WIDTH, yPos * TILE_HEIGHT); // Determine the location on-screen compared to the start tile Tile startTile = ArenaBuilder.instance.getStartTile(); modelPosition = new Vector3(drawPos.X, -10, drawPos.Y); //set tile ambience as arena ambience as default TileAmbience = UNDISCOVERED_AMBIENCE; }
/// <summary> /// This is the default constructor for the arena enemy. /// </summary> /// <param name="createTile">The tile to start on</param> /// <param name="Content">The content manager for loading</param> public ArenaEnemy(Tile createTile, ContentManager Content, PartyUtils.Enemy type) { // Add this to the collidables list ArenaScene.instance.collidables.Add(this); _currentTile = createTile; _Position = new Vector3(_currentTile.getModelPos().X, 0, _currentTile.getModelPos().Z); //should start in the middle of the start tile (X, Y, Z); scale = 0.5f; // Set the wait turns randomly waitTurns = ArenaController.instance.getGenerator().Next(1, WAIT_TURNS + 1); this.type = type; myModel = Content.Load<Model>("Models/hero"); setTexture(Content); }
/// <summary> /// will take the input states from the update method call. /// If any of the states indicate character movement, the characters _positon will be updated. /// </summary> /// <param name="baseArena"></param> private void moveCharacter(InputState inputState) { if(!_currentTile.walkedOn()) _currentTile.setWalkedOnAmbience(); PlayerIndex player; if (up.Evaluate(inputState, PlayerIndex.One, out player)) { if (_currentTile.getConnection(TileConnections.TOP) != null) { //deltaZ = deltaZ - Tile.TILE_HEIGHT; Tile temp = _currentTile.getConnection(TileConnections.TOP); _currentTile = temp; ArenaController.instance.setMoved(); SoundUtils.Play(SoundUtils.Sound.Step); stepsTaken++; } } else if (down.Evaluate(inputState, PlayerIndex.One, out player)) { if (_currentTile.getConnection(TileConnections.BOTTOM) != null) { //deltaZ = deltaZ + Tile.TILE_HEIGHT; Tile temp = _currentTile.getConnection(TileConnections.BOTTOM); _currentTile = temp; ArenaController.instance.setMoved(); SoundUtils.Play(SoundUtils.Sound.Step); stepsTaken++; } } else if (left.Evaluate(inputState, PlayerIndex.One, out player)) { if (_currentTile.getConnection(TileConnections.LEFT) != null) { //deltaX = deltaX - Tile.TILE_WIDTH; Tile temp = _currentTile.getConnection(TileConnections.LEFT); _currentTile = temp; ArenaController.instance.setMoved(); SoundUtils.Play(SoundUtils.Sound.Step); stepsTaken++; } rotAngle = MathHelper.ToRadians(0); } else if (right.Evaluate(inputState, PlayerIndex.One, out player)) { if (_currentTile.getConnection(TileConnections.RIGHT) != null) { //deltaX = deltaX + Tile.TILE_WIDTH; Tile temp = _currentTile.getConnection(TileConnections.RIGHT); _currentTile = temp; ArenaController.instance.setMoved(); SoundUtils.Play(SoundUtils.Sound.Step); stepsTaken++; } rotAngle = MathHelper.ToRadians(180); } //update model rotation modelRotation = rotAngle; }
/// <summary> /// This function updates the arena enemy. /// </summary> /// <param name="gameTime">The game time object for timing</param> /// <param name="inputState">The input state object for input</param> public override void Update(GameTime gameTime, InputState inputState) { // If the player moved this frame if (ArenaController.instance.getPlayerMoved()) { waitTurns--; // If it's our turn to move if (waitTurns == 0) { waitTurns = WAIT_TURNS; TileConnections dir = TileConnections.NONE; Random r = ArenaController.instance.getGenerator(); // Search for an adjacent tile for (int i = 0; i < MAX_TRIES; i++) { dir = (TileConnections)r.Next(0, 4); if (_currentTile.getConnection(dir) != null && !_currentTile.getConnection(dir).hasEnemy() && !_currentTile.getConnection(dir).hasExit()) { // We found a good tile break; } else { dir = TileConnections.NONE; } } if (dir != TileConnections.NONE) { // Swap the tile _currentTile.deleteEntity(this); _currentTile = _currentTile.getConnection(dir); _currentTile.addEntity(this); } } } _Position.X += MathUtils.smoothChange(_Position.X, _currentTile.getDrawPos().X, MOVE_RATE); _Position.Z += MathUtils.smoothChange(_Position.Z, _currentTile.getDrawPos().Y, MOVE_RATE); }
/// <summary> /// This function sets a connection between this tile and another. /// </summary> /// <param name="dir">The connection direction</param> /// <param name="t">The tile to connect with</param> public void setConnection(TileConnections dir, Tile t) { connections[(int) dir] = t; }
/** * This function is called when a scene is made active. */ public override void loadScene(ContentManager content) { collidables = new List<Entity>(); if (content == null) content = new ContentManager(SceneManager.Game.Services, "Content"); // Load the shader HLSLeffect = content.Load<Effect>("Effects/Shader"); if (!loaded) { GameSave.seed = Environment.TickCount; GameSave.level = controller.getLevel(); GameSave.partyHealth = PartyUtils.getPartyHealth(); GameSave.score = controller.getScore(); //SAVE SaveUtils.getInstance().saveGame(GameSave); controller.setGenerator(new Random(GameSave.seed)); } // Generate the arena ArenaBuilder builder = new ArenaBuilder(controller.getLevelSize(), controller.getLevelSize(), content, SceneManager.GraphicsDevice.Viewport.AspectRatio, controller.getLevelDifficulty()); baseArena = builder.buildArenaBase(); StartTile = builder.getStartTile(); // if (effect == null) effect = new BasicEffect(SceneManager.Game.GraphicsDevice);//null FlashLightAngle = MIN_FLASH; Hero = new Character(); camera = new Camera(effect, SceneManager.Game.Window.ClientBounds.Width, SceneManager.Game.Window.ClientBounds.Height, SceneManager.GraphicsDevice.Viewport.AspectRatio, Hero.getPOSITION()); //load model Hero.LoadModel(content, SceneManager.GraphicsDevice.Viewport.AspectRatio); table = new ArenaTable(getStartTile(), content); skybox = new ArenaSkybox(getStartTile(), content); potionsUsed = 0; MysteryBoxUsed = false; //load CombatInfo at top left Vector2 start = new Vector2(10, 45); foreach (PlayerSprite ps in PartyUtils.getParty()) { ps.getCombatInfo().init(content, start); start.Y += 60; } pauseMenu.load(content, SceneManager.GraphicsDevice.Viewport); pauseMenu.center(); // Load the level start conversation currentConversation = DialogueUtils.makeConversation((ConversationType)controller.getLevel() - 1); currentConversation.load(content); //load score dispaly ScoreDisplay = new Scoring(); ScoreDisplay.load(content); }
/// <summary> /// This function reloads the arena with a new difficulty. /// </summary> /// <param name="difficulty">The new arena's difficulty</param> public void loadNewArena(ArenaDifficulty difficulty) { collidables = new List<Entity>(); if (content == null) content = new ContentManager(SceneManager.Game.Services, "Content"); //populate the GameSave object GameSave.seed = Environment.TickCount; GameSave.level = controller.getLevel(); GameSave.partyHealth = PartyUtils.getPartyHealth(); GameSave.score = controller.getScore(); //SAVE SaveUtils.getInstance().saveGame(GameSave); controller.setGenerator(new Random(GameSave.seed)); // Set the new ambience colour ambientColour = controller.getAmbience(); // Generate the arena ArenaBuilder builder = new ArenaBuilder(controller.getLevelSize(), controller.getLevelSize(), content, SceneManager.GraphicsDevice.Viewport.AspectRatio, difficulty); baseArena = builder.buildArenaBase(); StartTile = builder.getStartTile(); // if (effect == null) effect = new BasicEffect(SceneManager.Game.GraphicsDevice);//null Hero = new Character(); camera = new Camera(effect, SceneManager.Game.Window.ClientBounds.Width, SceneManager.Game.Window.ClientBounds.Height, SceneManager.GraphicsDevice.Viewport.AspectRatio, Hero.getPOSITION()); //load model Hero.LoadModel(content, SceneManager.GraphicsDevice.Viewport.AspectRatio); potionsUsed = 0; MysteryBoxUsed = false; // Load the level start conversation currentConversation = DialogueUtils.makeConversation((ConversationType)controller.getLevel() - 1); currentConversation.load(content); //load score dispaly ScoreDisplay = new Scoring(); ScoreDisplay.load(content); // Debug arena printDebugArena(); }
/// <summary> /// This function sets the exit point of the arena /// </summary> private void setExit() { Tile curTile = getStartTile(); List<Tile> visited = new List<Tile>(); // Keep digging into the maze until we reach an end point while (curTile == startTile || curTile.getNumConnections() > 1) { int nextDir; do { // Look in a random direction nextDir = r.Next(4); } while (visited.Contains(curTile.getConnection((TileConnections) nextDir)) || curTile.getConnection((TileConnections) nextDir) == null); // Set the next tile in the search visited.Add(curTile); curTile = curTile.getConnection((TileConnections) nextDir); } // Add the exit door to the tile curTile.addEntity(new ArenaExit(curTile, Content)); endTile = curTile; }
/// <summary> /// This function sets the tile's graphical component. /// </summary> /// <param name="tile">The tile to set the art of</param> private void setArenaTile(Tile tile) { Tile[] connections = new Tile[4]; // Retrieve the connections from the tile for (int i = 0; i < connections.Length; i++) { connections[i] = tile.getConnection((TileConnections) i); } string type = ArenaController.instance.getLevelType(); if (connections[0] != null) { // LEFT CONNECTION // if (connections[1] != null) { if (connections[2] != null) { if (connections[3] != null) { // Cross tile.setArenaTile(ArenaTiles.CROSS, type, Content); } else { // Tri-Up tile.setArenaTile(ArenaTiles.TRI_UP, type, Content); } } else { if (connections[3] != null) { // Tri-left tile.setArenaTile(ArenaTiles.TRI_LEFT, type, Content); } else { // Corner Bottom Right tile.setArenaTile(ArenaTiles.CORNER_BR, type, Content); } } } else { if (connections[2] != null) { if (connections[3] != null) { // Tri-Bottom tile.setArenaTile(ArenaTiles.TRI_DOWN, type, Content); } else { // Straight Horizontal tile.setArenaTile(ArenaTiles.STR_HOR, type, Content); } } else { if (connections[3] != null) { // Corner Top Right tile.setArenaTile(ArenaTiles.CORNER_TR, type, Content); } else { // Dead End Right tile.setArenaTile(ArenaTiles.DE_RIGHT, type, Content); } } } } else { // NO LEFT CONNECTION // if (connections[1] != null) { if (connections[2] != null) { if (connections[3] != null) { // Tri-Right tile.setArenaTile(ArenaTiles.TRI_RIGHT, type, Content); } else { // Corner Bottom Left tile.setArenaTile(ArenaTiles.CORNER_BL, type, Content); } } else { if (connections[3] != null) { // Straight Vertical tile.setArenaTile(ArenaTiles.STR_VERT, type, Content); } else { // Dead End Bottom tile.setArenaTile(ArenaTiles.DE_BOTTOM, type, Content); } } } else { if (connections[2] != null) { if (connections[3] != null) { // Corner Top Left tile.setArenaTile(ArenaTiles.CORNER_TL, type, Content); } else { // Dead End Left tile.setArenaTile(ArenaTiles.DE_LEFT, type, Content); } } else { if (connections[3] != null) { // Dead End Top tile.setArenaTile(ArenaTiles.DE_TOP, type, Content); } } } } }
/// <summary> /// This function generates a tile recursively in the arena. /// </summary> /// <param name="parent">The parent tile (or null if it's the first tile)</param> /// <param name="dir">The direction from the parent (or null)</param> /// <param name="numConnections">The number of connections to try to create</param> /// <param name="maxLength">The maximum length of this path</param> /// <returns>The generated tile</returns> private Tile generateTile(Tile parent, TileConnections dir, int numConnections, int maxLength) { Tile tile; if (parent == null) { // This is the first tile in the arena int xPos = r.Next(EDGE_START_BUFFER, tiles.GetLength(1) - EDGE_START_BUFFER); int yPos = r.Next(EDGE_START_BUFFER, tiles.GetLength(0) - EDGE_START_BUFFER); tile = new Tile(parent, xPos, yPos); startTile = tile; tiles[yPos, xPos] = tile; } else { // This is an extension of the arena // Set the connection with the parent switch(dir) { case TileConnections.LEFT: { tile = new Tile(parent, (int)parent.getPos().X - 1, (int)parent.getPos().Y); tile.setConnection(TileConnections.RIGHT, parent); tiles[(int)parent.getPos().Y, (int)parent.getPos().X - 1] = tile; break; } case TileConnections.RIGHT: { tile = new Tile(parent, (int)parent.getPos().X + 1, (int)parent.getPos().Y); tile.setConnection(TileConnections.LEFT, parent); tiles[(int)parent.getPos().Y, (int)parent.getPos().X + 1] = tile; break; } case TileConnections.TOP: { tile = new Tile(parent, (int)parent.getPos().X, (int)parent.getPos().Y - 1); tile.setConnection(TileConnections.BOTTOM, parent); tiles[(int)parent.getPos().Y - 1, (int)parent.getPos().X] = tile; break; } case TileConnections.BOTTOM: { tile = new Tile(parent, (int)parent.getPos().X, (int)parent.getPos().Y + 1); tile.setConnection(TileConnections.TOP, parent); tiles[(int)parent.getPos().Y + 1, (int)parent.getPos().X] = tile; break; } default: { // We won't get here tile = new Tile(parent, (int)parent.getPos().X, (int)parent.getPos().Y); break; } } } // Determine the directions for (int i = 0; i < numConnections; i++) { TileConnections connection = TileConnections.NONE; // Find a free connection for (int j = 0; j < MAX_TRIES; j++) { connection = (TileConnections)r.Next(4); if (tile.getConnection(connection) == null) { int x = (int) tile.getPos().X; int y = (int) tile.getPos().Y; // Check the position in the array if ((y + 1 < height && connection == TileConnections.BOTTOM && tiles[y + 1, x] == null)|| (y - 1 >= 0 && connection == TileConnections.TOP && tiles[y - 1, x] == null) || (x + 1 < width && connection == TileConnections.RIGHT && tiles[y, x + 1] == null) || (x - 1 >= 0 && connection == TileConnections.LEFT && tiles[y, x - 1] == null)) { // We've found our next path break; } else { connection = TileConnections.NONE; } } else { connection = TileConnections.NONE; } } // If we found the next connection if (connection != TileConnections.NONE) { // Determine the next number of connections int nextNumConnections = r.Next(1, 4); if (maxLength == 0) { nextNumConnections = 0; } tile.setConnection(connection, generateTile(tile, connection, nextNumConnections, maxLength - 1)); } else { // We have no more connection opportunities break; } } // Set the tile's art setArenaTile(tile); return tile; }
/// <summary> /// This function fills the rest of the arena with empty tiles. /// </summary> private void fillEmptyTiles() { string type = ArenaController.instance.getLevelType(); for (int i = 0; i < tiles.GetLength(0); i++) { for (int j = 0; j < tiles.GetLength(1); j++) { if (tiles[i, j] == null) { tiles[i, j] = new Tile(null, j, i); tiles[i, j].setArenaTile(ArenaTiles.EMPTY, type, Content); } } } }