Portfolio


  • Home
  • DirectX Raytracing
  • Advanced Graphics
  • Roboflux
  • Boat Simulation

Pacman



The project



I created this project for a module in my first year of university using the graphical API S2D. We were tasked with recreating some of the mechanics in Pacman like the wrapping when the player goes around the screen and the munchies. On top of this i decided to add some of my own features like the shop and the fact Pacman can shoot.



The main screen



The main screen of the game has bits distributed across the stream. These are randomly placed and each one gets pacman a certain number of points depending on his score multiplier. There is also 3 basic AI which all act uniquely. One moves from left to right. the other follows the outside edge of the screen and the final AI moves left to right until you come into a certain range. At this point the AI then tries to follow the player until the players out of range again.



Pause menu and shop



The pause menu is drawn last meaning it appears over the top of everything else as this project didn't use any depth buffering. It then pauses everything as all of the animation and movement is scaled using the difference in time between frames meaning if you set it to 0 nothing will move. The buttons were then created by simply drawing sprites over the top and adding rectangle colliders.


The shop screen functions in a similar way to the pause menu as it sets the difference in time to 0. All the elements are again drawn over the top of the Pacman game. This is an ineffective way of doing it but since the game is simple and not resource heavy this isn't an issue. When the user first opens the shop it parses a file and illuminates the correct number of lights. When the user then buys an upgrade the file is updated. The price of each upgrade is also calculated depending on the number of upgrades you have purchased.



Object pools and animation



In order to make this game more efficient I decided to use object pools. This means you don't have to keep creating objects and instead store the objects off screen where they won't be rendered or updated. This was done with the munchies and Pacman's bullets.


The animations are implemented using basic spritesheets. In order to do this I created a sprite a rectangle which is the width and height of one frame on the spritesheet. This rectangle then moves position every set amount of time in order to display the next frame. Once this rectangle hits the end of the spritesheet it's then reset and starts again.



Gameover screen



When the user reaches the gameover screen the previous 5 high scores are displayed. These are loaded from a file and updated depending on if the user has beat any of the high scores. The total currency the user has collected is also updated and written to a file.



AI



The final thing I added to this project was the AI of the different ghosts. One ghost moves left to right. Another follows the outside of the screen. If the screen is resized then this ghost will move left until it hits the edge and continue to follow the edge of the screen. The final ghost patrols horizontally until the player comes within a certain range. It then calculates the difference in vertical and horizontal position. The ghost then moves in the direction of the value which is largest.