Repository navigation
Implementation
The core of our implementation comes down to an MVC style of architecture. The main driver of the game comes from the GameController, which keeps track of which screen the game is on. These screens are all JPanels, and represent different stages of the game, ie. menus, pause, game-over screen. The JPanels are all part of the GameViewer, which is the main JFrame that displays the visuals of the game. The main screen in the game is the GameScreen. The GameController gets the current room from the GameModel, and passes the GameScreen a list of Sprites. The list of sprites is all the parts of the room that need to be drawn, including walls, floors and mobs. The user interface is also drawn, which is from the class HeadsUpDisplay, which is passed information from the model like the Inventory, and the players health. The most important part is the list of Entities. This is a list of all the objects in the dungeon that can be interacted with, ie. attacks and collisions. For this, the controller runs through all the Entities in the list and checks their position, and whether they are colliding with another object.
It also calls the Entity function update(), which has an override method in specific mob classes to get movement. In the case of the player, the movements are set by arrow keys, and are then used to update the player position. The Rat AI works off a charge - rest system. What happens is that the Rat is passed the Player as a target, and then triangulates its position, and very quickly moves in the players direction. If the rat hits the player, it will attack, but if it misses, it is stunned for a period of time, and doesn't move.
The most complicated AI is the spider. The spider uses a variation of a best path algorithm. It makes use of a function lineOfSight(), which sees if the spider can see the player. It loops through every square of the room, and finds the furthest point from the player where it can still see them. Once it has the best position for it to be, it uses a best path algorithm to find a route from its current position to is optimum position. It also takes into account the player, and will not try and make a path that will cause it to run into the player. The spider has a projectile attack which shoots directly at the player. The spider will only fire if it has line of sight with the player.