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:
Tue May 26 13:37:32 2020 +0000
Revision:
17:3ebcf7bba112
Parent:
13:3b2a4e14937b
Final Submission. I have read and agreed with Statement of Academic Integrity.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el18gs 13:3b2a4e14937b 1 #include "tooling.h"
el18gs 13:3b2a4e14937b 2
el18gs 13:3b2a4e14937b 3 // Function taken from https://stackoverflow.com/a/874160/10436605
el18gs 13:3b2a4e14937b 4 bool hasEnding (std::string const &fullString, std::string const &ending)
el18gs 13:3b2a4e14937b 5 {
el18gs 13:3b2a4e14937b 6 if (fullString.length() >= ending.length()) {
el18gs 13:3b2a4e14937b 7 return (0 == fullString.compare (fullString.length() - ending.length(), ending.length(), ending));
el18gs 13:3b2a4e14937b 8 } else {
el18gs 13:3b2a4e14937b 9 return false;
el18gs 13:3b2a4e14937b 10 }
el18gs 13:3b2a4e14937b 11 }
el18gs 13:3b2a4e14937b 12
el18gs 13:3b2a4e14937b 13 void listdir(std::string path, SDFileSystem &sd)
el18gs 13:3b2a4e14937b 14 {
el18gs 13:3b2a4e14937b 15 printf("Listing directory: %s\n", path.c_str());
el18gs 13:3b2a4e14937b 16 DIR *d;
el18gs 13:3b2a4e14937b 17 struct dirent *p;
el18gs 13:3b2a4e14937b 18
el18gs 13:3b2a4e14937b 19 d = opendir(path.c_str());
el18gs 13:3b2a4e14937b 20 if (d != NULL) {
el18gs 13:3b2a4e14937b 21 while ((p = readdir(d)) != NULL) {
el18gs 13:3b2a4e14937b 22 printf(" - %s\n", p->d_name);
el18gs 13:3b2a4e14937b 23 }
el18gs 13:3b2a4e14937b 24 } else {
el18gs 13:3b2a4e14937b 25 printf("Could not open directory!\n");
el18gs 13:3b2a4e14937b 26 }
el18gs 13:3b2a4e14937b 27 closedir(d);
el18gs 13:3b2a4e14937b 28 }
el18gs 13:3b2a4e14937b 29
el18gs 13:3b2a4e14937b 30 int** import_sprite(std::string file, SDFileSystem &sd)
el18gs 13:3b2a4e14937b 31 {
el18gs 13:3b2a4e14937b 32 FILE *fp; // this is our file pointer
el18gs 13:3b2a4e14937b 33
el18gs 13:3b2a4e14937b 34 // the previous example just read the values into variables and printed to
el18gs 13:3b2a4e14937b 35 // serial, we'll now read files into an array.
el18gs 13:3b2a4e14937b 36
el18gs 13:3b2a4e14937b 37 // now open file for reading...note the 'r'
el18gs 13:3b2a4e14937b 38 fp = fopen(file.c_str(), "r");
el18gs 13:3b2a4e14937b 39
el18gs 13:3b2a4e14937b 40
el18gs 13:3b2a4e14937b 41 int n=0; // going to store the number of lines in the file
el18gs 13:3b2a4e14937b 42 stringvec values;
el18gs 13:3b2a4e14937b 43
el18gs 13:3b2a4e14937b 44 if (fp == NULL) { // if it can't open the file then print error message
el18gs 13:3b2a4e14937b 45 printf("Error! Unable to open file: %s\n", file.c_str());
el18gs 13:3b2a4e14937b 46 listdir("/sd/assets", sd);
el18gs 13:3b2a4e14937b 47 } else {
el18gs 13:3b2a4e14937b 48 //Since we may not know the
el18gs 13:3b2a4e14937b 49 // number of lines in the files ahead of time, we'll first count them
el18gs 13:3b2a4e14937b 50 // * means scan but don't save
el18gs 13:3b2a4e14937b 51 int max_len_tmp = 0;
el18gs 13:3b2a4e14937b 52 int max_len = 0;
el18gs 13:3b2a4e14937b 53
el18gs 13:3b2a4e14937b 54 while (fscanf(fp, "%*i%n", &max_len_tmp) != EOF) {
el18gs 13:3b2a4e14937b 55 n++; // increment counter when read a line
el18gs 13:3b2a4e14937b 56 if(max_len_tmp > max_len) {
el18gs 13:3b2a4e14937b 57 max_len = max_len_tmp;
el18gs 13:3b2a4e14937b 58 }
el18gs 13:3b2a4e14937b 59 }
el18gs 13:3b2a4e14937b 60
el18gs 13:3b2a4e14937b 61 max_len--;
el18gs 13:3b2a4e14937b 62
el18gs 13:3b2a4e14937b 63 rewind(fp); // 'scrolled' to end of file, so go back to beginning
el18gs 13:3b2a4e14937b 64
el18gs 13:3b2a4e14937b 65 char buffer[n][max_len];
el18gs 13:3b2a4e14937b 66
el18gs 13:3b2a4e14937b 67 for(int i = 0; i < n; i++) {
el18gs 13:3b2a4e14937b 68 fscanf(fp, "%s", &buffer[i][0]);
el18gs 13:3b2a4e14937b 69 }
el18gs 13:3b2a4e14937b 70
el18gs 13:3b2a4e14937b 71 int** sprite = 0;
el18gs 13:3b2a4e14937b 72 sprite = new int*[n];
el18gs 13:3b2a4e14937b 73 for(int i = 0; i < n; i++) {
el18gs 13:3b2a4e14937b 74 sprite[i] = new int[max_len];
el18gs 13:3b2a4e14937b 75 }
el18gs 13:3b2a4e14937b 76
el18gs 13:3b2a4e14937b 77 for(int i = 0; i < n; i++) {
el18gs 13:3b2a4e14937b 78 //printf("%s\n", buffer[i]);
el18gs 13:3b2a4e14937b 79 for(int j = 0; j < max_len; j++) {
el18gs 13:3b2a4e14937b 80 if((int)buffer[i][j] == 48) {
el18gs 13:3b2a4e14937b 81 sprite[i][j] = 0;
el18gs 13:3b2a4e14937b 82 } else if((int) buffer[i][j] == 49) {
el18gs 13:3b2a4e14937b 83 sprite[i][j] = 1;
el18gs 13:3b2a4e14937b 84 }
el18gs 13:3b2a4e14937b 85 }
el18gs 13:3b2a4e14937b 86 }
el18gs 13:3b2a4e14937b 87
el18gs 13:3b2a4e14937b 88 fclose(fp); // ensure you close the file after reading
el18gs 13:3b2a4e14937b 89
el18gs 13:3b2a4e14937b 90 return sprite;
el18gs 13:3b2a4e14937b 91
el18gs 13:3b2a4e14937b 92 }
el18gs 13:3b2a4e14937b 93
el18gs 13:3b2a4e14937b 94 return 0;
el18gs 13:3b2a4e14937b 95 }
el18gs 13:3b2a4e14937b 96
el18gs 13:3b2a4e14937b 97 float cursor_transform(float OldMax,
el18gs 13:3b2a4e14937b 98 float OldMin,
el18gs 13:3b2a4e14937b 99 float NewMax,
el18gs 13:3b2a4e14937b 100 float NewMin,
el18gs 13:3b2a4e14937b 101 float OldValue)
el18gs 13:3b2a4e14937b 102 {
el18gs 13:3b2a4e14937b 103 float NewValue = -1;
el18gs 13:3b2a4e14937b 104 float OldRange = (OldMax - OldMin);
el18gs 13:3b2a4e14937b 105 if (OldRange == 0) {
el18gs 13:3b2a4e14937b 106 NewValue = NewMin;
el18gs 13:3b2a4e14937b 107 } else {
el18gs 13:3b2a4e14937b 108 float NewRange = (NewMax - NewMin);
el18gs 13:3b2a4e14937b 109 NewValue = (((OldValue - OldMin) * NewRange) / OldRange) + NewMin;
el18gs 13:3b2a4e14937b 110 }
el18gs 13:3b2a4e14937b 111 return NewValue;
el18gs 13:3b2a4e14937b 112 }