George Sykes ELEC2645 project

Dependencies:   mbed

https://os.mbed.com/media/uploads/el18gs/pixil-frame-0.png

GHOST HUNTER

In a world of ghostly horrors there is much money to be made in underground ghost fighting rings. You've managed to get hold of a Ghostbuster, a special piece of equipment that allows you to catch, train and fight ghosts.

Instructions

Below you will find the instructions for the game. Please note that due to COVID-19 a large part of the game (fighting ghosts) could not be added as it would have required access to a second gamepad which i could not acquire.

Welcome screen

When first started you will be presented with a welcome screen

  • Pot 1 to adjust the contrast on the screen
  • Press A to continue.

Main menu

You have three options, catch ghosts (add ghosts to your inventory), inventory (sell ghosts) or settings(adjust the games settings).

  • Press X and B to move the selection up and down respectively
  • Press A to enter the selected submenu

Catch Ghost

Will now be presented with two challenges. In the first you need to find a ghost, in the second you catch it. Theses stages will start automatically.

Find ghost

Rotate the gamepad on its roll and pitch axis until all the LED's turn on. The ones on the left indicate roll and the right pitch.

  • Rotate the gamepad on it roll and pitch to light up the LED's

Catch ghost

Return the gamepad to a comfortable position and use the joystick to move the crosshairs onto the ghost sprite. When ready press the A button to catch the ghost. You will be told what kind of ghost you have captured and it will be added to your inventory.

  • Press A to catch the ghost
  • Move the joystick to move the crosshairs

Inventory

The inventory allows you to view your ghosts and sell them.

  • Use Pot 1 to scroll through the ghosts
  • Pot 2 to scroll up and down the details of the individual ghosts
  • Press X to prepare to sell a ghost and press again to confirm, if you don't press again the sale screen will disappear after 5 seconds
  • Press Start to return to the main menu

Settings

This menu allows you to adjust some of the settings of the game.

  • Press X to go up one option
  • Press B to go down one option
  • Press A to enter the selected submenu
  • Press Start to return to the main menu

Contrast

Set the contrast of the LCD screen, the contrast will adjust on this screen so you can see the effect (contrast is bounded between 0.4 and 0.6).

  • Pot 1 to increase or decrease the contrast
  • Press A to set the contrast

Button Delay

Set the minimum time between button presses; if this is too low the game will detect two button presses when there was only one, too high and the buttons will seem unresponsive. So as to ensure these issues do not occur while changing the setting button X temporarily operates on the new delay but none of the others will until A is pressed.

  • Pot 1 to increase or decrease the delay
  • Press X to test the new delay, this will toggle the small circle to be filled in or unfilled
  • Press A to save the setting
