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:
Wed May 13 10:19:10 2020 +0000
Revision:
15:598baed15751
Parent:
13:3b2a4e14937b
Fixed catch ghosts only needing one side lined up

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el18gs 13:3b2a4e14937b 1 #include "gameEngine.h"
el18gs 13:3b2a4e14937b 2
el18gs 13:3b2a4e14937b 3 gameEngine::gameEngine(SDFileSystem &sd, Gamepad &pad, N5110 &lcd)
el18gs 13:3b2a4e14937b 4 {
el18gs 13:3b2a4e14937b 5 #ifdef DEBUG
el18gs 13:3b2a4e14937b 6 printf("Initialising game\n");
el18gs 13:3b2a4e14937b 7 #endif
el18gs 13:3b2a4e14937b 8
el18gs 13:3b2a4e14937b 9 #ifdef DEBUG
el18gs 13:3b2a4e14937b 10 printf("Intialising gamepad\n");
el18gs 13:3b2a4e14937b 11 #endif
el18gs 13:3b2a4e14937b 12 pad.init();
el18gs 13:3b2a4e14937b 13
el18gs 13:3b2a4e14937b 14 #ifdef DEBUG
el18gs 13:3b2a4e14937b 15 printf("Mounting SD card\n");
el18gs 13:3b2a4e14937b 16 #endif
el18gs 13:3b2a4e14937b 17 sd.mount(); // Mount the SD card
el18gs 13:3b2a4e14937b 18
el18gs 13:3b2a4e14937b 19 #ifdef DEBUG
el18gs 13:3b2a4e14937b 20 printf("Initialising LCD\n");
el18gs 13:3b2a4e14937b 21 #endif
el18gs 13:3b2a4e14937b 22 lcd.init(); // Initialise the screen
el18gs 13:3b2a4e14937b 23 lcd.backLightOn(); // Turn the LCD backlight on
el18gs 13:3b2a4e14937b 24 }
el18gs 13:3b2a4e14937b 25
el18gs 13:3b2a4e14937b 26 void gameEngine::welcome(SDFileSystem &sd, N5110 &lcd, Gamepad &pad, volatile int &g_buttonA_flag)
el18gs 13:3b2a4e14937b 27 {
el18gs 13:3b2a4e14937b 28 #ifdef DEBUG
el18gs 13:3b2a4e14937b 29 printf("Entered welcome screen\n");
el18gs 13:3b2a4e14937b 30 #endif
el18gs 13:3b2a4e14937b 31 int** welcome = import_sprite("/sd/assets/welcome.sprite", sd); // importing welcome sprite
el18gs 13:3b2a4e14937b 32 lcd.clear(); // clear the LCD and display the sprite
el18gs 13:3b2a4e14937b 33 for(int i = 0; i < 48; i++) {
el18gs 13:3b2a4e14937b 34 for(int j = 0; j < 84; j++) {
el18gs 13:3b2a4e14937b 35 lcd.setPixel(j,i, welcome[i][j]);
el18gs 13:3b2a4e14937b 36 }
el18gs 13:3b2a4e14937b 37 }
el18gs 13:3b2a4e14937b 38
el18gs 13:3b2a4e14937b 39 while(!g_buttonA_flag) {
el18gs 13:3b2a4e14937b 40 // User can set contrast before continuing, contrast should be bounded between 4 and 6
el18gs 13:3b2a4e14937b 41 lcd.setContrast(0.4 + ((double) pad.read_pot1()/5));
el18gs 13:3b2a4e14937b 42 lcd.refresh();
el18gs 13:3b2a4e14937b 43 wait_ms(10);
el18gs 13:3b2a4e14937b 44 }
el18gs 13:3b2a4e14937b 45 g_buttonA_flag = 0; // Once the flags been detected set it back to 0
el18gs 13:3b2a4e14937b 46 }
el18gs 13:3b2a4e14937b 47
el18gs 13:3b2a4e14937b 48
el18gs 13:3b2a4e14937b 49 int gameEngine::game_menu(N5110 &lcd, volatile int &g_buttonA_flag, volatile int &g_buttonB_flag, volatile int &g_buttonX_flag)
el18gs 13:3b2a4e14937b 50 {
el18gs 13:3b2a4e14937b 51 #ifdef DEBUG
el18gs 13:3b2a4e14937b 52 printf("entered game menu\n");
el18gs 13:3b2a4e14937b 53 #endif
el18gs 13:3b2a4e14937b 54 g_buttonA_flag = 0, g_buttonB_flag = 0, g_buttonX_flag = 0;
el18gs 13:3b2a4e14937b 55 int current_state = 0; // Set the current selected option to Catch Ghosts
el18gs 13:3b2a4e14937b 56
el18gs 13:3b2a4e14937b 57 while(1) {
el18gs 13:3b2a4e14937b 58 lcd.clear();
el18gs 13:3b2a4e14937b 59 lcd.printString("Catch Ghosts",0,0);
el18gs 13:3b2a4e14937b 60 lcd.printString("Inventory",0,2);
el18gs 13:3b2a4e14937b 61 lcd.printString("Settings",0,4);
el18gs 13:3b2a4e14937b 62
el18gs 13:3b2a4e14937b 63 if(g_buttonA_flag) {
el18gs 13:3b2a4e14937b 64 g_buttonA_flag = 0;
el18gs 13:3b2a4e14937b 65 return current_state;
el18gs 13:3b2a4e14937b 66 }
el18gs 13:3b2a4e14937b 67
el18gs 13:3b2a4e14937b 68 if(g_buttonX_flag) {
el18gs 13:3b2a4e14937b 69 current_state = mainMenuFsm[current_state].nextState[0];
el18gs 13:3b2a4e14937b 70 } else if(g_buttonB_flag) {
el18gs 13:3b2a4e14937b 71 current_state = mainMenuFsm[current_state].nextState[1];
el18gs 13:3b2a4e14937b 72 }
el18gs 13:3b2a4e14937b 73 g_buttonA_flag = 0, g_buttonB_flag = 0, g_buttonX_flag = 0;
el18gs 13:3b2a4e14937b 74
el18gs 13:3b2a4e14937b 75 switch (mainMenuFsm[current_state].output) {
el18gs 13:3b2a4e14937b 76 case 0:
el18gs 13:3b2a4e14937b 77 lcd.drawCircle(79, 3, 3, FILL_BLACK);
el18gs 13:3b2a4e14937b 78 break;
el18gs 13:3b2a4e14937b 79 case 2:
el18gs 13:3b2a4e14937b 80 lcd.drawCircle(79, 20, 3, FILL_BLACK);
el18gs 13:3b2a4e14937b 81 break;
el18gs 13:3b2a4e14937b 82 case 4:
el18gs 13:3b2a4e14937b 83 lcd.drawCircle(79, 35, 3, FILL_BLACK);
el18gs 13:3b2a4e14937b 84 break;
el18gs 13:3b2a4e14937b 85 }
el18gs 13:3b2a4e14937b 86 lcd.refresh();
el18gs 13:3b2a4e14937b 87 }
el18gs 13:3b2a4e14937b 88 }
el18gs 13:3b2a4e14937b 89
el18gs 13:3b2a4e14937b 90 void gameEngine::catch_ghosts(Inventory &inventory, FX0S8700CQ &accel, SDFileSystem &sd, N5110 &lcd, Gamepad &pad, volatile int &g_buttonA_flag, BusOut &left_LED, BusOut &right_LED)
el18gs 13:3b2a4e14937b 91 {
el18gs 13:3b2a4e14937b 92 ghostCatchTrial(accel, lcd, sd, pad,left_LED, right_LED, g_buttonA_flag);
el18gs 13:3b2a4e14937b 93
el18gs 13:3b2a4e14937b 94 Ghost caught_ghost(rand()%100, rand()%20, "/ghosts/", sd);
el18gs 13:3b2a4e14937b 95 caught_ghost.save(sd);
el18gs 13:3b2a4e14937b 96
el18gs 13:3b2a4e14937b 97 lcd.clear();
el18gs 13:3b2a4e14937b 98 lcd.printString("You caught:", 0, 0);
el18gs 13:3b2a4e14937b 99 lcd.printString(caught_ghost.get_type_string().c_str(), 0, 1);
el18gs 13:3b2a4e14937b 100 lcd.printString("Press A to", 0, 2);
el18gs 13:3b2a4e14937b 101 lcd.printString("continue", 0, 3);
el18gs 13:3b2a4e14937b 102 lcd.refresh();
el18gs 13:3b2a4e14937b 103
el18gs 13:3b2a4e14937b 104 g_buttonA_flag = 0;
el18gs 13:3b2a4e14937b 105 while(!g_buttonA_flag) {
el18gs 13:3b2a4e14937b 106 }
el18gs 13:3b2a4e14937b 107 g_buttonA_flag = 0;
el18gs 13:3b2a4e14937b 108
el18gs 13:3b2a4e14937b 109 inventory.regen(sd);
el18gs 13:3b2a4e14937b 110 }
el18gs 13:3b2a4e14937b 111
el18gs 13:3b2a4e14937b 112 void gameEngine::ghostCatchTrial(FX0S8700CQ &accel, N5110 &lcd, SDFileSystem &sd, Gamepad &pad, BusOut &left_LED, BusOut &right_LED, volatile int &g_buttonA_flag)
el18gs 13:3b2a4e14937b 113 {
el18gs 13:3b2a4e14937b 114 // Display instructions
el18gs 13:3b2a4e14937b 115 lcd.clear();
el18gs 13:3b2a4e14937b 116 lcd.printString("Align the",18,0);
el18gs 13:3b2a4e14937b 117 lcd.printString("Gamepad until",4,1);
el18gs 13:3b2a4e14937b 118 lcd.printString("all LEDs",20,2);
el18gs 13:3b2a4e14937b 119 lcd.printString("turn on",22,3);
el18gs 13:3b2a4e14937b 120 lcd.refresh();
el18gs 13:3b2a4e14937b 121
el18gs 13:3b2a4e14937b 122 // Detect whn the pad is in the right orientation
el18gs 13:3b2a4e14937b 123 angleDetectionTechnicalSub(accel, left_LED, right_LED);
el18gs 13:3b2a4e14937b 124
el18gs 13:3b2a4e14937b 125 // Import the ghost and generate its starting location
el18gs 13:3b2a4e14937b 126 Vector2D ideal = {rand() % 85,rand() % 49};
el18gs 13:3b2a4e14937b 127 int** ghost = import_sprite("/sd/assets/ghost.sprite", sd);
el18gs 13:3b2a4e14937b 128
el18gs 13:3b2a4e14937b 129 // Loop until the ghost has been caught
el18gs 13:3b2a4e14937b 130 while(1) {
el18gs 13:3b2a4e14937b 131 if (drawCrosshairs(ideal, ghost, lcd, pad, g_buttonA_flag)) {
el18gs 13:3b2a4e14937b 132 return;
el18gs 13:3b2a4e14937b 133 } else {
el18gs 13:3b2a4e14937b 134 randomMove(ideal);
el18gs 13:3b2a4e14937b 135 }
el18gs 13:3b2a4e14937b 136 }
el18gs 13:3b2a4e14937b 137 }
el18gs 13:3b2a4e14937b 138
el18gs 13:3b2a4e14937b 139 // Sub routine that manages the technical side of the angle detection part of ghost catching
el18gs 13:3b2a4e14937b 140 void gameEngine::angleDetectionTechnicalSub(FX0S8700CQ &accel, BusOut &left_LED, BusOut &right_LED)
el18gs 13:3b2a4e14937b 141 {
el18gs 13:3b2a4e14937b 142 // Generate a random target angle and set the counter to 0
el18gs 13:3b2a4e14937b 143 float pitch = rand() % 46;
el18gs 13:3b2a4e14937b 144 if(rand() & 1) {
el18gs 13:3b2a4e14937b 145 pitch = pitch * -1;
el18gs 13:3b2a4e14937b 146 }
el18gs 13:3b2a4e14937b 147 float roll = rand() % 46;
el18gs 13:3b2a4e14937b 148 if(rand() & 1) {
el18gs 13:3b2a4e14937b 149 roll = roll * -1;
el18gs 13:3b2a4e14937b 150 }
el18gs 13:3b2a4e14937b 151 int counter = 0;
el18gs 13:3b2a4e14937b 152
el18gs 13:3b2a4e14937b 153 while(counter < 250) { // loop forever (until intentionally broken)
el18gs 13:3b2a4e14937b 154 accel.read_data(); // Read data from the accelerometer and assume the pad's off
el18gs 15:598baed15751 155 bool focused = true;
el18gs 13:3b2a4e14937b 156
el18gs 13:3b2a4e14937b 157 // Check if the pad is pointing in the right direction, light up LEDs to indicate proximity
el18gs 13:3b2a4e14937b 158 if((double)accel.sensor.roll/roll > 0.75) {
el18gs 13:3b2a4e14937b 159 left_LED = 0b000;
el18gs 13:3b2a4e14937b 160 } else if ((double)accel.sensor.roll/roll > 0.3) {
el18gs 13:3b2a4e14937b 161 left_LED = 0b001;
el18gs 15:598baed15751 162 focused = false;
el18gs 13:3b2a4e14937b 163 } else {
el18gs 13:3b2a4e14937b 164 left_LED = 0b011;
el18gs 15:598baed15751 165 focused = false;
el18gs 13:3b2a4e14937b 166 }
el18gs 13:3b2a4e14937b 167 if((double)accel.sensor.pitch/pitch > 0.75) {
el18gs 13:3b2a4e14937b 168 right_LED = 0b000;
el18gs 13:3b2a4e14937b 169 } else if ((double)accel.sensor.pitch/pitch > 0.3) {
el18gs 13:3b2a4e14937b 170 right_LED = 0b001;
el18gs 15:598baed15751 171 focused = false;
el18gs 13:3b2a4e14937b 172 } else {
el18gs 13:3b2a4e14937b 173 right_LED = 0b011;
el18gs 15:598baed15751 174 focused = false;
el18gs 13:3b2a4e14937b 175 }
el18gs 13:3b2a4e14937b 176
el18gs 13:3b2a4e14937b 177 // Increment the counter
el18gs 13:3b2a4e14937b 178 if(focused) {
el18gs 13:3b2a4e14937b 179 counter++;
el18gs 13:3b2a4e14937b 180 }
el18gs 13:3b2a4e14937b 181 wait_ms(10);
el18gs 13:3b2a4e14937b 182 }
el18gs 13:3b2a4e14937b 183 }
el18gs 13:3b2a4e14937b 184
el18gs 13:3b2a4e14937b 185 bool gameEngine::drawCrosshairs(Vector2D ideal, int** ghost, N5110 &lcd, Gamepad &pad, volatile int g_buttonA_flag)
el18gs 13:3b2a4e14937b 186 {
el18gs 13:3b2a4e14937b 187 lcd.clear(); // Clear the LCD
el18gs 13:3b2a4e14937b 188 // Get the position of the joystick
el18gs 13:3b2a4e14937b 189 Vector2D actual = {cursor_transform(1, -1, 84, 0, pad.get_coord().x),
el18gs 13:3b2a4e14937b 190 cursor_transform(1, -1, 48, 0, pad.get_coord().y * -1)
el18gs 13:3b2a4e14937b 191 };
el18gs 13:3b2a4e14937b 192
el18gs 13:3b2a4e14937b 193 printf("X: %f, Y: %f\n", pad.get_coord().x, pad.get_coord().y);
el18gs 13:3b2a4e14937b 194
el18gs 13:3b2a4e14937b 195 // Draw the crosshairs (x0 y0 x1 y1 type)
el18gs 13:3b2a4e14937b 196 lcd.drawLine(actual.x, 0, actual.x, 48, 2);
el18gs 13:3b2a4e14937b 197 lcd.drawLine(0, actual.y, 84, actual.y, 2);
el18gs 13:3b2a4e14937b 198
el18gs 13:3b2a4e14937b 199 int col = 0;
el18gs 13:3b2a4e14937b 200 for(int i = ideal.x - 8; i < ideal.x + 8; i++) { // Iterate Columns: x
el18gs 13:3b2a4e14937b 201 int row = 0;
el18gs 13:3b2a4e14937b 202 for(int j = ideal.y - 9; j < ideal.y + 9; j++) { // Iterate Rows: y
el18gs 13:3b2a4e14937b 203 lcd.setPixel(i,j, ghost[row][col]);
el18gs 13:3b2a4e14937b 204 row++;
el18gs 13:3b2a4e14937b 205 }
el18gs 13:3b2a4e14937b 206 col++;
el18gs 13:3b2a4e14937b 207 }
el18gs 13:3b2a4e14937b 208
el18gs 13:3b2a4e14937b 209 if(ghostHit(ideal.x, ideal.y, actual.x, actual.y)) {
el18gs 13:3b2a4e14937b 210 lcd.printString("Press A!",0,0);
el18gs 13:3b2a4e14937b 211 if(g_buttonA_flag) {
el18gs 13:3b2a4e14937b 212 g_buttonA_flag = 0;
el18gs 13:3b2a4e14937b 213 return true;
el18gs 13:3b2a4e14937b 214 }
el18gs 13:3b2a4e14937b 215 }
el18gs 13:3b2a4e14937b 216
el18gs 13:3b2a4e14937b 217 g_buttonA_flag = 0;
el18gs 13:3b2a4e14937b 218 lcd.refresh();
el18gs 13:3b2a4e14937b 219 return false;
el18gs 13:3b2a4e14937b 220 }
el18gs 13:3b2a4e14937b 221
el18gs 13:3b2a4e14937b 222 void gameEngine::randomMove(Vector2D &ideal)
el18gs 13:3b2a4e14937b 223 {
el18gs 13:3b2a4e14937b 224 int x_move = 0;
el18gs 13:3b2a4e14937b 225 int y_move = 0;
el18gs 13:3b2a4e14937b 226 if(rand() & 1) {
el18gs 13:3b2a4e14937b 227 x_move = 1;
el18gs 13:3b2a4e14937b 228 } else {
el18gs 13:3b2a4e14937b 229 x_move = -1;
el18gs 13:3b2a4e14937b 230 }
el18gs 13:3b2a4e14937b 231 if(rand() & 1) {
el18gs 13:3b2a4e14937b 232 y_move = 1;
el18gs 13:3b2a4e14937b 233 } else {
el18gs 13:3b2a4e14937b 234 y_move = -1;
el18gs 13:3b2a4e14937b 235 }
el18gs 13:3b2a4e14937b 236
el18gs 13:3b2a4e14937b 237 ideal.x = ideal.x + x_move;
el18gs 13:3b2a4e14937b 238 ideal.y = ideal.y + y_move;
el18gs 13:3b2a4e14937b 239
el18gs 13:3b2a4e14937b 240 if(ideal.x > 70) {
el18gs 13:3b2a4e14937b 241 ideal.x = 70;
el18gs 13:3b2a4e14937b 242 } else if(ideal.x < 13) {
el18gs 13:3b2a4e14937b 243 ideal.x = 13;
el18gs 13:3b2a4e14937b 244 }
el18gs 13:3b2a4e14937b 245 if(ideal.y > 30) {
el18gs 13:3b2a4e14937b 246 ideal.y = 30;
el18gs 13:3b2a4e14937b 247 } else if(ideal.y < 12) {
el18gs 13:3b2a4e14937b 248 ideal.y = 12;
el18gs 13:3b2a4e14937b 249 }
el18gs 13:3b2a4e14937b 250 }
el18gs 13:3b2a4e14937b 251
el18gs 13:3b2a4e14937b 252 bool gameEngine::ghostHit( int xGhost, int yGhost, int xJoy, int yJoy)
el18gs 13:3b2a4e14937b 253 {
el18gs 13:3b2a4e14937b 254 int xDifference = abs(xGhost - xJoy);
el18gs 13:3b2a4e14937b 255 int yDifference = abs(yGhost - yJoy);
el18gs 13:3b2a4e14937b 256
el18gs 13:3b2a4e14937b 257 if(xDifference < 10 && yDifference <10) {
el18gs 13:3b2a4e14937b 258 return true;
el18gs 13:3b2a4e14937b 259 } else {
el18gs 13:3b2a4e14937b 260 return false;
el18gs 13:3b2a4e14937b 261 }
el18gs 13:3b2a4e14937b 262 }
el18gs 13:3b2a4e14937b 263
el18gs 13:3b2a4e14937b 264 void gameEngine::settings(N5110 &lcd, Gamepad &pad, volatile int &g_buttonA_flag, volatile int &g_buttonStart_flag, volatile int &g_buttonX_flag, volatile int &g_buttonB_flag,
el18gs 13:3b2a4e14937b 265 volatile bool &g_buttonTesting,
el18gs 13:3b2a4e14937b 266 volatile int &g_buttonSensitivityTest,
el18gs 13:3b2a4e14937b 267 volatile int &g_buttonSensitivity)
el18gs 13:3b2a4e14937b 268 {
el18gs 13:3b2a4e14937b 269 #ifdef DEBUG
el18gs 13:3b2a4e14937b 270 printf("entered game menu\n");
el18gs 13:3b2a4e14937b 271 #endif
el18gs 13:3b2a4e14937b 272 // Set the default state to 0 and zero all the interrupt flags
el18gs 13:3b2a4e14937b 273 int current_state = 0;
el18gs 13:3b2a4e14937b 274 g_buttonA_flag = 0, g_buttonStart_flag = 0, g_buttonX_flag = 0, g_buttonB_flag = 0;
el18gs 13:3b2a4e14937b 275
el18gs 13:3b2a4e14937b 276 // Loop until one of the sub menus is entered
el18gs 13:3b2a4e14937b 277 while(1) {
el18gs 13:3b2a4e14937b 278 lcd.clear(); // Clear the display and print the options
el18gs 13:3b2a4e14937b 279 lcd.printString("Settings",0,0);
el18gs 13:3b2a4e14937b 280 lcd.printString("Contrast",0,2);
el18gs 13:3b2a4e14937b 281 lcd.printString("Button delay",0,4);
el18gs 13:3b2a4e14937b 282
el18gs 13:3b2a4e14937b 283 // Decide what to do depending on what flags are high, zero all flags after
el18gs 13:3b2a4e14937b 284 if(g_buttonA_flag) { // If the A enter the selected sub menu
el18gs 13:3b2a4e14937b 285 g_buttonA_flag = 0;
el18gs 13:3b2a4e14937b 286 switch (settingsFsm[current_state].output) {
el18gs 13:3b2a4e14937b 287 case 2:
el18gs 13:3b2a4e14937b 288 adjustContrast(lcd, pad, g_buttonA_flag);
el18gs 13:3b2a4e14937b 289 break;
el18gs 13:3b2a4e14937b 290 case 4:
el18gs 13:3b2a4e14937b 291 buttonDelay(lcd, pad, g_buttonA_flag, g_buttonX_flag, g_buttonTesting, g_buttonSensitivityTest, g_buttonSensitivity);
el18gs 13:3b2a4e14937b 292 break;
el18gs 13:3b2a4e14937b 293 }
el18gs 13:3b2a4e14937b 294 } else if (g_buttonStart_flag) { // If Start return to the main menu
el18gs 13:3b2a4e14937b 295 g_buttonStart_flag = 0;
el18gs 13:3b2a4e14937b 296 return;
el18gs 13:3b2a4e14937b 297 } else if(g_buttonX_flag) { // If X go up one option
el18gs 13:3b2a4e14937b 298 current_state = settingsFsm[current_state].nextState[0];
el18gs 13:3b2a4e14937b 299 } else if(g_buttonB_flag) { // If B go down one option
el18gs 13:3b2a4e14937b 300 current_state = settingsFsm[current_state].nextState[1];
el18gs 13:3b2a4e14937b 301 }
el18gs 13:3b2a4e14937b 302 g_buttonA_flag = 0, g_buttonStart_flag = 0, g_buttonX_flag = 0, g_buttonB_flag = 0;
el18gs 13:3b2a4e14937b 303
el18gs 13:3b2a4e14937b 304 // Display a circle on the correct line
el18gs 13:3b2a4e14937b 305 switch (settingsFsm[current_state].output) {
el18gs 13:3b2a4e14937b 306 case 2:
el18gs 13:3b2a4e14937b 307 lcd.drawCircle(79, 20, 3, FILL_BLACK);
el18gs 13:3b2a4e14937b 308 break;
el18gs 13:3b2a4e14937b 309 case 4:
el18gs 13:3b2a4e14937b 310 lcd.drawCircle(79, 35, 3, FILL_BLACK);
el18gs 13:3b2a4e14937b 311 break;
el18gs 13:3b2a4e14937b 312 }
el18gs 13:3b2a4e14937b 313 lcd.refresh();
el18gs 13:3b2a4e14937b 314 }
el18gs 13:3b2a4e14937b 315 }
el18gs 13:3b2a4e14937b 316
el18gs 13:3b2a4e14937b 317 void gameEngine::adjustContrast(N5110 &lcd, Gamepad &pad, volatile int &g_buttonA_flag)
el18gs 13:3b2a4e14937b 318 {
el18gs 13:3b2a4e14937b 319 while(1) {
el18gs 13:3b2a4e14937b 320 lcd.clear();
el18gs 13:3b2a4e14937b 321 lcd.printString("Contrast", 0, 0);
el18gs 13:3b2a4e14937b 322 lcd.printString("Press A to set", 0, 3);
el18gs 13:3b2a4e14937b 323
el18gs 13:3b2a4e14937b 324 float conSet = 0.4 + ((double) pad.read_pot1()/5);
el18gs 13:3b2a4e14937b 325 float bar = cursor_transform(0.6,0.4,64,0,conSet);
el18gs 13:3b2a4e14937b 326
el18gs 13:3b2a4e14937b 327 lcd.drawRect(10,10,74,10,FILL_TRANSPARENT); // transparent, just outline
el18gs 13:3b2a4e14937b 328 lcd.drawRect(10,10,bar,10,FILL_BLACK); // filled black rectangle
el18gs 13:3b2a4e14937b 329 lcd.setContrast(conSet);
el18gs 13:3b2a4e14937b 330
el18gs 13:3b2a4e14937b 331 if(g_buttonA_flag) {
el18gs 13:3b2a4e14937b 332 g_buttonA_flag = 0;
el18gs 13:3b2a4e14937b 333 return;
el18gs 13:3b2a4e14937b 334 }
el18gs 13:3b2a4e14937b 335
el18gs 13:3b2a4e14937b 336 lcd.refresh();
el18gs 13:3b2a4e14937b 337 }
el18gs 13:3b2a4e14937b 338 }
el18gs 13:3b2a4e14937b 339
el18gs 13:3b2a4e14937b 340 void gameEngine::buttonDelay(N5110 &lcd,
el18gs 13:3b2a4e14937b 341 Gamepad &pad,
el18gs 13:3b2a4e14937b 342 volatile int &g_buttonA_flag,
el18gs 13:3b2a4e14937b 343 volatile int &g_buttonX_flag,
el18gs 13:3b2a4e14937b 344 volatile bool &g_buttonTesting,
el18gs 13:3b2a4e14937b 345 volatile int &g_buttonSensitivityTest,
el18gs 13:3b2a4e14937b 346 volatile int &g_buttonSensitivity)
el18gs 13:3b2a4e14937b 347 {
el18gs 13:3b2a4e14937b 348 // Tell the X button that test mode is on, initially start with an empty circle
el18gs 13:3b2a4e14937b 349 g_buttonTesting = true;
el18gs 13:3b2a4e14937b 350 bool trialCircle = false;
el18gs 13:3b2a4e14937b 351
el18gs 13:3b2a4e14937b 352 while(1) {
el18gs 13:3b2a4e14937b 353 lcd.clear();
el18gs 13:3b2a4e14937b 354 lcd.printString("Button Delay", 0, 0);
el18gs 13:3b2a4e14937b 355 lcd.printString("Press X to test", 0, 4);
el18gs 13:3b2a4e14937b 356 lcd.printString("Press A to set", 0, 5);
el18gs 13:3b2a4e14937b 357
el18gs 13:3b2a4e14937b 358 // Calculate the length of the bar
el18gs 13:3b2a4e14937b 359 g_buttonSensitivityTest = cursor_transform(1,0,2,0,pad.read_pot1()) * 250;
el18gs 13:3b2a4e14937b 360 int bar = cursor_transform(500,0,64,0,g_buttonSensitivityTest);
el18gs 13:3b2a4e14937b 361
el18gs 13:3b2a4e14937b 362 // example of how to draw rectangles
el18gs 13:3b2a4e14937b 363 // origin x,y,width,height,type
el18gs 13:3b2a4e14937b 364 lcd.drawRect(10,10,74,10,FILL_TRANSPARENT); // transparent, just outline
el18gs 13:3b2a4e14937b 365 lcd.drawRect(10,10,bar,10,FILL_BLACK); // filled black rectangle
el18gs 13:3b2a4e14937b 366
el18gs 13:3b2a4e14937b 367 if(trialCircle) {
el18gs 13:3b2a4e14937b 368 lcd.drawCircle(42, 25, 3, FILL_BLACK);
el18gs 13:3b2a4e14937b 369 } else {
el18gs 13:3b2a4e14937b 370 lcd.drawCircle(42, 25, 3, FILL_TRANSPARENT);
el18gs 13:3b2a4e14937b 371 }
el18gs 13:3b2a4e14937b 372
el18gs 13:3b2a4e14937b 373 if(g_buttonX_flag) {
el18gs 13:3b2a4e14937b 374 g_buttonX_flag = 0;
el18gs 13:3b2a4e14937b 375 trialCircle = !trialCircle;
el18gs 13:3b2a4e14937b 376 } else if(g_buttonA_flag) {
el18gs 13:3b2a4e14937b 377 g_buttonA_flag = 0;
el18gs 13:3b2a4e14937b 378 g_buttonSensitivity = g_buttonSensitivityTest;
el18gs 13:3b2a4e14937b 379 g_buttonTesting = false;
el18gs 13:3b2a4e14937b 380 return;
el18gs 13:3b2a4e14937b 381 }
el18gs 13:3b2a4e14937b 382
el18gs 13:3b2a4e14937b 383 // Refresh the screen so its up to date
el18gs 13:3b2a4e14937b 384 lcd.refresh();
el18gs 13:3b2a4e14937b 385 }
el18gs 13:3b2a4e14937b 386 }