LevelManager

Description

Will hold all the data for a level such as level sections. Level data will be loaded by the Loader class from an XML file. Each level section will describe the images in it, obstacles, enemies(type and position), and checkpoints. Things the manager does is makes the level based off of the data received from the Loader, sends data to the pool manager to make the minimum resources for a level, passes in the tile data to the tile manager, updating the enemies and boss, communicates with the collision manager to test collisions, and calls draw on everything in the level so that it draws in the correct order. This will also send dialogue data to the LevelDialogue class and have it show the dialogue.

Relationships

  • GameManager : made by the GameManager
  • PoolManager : makes a PoolManager which holds the minimum number of resources in a level
  • Boss : makes the correct Boss class based on the data from the XML
  • GridManager : makes a GridManager
  • TileManager : makes the TileManager which holds tile data for the background, midground (this includes color map), and foreground.
  • Loader: accesses the Loader class to load in the levels
  • CollisionManager : checks for collisions with CollisionManager
  • LevelDialogue : makes a LevelDialogue and uses it to show dialogue in the level

Members

  • const float SELECTION_RATIO - heuristic for determining where the selection reticle goes
  • int currentSection - the index of the current level section the player is in
  • int iter - looping iteration
  • int lastCheckPoint - the index of the level section which contains the last checkpoint reached by the player
  • List poolManager - the pool manager which makes and holds the enemies and images used in the level
  • List sections - a list containing all level sections in the level
  • Boss boss - the boss that is in this level
  • TileManager tile - the tile manager used to draw the tiled backgrounds/foregrounds
  • LevelDialogue dialogue - the class that stores and draws the dialogue onscreen
  • bool showDialogue - whether or not it should be udating the dialogue

Methods

  • Reset
    • This method will take in a list of level sections and a boss. the sections and boss will get set by those. Then the pool manager will get set up based on the new level sections. The tile manager will get all the tile data from the level sections. currentSection will get set to 0.
  • Update
    • Check to see if the player is still alive. It not, will call the GameOver method
    • call update of the enemies whose isActive property is true
    • if in the last level section call update for boss
      • If the boss has died, then load the next level and save the current game using Loader by calling the savegame method. Will load the next method by using the changestate method in Window and pass in the loading state.
    • calls the CheckCollisions method
    • updates the positions of enemies/objects/player in the gridmanager
    • will call CheckDialogue
    • based on the player's position and the current level sections bounding box, it will check if the player has reached the next section or gone back to a previous one. These checks will be done on the previous section in the list(if the current section is not the first one) and the next section in the list(if the current one isn't the last section)
  • CheckDialogue
    • If showDialogue is false, then it will check if it has reached a spot in the current level section where dialogue should be shown, and if so then it will start the dialogue by passing in the name of it to LevelDialogues ShowDialogue method. Will also se showDialogue to true.
    • If show Dialogue is true it will call update on the LevelDialogue. If its dialogueDone property is now true then showDialogue will get set to false
  • GameOver
    • Set everything into the PoolManager to inactive
    • Set player's position to the last checkpoint
    • Set the current section to the checkpoint variable
    • Set player to active
    • Populate the area based on the current section
  • Draw
    • calls draw for backgrounds in tile manager
    • calls draw for all currentEnemies, boss, and play field objects drawing those with a higher z first
    • calls players draw durning midground drawing
    • calls draw for foreground in tile manager
    • calls draw for the LevelDialogue if showDialogue is true
  • Simulate
  • CheckCollisions
    • This method will handle all collision detection between the player, enemies, attacks, and level objects. The player is a singleton so it can be accessed easily, the level manager has the enemies and there attacks, and it can access the level objects from the current level section. Collisions will be tested by passing in either 2 BB's, a BB and a ray, or 2 rays to the collision manager, and if true is returned it will carry out the correct response. Before calling the method in the collision manager it will check the 2 objects Z as a buffer. If they do not collide along the z-axis then they don't need to be tested at all. Collisions will be tested against the player's and enemies future position, based off of their velocity, not off of there current one.
    • This will test player collision first, but only if its in demon form.
      • First it will test the player's bounding box against all the color map tiles. If any checks return true then it will see if the player is on a walkable area. If not it will have the player stop.
      • Next it will test the player's bounding box against all the level objects bounding boxes. If any checks return true it will stop the player.
    • Next it will test enemies collision
      • For each enemy alive it will do the same tests that the player did first.
      • After those checks the enemies abilities will get checked. For each one that has been used:
        • It will test the abilities bounding box/ray against the players bounding box and each enemies bounding box.
        • For any that return true the player/enemy will get damaged by that ability and will have any debuffs that are tied to that ability applied to them.
        • It will then test the abilities against the level objects. If it hits ones that you can collide with then they will be set to not used so that for example, a bullet doesn't hit an enemy that was safely behind a wall.
  • SelectEnemy
    • This method will be used by the GameManager to get the correct enemy that should be targeted. This will work by getting in a position(of the player) and a direction(that the thumbstick was pressed in).
    • If the direction passed in is up or down, then it will loop through all the enemies and for ones that are currently alive, it will find the one that has the Y value that is both up/down from the Y position passed in, and closest to it. If there is a tie then then the X position will be taken into account. The enemy that is found will be returned, and null will be returned if there is no enemy in that direction.
    • If the direction passed in is right or left then the same process will be used except the X position will be used first, with the Y value being the tie breaker.