Committer:
el18gs
Date:
Mon May 11 11:58:31 2020 +0000
Revision:
3:9d811414d35e
Child:
8:4220d116f17c
testing docs commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el18gs 3:9d811414d35e 1 #include "Inventory.h"
el18gs 3:9d811414d35e 2
el18gs 3:9d811414d35e 3 Inventory::Inventory(void){
el18gs 3:9d811414d35e 4 printf("creating inventory\n");
el18gs 3:9d811414d35e 5 stringvec ghost_list = list_ghosts("/sd/ghosts");
el18gs 3:9d811414d35e 6
el18gs 3:9d811414d35e 7 for(int i = 0; i < ghost_list.size(); i++){
el18gs 3:9d811414d35e 8
el18gs 3:9d811414d35e 9 std::string path = "/sd/ghosts/";
el18gs 3:9d811414d35e 10 path.append(ghost_list[i]);
el18gs 3:9d811414d35e 11 printf("Path to import '%s'\n", path.c_str());
el18gs 3:9d811414d35e 12
el18gs 3:9d811414d35e 13 Ghost temp(path, "/sd/ghosts/");
el18gs 3:9d811414d35e 14 _ghosts.push_back(temp);
el18gs 3:9d811414d35e 15 }
el18gs 3:9d811414d35e 16 }
el18gs 3:9d811414d35e 17
el18gs 3:9d811414d35e 18 void Inventory::regen(void){
el18gs 3:9d811414d35e 19 printf("Regenerating ghost list\n");
el18gs 3:9d811414d35e 20 _ghosts.clear();
el18gs 3:9d811414d35e 21
el18gs 3:9d811414d35e 22 stringvec ghost_list = list_ghosts("/sd/ghosts");
el18gs 3:9d811414d35e 23
el18gs 3:9d811414d35e 24 for(int i = 0; i < ghost_list.size(); i++){
el18gs 3:9d811414d35e 25
el18gs 3:9d811414d35e 26 std::string path = "/sd/ghosts/";
el18gs 3:9d811414d35e 27 path.append(ghost_list[i]);
el18gs 3:9d811414d35e 28 printf("Path to import '%s'\n", path.c_str());
el18gs 3:9d811414d35e 29
el18gs 3:9d811414d35e 30 Ghost temp(path, "/sd/ghosts/");
el18gs 3:9d811414d35e 31 _ghosts.push_back(temp);
el18gs 3:9d811414d35e 32 }
el18gs 3:9d811414d35e 33
el18gs 3:9d811414d35e 34 //for(int i = 0; i < _ghosts.size(); i++){
el18gs 3:9d811414d35e 35 // _ghosts[i].print_all();
el18gs 3:9d811414d35e 36 //}
el18gs 3:9d811414d35e 37 }
el18gs 3:9d811414d35e 38
el18gs 3:9d811414d35e 39 std::vector<int> Inventory::list_ghost_uids(void){
el18gs 3:9d811414d35e 40 std::vector<int> uids;
el18gs 3:9d811414d35e 41 for(int i = 0; i < _ghosts.size(); i++){
el18gs 3:9d811414d35e 42 uids.push_back(_ghosts[i].get_uid());
el18gs 3:9d811414d35e 43 //printf("Added UID %i to list\n", _ghosts[i].get_uid());
el18gs 3:9d811414d35e 44 }
el18gs 3:9d811414d35e 45
el18gs 3:9d811414d35e 46 return uids;
el18gs 3:9d811414d35e 47 }
el18gs 3:9d811414d35e 48
el18gs 3:9d811414d35e 49 Ghost Inventory::get_ghost_by_uid(int uid){
el18gs 3:9d811414d35e 50 for(int i = 0; i < _ghosts.size(); i++){
el18gs 3:9d811414d35e 51 if(_ghosts[i].get_uid() == uid){
el18gs 3:9d811414d35e 52 return _ghosts[i];
el18gs 3:9d811414d35e 53 }
el18gs 3:9d811414d35e 54 }
el18gs 3:9d811414d35e 55 return _ghosts[0];
el18gs 3:9d811414d35e 56 }
el18gs 3:9d811414d35e 57
el18gs 3:9d811414d35e 58 stringvec Inventory::list_ghosts(std::string path)
el18gs 3:9d811414d35e 59 {
el18gs 3:9d811414d35e 60 // Connections to SD card holder on K64F (SPI interface)
el18gs 3:9d811414d35e 61 SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); // MOSI, MISO, SCK, CS
el18gs 3:9d811414d35e 62 //std::string path = "/sd/ghosts";
el18gs 3:9d811414d35e 63 printf("Checking directory for ghosts: %s\n", path.c_str());
el18gs 3:9d811414d35e 64 DIR *d;
el18gs 3:9d811414d35e 65 struct dirent *p;
el18gs 3:9d811414d35e 66
el18gs 3:9d811414d35e 67 stringvec files;
el18gs 3:9d811414d35e 68
el18gs 3:9d811414d35e 69 d = opendir(path.c_str());
el18gs 3:9d811414d35e 70 if (d != NULL) {
el18gs 3:9d811414d35e 71 while ((p = readdir(d)) != NULL) {
el18gs 3:9d811414d35e 72 files.push_back(p->d_name);
el18gs 3:9d811414d35e 73 }
el18gs 3:9d811414d35e 74 } else {
el18gs 3:9d811414d35e 75 printf("Could not open directory!\n");
el18gs 3:9d811414d35e 76 }
el18gs 3:9d811414d35e 77 closedir(d);
el18gs 3:9d811414d35e 78
el18gs 3:9d811414d35e 79 stringvec correct_files;
el18gs 3:9d811414d35e 80
el18gs 3:9d811414d35e 81 for(int i = 0; i < files.size(); i++){
el18gs 3:9d811414d35e 82 if(hasEnding(files[i], ".ghost")){
el18gs 3:9d811414d35e 83 correct_files.push_back(files[i]);
el18gs 3:9d811414d35e 84 }
el18gs 3:9d811414d35e 85 }
el18gs 3:9d811414d35e 86
el18gs 3:9d811414d35e 87 return correct_files;
el18gs 3:9d811414d35e 88 }
el18gs 3:9d811414d35e 89
el18gs 3:9d811414d35e 90 bool Inventory::hasEnding (std::string const &fullString, std::string const &ending) {
el18gs 3:9d811414d35e 91 if (fullString.length() >= ending.length()) {
el18gs 3:9d811414d35e 92 return (0 == fullString.compare (fullString.length() - ending.length(), ending.length(), ending));
el18gs 3:9d811414d35e 93 } else {
el18gs 3:9d811414d35e 94 return false;
el18gs 3:9d811414d35e 95 }
el18gs 3:9d811414d35e 96 }
el18gs 3:9d811414d35e 97
el18gs 3:9d811414d35e 98 void Inventory::sell_ghost_by_uid(int uid){
el18gs 3:9d811414d35e 99 printf("Inside sell function\n");
el18gs 3:9d811414d35e 100 for(int i = 0; i < _ghosts.size(); i++){
el18gs 3:9d811414d35e 101 if(_ghosts[i].get_uid() == uid){
el18gs 3:9d811414d35e 102 printf("Sale target found\n");
el18gs 3:9d811414d35e 103 int value = _ghosts[i].sell();
el18gs 3:9d811414d35e 104 _ghosts.erase(_ghosts.begin() + i);
el18gs 3:9d811414d35e 105 _gold = _gold + value;
el18gs 3:9d811414d35e 106 break;
el18gs 3:9d811414d35e 107 }
el18gs 3:9d811414d35e 108
el18gs 3:9d811414d35e 109 }
el18gs 3:9d811414d35e 110 }