Other Notes

How LevelSections Work

When the Loader loads in the xml file the first thing it will do is make all of the LevelSection structs. In the file there will be tags for each LevelSection and inside each the bounding box, enemies, obstacles, checkpoints, objects, tiles, camera stopping points, and level dialogue will be defined. The Loader will make the LevelSections from all of this information. When it is done, it will send them to the GameManager, which will then send them here to be stored in the sections list.

When this class receives the sections it will pass them into the pool manager so that it can pool all the resources for a level. It will do this by looping through the list of level sections. For each level section it will loop through the enemies and obstacles in the level. For enemies it will keep a count of how many times each type of enemy appears in each section. After looping through all the sections the pool will have the most amount of times every enemy will appear at one time in a section and it will make that many enemies. For obstacles it will keep track of the most amount of obstacles that are in a single section, and at the end will make the minimum number of LevelObjects needed.

To access these enemies and level objects there are two methods, one for each. For enemies there is a GetEnemy method. You pass in a enemy type and it finds an enemy that is of that type and whose isActive property is false, then returns it. For LevelObjects it loops through the level objects list and finds one whose isActive property is false and returns it.

Transitioning between level sections will be done with the level sections bounding box and the player's position. The previous section, if the current section is not the first one, will be checked first. Then the next section in the list, if the current one isn't the last one, will be checked. If the player has entered either of these sections the currentSection will get updated. When the transition happens the level manager will loop through the sections enemies and level objects and update the in-active ones in the pool manager to set up this sections enemies and objects.

How saving and retrying after gameovers work

Saving: In Update, after updating the boss it will check if the boss is alive or not. If the boss has died then its time for the next level. This will call the SaveGame method in the Loader passing in an int representing the number of the next level after the current one, and then call the ChangeState method in Window passing in the Loading state so that the next level will get loaded.

Retrying: At the start of update there will be a check to see if the player is active(alive). If not, then there is a gameover and the GameOver method will get called. This method will set everything in the pool manager to inactive so that the level can be repopulated when it gets restarted. This will set the player's position to the last checkpoint, this is done by doing sections[lastCheckPoint].checkpoint. Then the current section gets set to lastCheckPoint (which represents the index of the section which the last checkpoint occurred in). Finally the player is set to active and the level gets repopulated. The state gets switched to gameover in the player's Death method so after this the gameover screen comes up. If the player chooses to retry then it goes back to gameplay and the player is already in the right spot and the level is already populated.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License