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:
16:3b298bea3a70
Final Submission. I have read and agreed with Statement of Academic Integrity.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el18gs 3:9d811414d35e 1 #include "Inventory.h"
el18gs 3:9d811414d35e 2
el18gs 16:3b298bea3a70 3 Inventory::Inventory(SDFileSystem &sd)
el18gs 16:3b298bea3a70 4 {
el18gs 3:9d811414d35e 5 printf("creating inventory\n");
el18gs 8:4220d116f17c 6 stringvec ghost_list = list_ghosts("/sd/ghosts", sd);
el18gs 16:3b298bea3a70 7
el18gs 16:3b298bea3a70 8 for(int i = 0; i < ghost_list.size(); i++) {
el18gs 16:3b298bea3a70 9
el18gs 3:9d811414d35e 10 std::string path = "/sd/ghosts/";
el18gs 3:9d811414d35e 11 path.append(ghost_list[i]);
el18gs 3:9d811414d35e 12 printf("Path to import '%s'\n", path.c_str());
el18gs 16:3b298bea3a70 13
el18gs 8:4220d116f17c 14 Ghost temp(path, "/sd/ghosts/", sd);
el18gs 3:9d811414d35e 15 _ghosts.push_back(temp);
el18gs 3:9d811414d35e 16 }
el18gs 16:3b298bea3a70 17 _gold = 0;
el18gs 3:9d811414d35e 18 }
el18gs 3:9d811414d35e 19
el18gs 16:3b298bea3a70 20 void Inventory::regen(SDFileSystem &sd)
el18gs 16:3b298bea3a70 21 {
el18gs 3:9d811414d35e 22 printf("Regenerating ghost list\n");
el18gs 3:9d811414d35e 23 _ghosts.clear();
el18gs 16:3b298bea3a70 24
el18gs 8:4220d116f17c 25 stringvec ghost_list = list_ghosts("/sd/ghosts", sd);
el18gs 16:3b298bea3a70 26
el18gs 16:3b298bea3a70 27 for(int i = 0; i < ghost_list.size(); i++) {
el18gs 16:3b298bea3a70 28
el18gs 3:9d811414d35e 29 std::string path = "/sd/ghosts/";
el18gs 3:9d811414d35e 30 path.append(ghost_list[i]);
el18gs 3:9d811414d35e 31 printf("Path to import '%s'\n", path.c_str());
el18gs 16:3b298bea3a70 32
el18gs 8:4220d116f17c 33 Ghost temp(path, "/sd/ghosts/", sd);
el18gs 3:9d811414d35e 34 _ghosts.push_back(temp);
el18gs 3:9d811414d35e 35 }
el18gs 16:3b298bea3a70 36
el18gs 3:9d811414d35e 37 }
el18gs 3:9d811414d35e 38
el18gs 16:3b298bea3a70 39 std::vector<int> Inventory::list_ghost_uids(void)
el18gs 16:3b298bea3a70 40 {
el18gs 3:9d811414d35e 41 std::vector<int> uids;
el18gs 16:3b298bea3a70 42 for(int i = 0; i < _ghosts.size(); i++) {
el18gs 3:9d811414d35e 43 uids.push_back(_ghosts[i].get_uid());
el18gs 3:9d811414d35e 44 //printf("Added UID %i to list\n", _ghosts[i].get_uid());
el18gs 3:9d811414d35e 45 }
el18gs 16:3b298bea3a70 46
el18gs 3:9d811414d35e 47 return uids;
el18gs 3:9d811414d35e 48 }
el18gs 3:9d811414d35e 49
el18gs 16:3b298bea3a70 50 Ghost Inventory::get_ghost_by_uid(int uid)
el18gs 16:3b298bea3a70 51 {
el18gs 16:3b298bea3a70 52 for(int i = 0; i < _ghosts.size(); i++) {
el18gs 16:3b298bea3a70 53 if(_ghosts[i].get_uid() == uid) {
el18gs 3:9d811414d35e 54 return _ghosts[i];
el18gs 3:9d811414d35e 55 }
el18gs 3:9d811414d35e 56 }
el18gs 3:9d811414d35e 57 return _ghosts[0];
el18gs 3:9d811414d35e 58 }
el18gs 3:9d811414d35e 59
el18gs 8:4220d116f17c 60 stringvec Inventory::list_ghosts(std::string path, SDFileSystem &sd)
el18gs 3:9d811414d35e 61 {
el18gs 3:9d811414d35e 62 // Connections to SD card holder on K64F (SPI interface)
el18gs 8:4220d116f17c 63 //SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); // MOSI, MISO, SCK, CS
el18gs 3:9d811414d35e 64 //std::string path = "/sd/ghosts";
el18gs 3:9d811414d35e 65 printf("Checking directory for ghosts: %s\n", path.c_str());
el18gs 3:9d811414d35e 66 DIR *d;
el18gs 3:9d811414d35e 67 struct dirent *p;
el18gs 3:9d811414d35e 68
el18gs 3:9d811414d35e 69 stringvec files;
el18gs 3:9d811414d35e 70
el18gs 3:9d811414d35e 71 d = opendir(path.c_str());
el18gs 3:9d811414d35e 72 if (d != NULL) {
el18gs 3:9d811414d35e 73 while ((p = readdir(d)) != NULL) {
el18gs 3:9d811414d35e 74 files.push_back(p->d_name);
el18gs 3:9d811414d35e 75 }
el18gs 3:9d811414d35e 76 } else {
el18gs 3:9d811414d35e 77 printf("Could not open directory!\n");
el18gs 3:9d811414d35e 78 }
el18gs 3:9d811414d35e 79 closedir(d);
el18gs 16:3b298bea3a70 80
el18gs 3:9d811414d35e 81 stringvec correct_files;
el18gs 16:3b298bea3a70 82
el18gs 16:3b298bea3a70 83 for(int i = 0; i < files.size(); i++) {
el18gs 16:3b298bea3a70 84 if(hasEnding(files[i], ".ghost")) {
el18gs 3:9d811414d35e 85 correct_files.push_back(files[i]);
el18gs 3:9d811414d35e 86 }
el18gs 3:9d811414d35e 87 }
el18gs 16:3b298bea3a70 88
el18gs 3:9d811414d35e 89 return correct_files;
el18gs 3:9d811414d35e 90 }
el18gs 3:9d811414d35e 91
el18gs 16:3b298bea3a70 92 void Inventory::sell_ghost_by_uid(int uid, SDFileSystem &sd)
el18gs 16:3b298bea3a70 93 {
el18gs 3:9d811414d35e 94 printf("Inside sell function\n");
el18gs 16:3b298bea3a70 95 for(int i = 0; i < _ghosts.size(); i++) {
el18gs 16:3b298bea3a70 96 if(_ghosts[i].get_uid() == uid) {
el18gs 3:9d811414d35e 97 printf("Sale target found\n");
el18gs 8:4220d116f17c 98 int value = _ghosts[i].sell(sd);
el18gs 3:9d811414d35e 99 _ghosts.erase(_ghosts.begin() + i);
el18gs 3:9d811414d35e 100 _gold = _gold + value;
el18gs 16:3b298bea3a70 101 if(_gold > 99) {
el18gs 16:3b298bea3a70 102 _gold = 99;
el18gs 16:3b298bea3a70 103 }
el18gs 3:9d811414d35e 104 break;
el18gs 3:9d811414d35e 105 }
el18gs 16:3b298bea3a70 106
el18gs 3:9d811414d35e 107 }
el18gs 11:e89dbdb74df5 108 }
el18gs 11:e89dbdb74df5 109
el18gs 16:3b298bea3a70 110 void Inventory::feed_ghost_by_uid(int uid, SDFileSystem &sd)
el18gs 16:3b298bea3a70 111 {
el18gs 16:3b298bea3a70 112 printf("Inside feed function\n");
el18gs 16:3b298bea3a70 113 if(_gold < 10) { return; }
el18gs 16:3b298bea3a70 114 for(int i = 0; i < _ghosts.size(); i++) {
el18gs 16:3b298bea3a70 115 if(_ghosts[i].get_uid() == uid) {
el18gs 16:3b298bea3a70 116 printf("Feed target found\n");
el18gs 16:3b298bea3a70 117 _ghosts[i].feed(10, sd);
el18gs 16:3b298bea3a70 118 _gold = _gold - 10;
el18gs 16:3b298bea3a70 119 break;
el18gs 16:3b298bea3a70 120 }
el18gs 16:3b298bea3a70 121
el18gs 16:3b298bea3a70 122 }
el18gs 16:3b298bea3a70 123 }
el18gs 16:3b298bea3a70 124
el18gs 16:3b298bea3a70 125 void Inventory::print_coin(SDFileSystem &sd, N5110 &lcd)
el18gs 16:3b298bea3a70 126 {
el18gs 16:3b298bea3a70 127 int** ghost = import_sprite("/sd/assets/coin.sprite", sd);
el18gs 16:3b298bea3a70 128 for(int i = 0; i < 10; i++) { // Iterate Columns: x
el18gs 16:3b298bea3a70 129 for(int j = 0; j < 10; j++) { // Iterate Rows: y
el18gs 16:3b298bea3a70 130 lcd.setPixel(i + 74, j, ghost[j][i]);
el18gs 16:3b298bea3a70 131 }
el18gs 16:3b298bea3a70 132 }
el18gs 16:3b298bea3a70 133 }
el18gs 16:3b298bea3a70 134
el18gs 16:3b298bea3a70 135 void Inventory::display_inventory(SDFileSystem &sd,
el18gs 16:3b298bea3a70 136 N5110 &lcd,
el18gs 16:3b298bea3a70 137 Gamepad &pad,
el18gs 16:3b298bea3a70 138 volatile int &g_buttonX_flag,
el18gs 16:3b298bea3a70 139 volatile int &g_buttonStart_flag,
el18gs 16:3b298bea3a70 140 volatile int &g_buttonA_flag)
el18gs 11:e89dbdb74df5 141 {
el18gs 11:e89dbdb74df5 142 int which_ghost_state = 0;
el18gs 11:e89dbdb74df5 143 int which_view_state = 0;
el18gs 11:e89dbdb74df5 144 int new_which_view_state = 0;
el18gs 11:e89dbdb74df5 145
el18gs 11:e89dbdb74df5 146 std::vector<inven_state> ghost_fsm;
el18gs 11:e89dbdb74df5 147
el18gs 11:e89dbdb74df5 148 bool regen_inven = true;
el18gs 11:e89dbdb74df5 149 bool scroll_ghost = false;
el18gs 11:e89dbdb74df5 150 bool update = true;
el18gs 11:e89dbdb74df5 151
el18gs 11:e89dbdb74df5 152 while(1) {
el18gs 11:e89dbdb74df5 153 if(regen_inven) {
el18gs 11:e89dbdb74df5 154 regen(sd);
el18gs 11:e89dbdb74df5 155 ghost_fsm = gen_ghost_fsm();
el18gs 11:e89dbdb74df5 156 regen_inven = false;
el18gs 11:e89dbdb74df5 157 which_ghost_state = 0;
el18gs 11:e89dbdb74df5 158 which_view_state = 0;
el18gs 11:e89dbdb74df5 159 }
el18gs 11:e89dbdb74df5 160
el18gs 11:e89dbdb74df5 161 if(update) {
el18gs 11:e89dbdb74df5 162 update = false;
el18gs 11:e89dbdb74df5 163
el18gs 11:e89dbdb74df5 164 if(scroll_ghost) {
el18gs 11:e89dbdb74df5 165 wait_ms(750);
el18gs 11:e89dbdb74df5 166 scroll_ghost = false;
el18gs 11:e89dbdb74df5 167 }
el18gs 11:e89dbdb74df5 168
el18gs 11:e89dbdb74df5 169 lcd.clear();
el18gs 16:3b298bea3a70 170 char buffer [64];
el18gs 16:3b298bea3a70 171 sprintf(buffer, "Inventory:%d", _gold);
el18gs 16:3b298bea3a70 172 lcd.printString(buffer, 0, 0);
el18gs 11:e89dbdb74df5 173
el18gs 16:3b298bea3a70 174 print_coin(sd, lcd);
el18gs 11:e89dbdb74df5 175
el18gs 11:e89dbdb74df5 176 if(ghost_fsm.size() == 0) {
el18gs 11:e89dbdb74df5 177 lcd.printString("No ghosts", 0, 1);
el18gs 11:e89dbdb74df5 178 lcd.printString("found, exiting", 0, 2);
el18gs 11:e89dbdb74df5 179 lcd.refresh();
el18gs 11:e89dbdb74df5 180 wait(1);
el18gs 11:e89dbdb74df5 181 return;
el18gs 11:e89dbdb74df5 182 } else {
el18gs 11:e89dbdb74df5 183
el18gs 11:e89dbdb74df5 184 if(which_view_state <= 0) {
el18gs 11:e89dbdb74df5 185 sprintf(buffer, "%s", ghost_fsm[which_ghost_state].type.c_str());
el18gs 11:e89dbdb74df5 186 lcd.printString(buffer, 0, 1 - which_view_state);
el18gs 11:e89dbdb74df5 187 }
el18gs 11:e89dbdb74df5 188
el18gs 11:e89dbdb74df5 189 if(which_view_state <= 1) {
el18gs 11:e89dbdb74df5 190 sprintf(buffer, "Name: %s", ghost_fsm[which_ghost_state].name.c_str());
el18gs 11:e89dbdb74df5 191 lcd.printString(buffer, 0, 2 - which_view_state);
el18gs 11:e89dbdb74df5 192 }
el18gs 11:e89dbdb74df5 193
el18gs 11:e89dbdb74df5 194 if(which_view_state <= 2) {
el18gs 11:e89dbdb74df5 195 sprintf(buffer, "Attack: %d", ghost_fsm[which_ghost_state].attack);
el18gs 11:e89dbdb74df5 196 lcd.printString(buffer, 0, 3 - which_view_state);
el18gs 11:e89dbdb74df5 197 }
el18gs 11:e89dbdb74df5 198
el18gs 11:e89dbdb74df5 199 if(which_view_state <= 3) {
el18gs 11:e89dbdb74df5 200 sprintf(buffer, "Defense: %d", ghost_fsm[which_ghost_state].defense);
el18gs 11:e89dbdb74df5 201 lcd.printString(buffer, 0, 4 - which_view_state);
el18gs 11:e89dbdb74df5 202 }
el18gs 11:e89dbdb74df5 203
el18gs 11:e89dbdb74df5 204 if(which_view_state <= 4) {
el18gs 11:e89dbdb74df5 205 sprintf(buffer, "Level: %d", ghost_fsm[which_ghost_state].level);
el18gs 11:e89dbdb74df5 206 lcd.printString(buffer, 0, 5 - which_view_state);
el18gs 11:e89dbdb74df5 207 }
el18gs 11:e89dbdb74df5 208
el18gs 11:e89dbdb74df5 209 if(which_view_state <= 5) {
el18gs 11:e89dbdb74df5 210 sprintf(buffer, "Value: %d", ghost_fsm[which_ghost_state].value);
el18gs 11:e89dbdb74df5 211 lcd.printString(buffer, 0, 6 - which_view_state);
el18gs 11:e89dbdb74df5 212 }
el18gs 11:e89dbdb74df5 213
el18gs 11:e89dbdb74df5 214 if(which_view_state <= 6) {
el18gs 11:e89dbdb74df5 215 sprintf(buffer, "HP Max: %d", ghost_fsm[which_ghost_state].hp_max);
el18gs 11:e89dbdb74df5 216 lcd.printString(buffer, 0, 7 - which_view_state);
el18gs 11:e89dbdb74df5 217 }
el18gs 11:e89dbdb74df5 218
el18gs 11:e89dbdb74df5 219 if(which_view_state <= 7) {
el18gs 11:e89dbdb74df5 220 sprintf(buffer, "HP: %d", ghost_fsm[which_ghost_state].hp);
el18gs 11:e89dbdb74df5 221 lcd.printString(buffer, 0, 7 - which_view_state);
el18gs 11:e89dbdb74df5 222 }
el18gs 11:e89dbdb74df5 223
el18gs 11:e89dbdb74df5 224 lcd.refresh();
el18gs 11:e89dbdb74df5 225 }
el18gs 11:e89dbdb74df5 226
el18gs 11:e89dbdb74df5 227 }
el18gs 11:e89dbdb74df5 228
el18gs 11:e89dbdb74df5 229 if(pad.read_pot2() <= (double) 0.33) {
el18gs 11:e89dbdb74df5 230 new_which_view_state = 0;
el18gs 11:e89dbdb74df5 231 } else if(pad.read_pot2() <= (double) 0.66) {
el18gs 11:e89dbdb74df5 232 new_which_view_state = 1;
el18gs 11:e89dbdb74df5 233 } else {
el18gs 11:e89dbdb74df5 234 new_which_view_state = 2;
el18gs 11:e89dbdb74df5 235 }
el18gs 11:e89dbdb74df5 236
el18gs 11:e89dbdb74df5 237 if(new_which_view_state != which_view_state) {
el18gs 11:e89dbdb74df5 238 update = true;
el18gs 11:e89dbdb74df5 239 which_view_state = new_which_view_state;
el18gs 11:e89dbdb74df5 240 }
el18gs 11:e89dbdb74df5 241
el18gs 11:e89dbdb74df5 242 if(pad.read_pot1() < (double) 0.33) {
el18gs 11:e89dbdb74df5 243 which_ghost_state = ghost_fsm[which_ghost_state].next[1];
el18gs 11:e89dbdb74df5 244 scroll_ghost = true;
el18gs 11:e89dbdb74df5 245 } else if(pad.read_pot1() > (double) 0.66) {
el18gs 11:e89dbdb74df5 246 which_ghost_state = ghost_fsm[which_ghost_state].next[0];
el18gs 11:e89dbdb74df5 247 scroll_ghost = true;
el18gs 11:e89dbdb74df5 248 }
el18gs 11:e89dbdb74df5 249
el18gs 11:e89dbdb74df5 250 if(scroll_ghost) {
el18gs 11:e89dbdb74df5 251 update = true;
el18gs 11:e89dbdb74df5 252 }
el18gs 11:e89dbdb74df5 253
el18gs 11:e89dbdb74df5 254 if(g_buttonX_flag) {
el18gs 11:e89dbdb74df5 255 printf("X button pressed\n");
el18gs 11:e89dbdb74df5 256 update = true;
el18gs 11:e89dbdb74df5 257 g_buttonX_flag = 0;
el18gs 11:e89dbdb74df5 258 lcd.drawRect(0,16,84,16, FILL_WHITE);
el18gs 11:e89dbdb74df5 259 lcd.printString("Press again",10,2);
el18gs 11:e89dbdb74df5 260 lcd.printString("to sell",20,3);
el18gs 11:e89dbdb74df5 261
el18gs 11:e89dbdb74df5 262 //wait_ms(50);
el18gs 11:e89dbdb74df5 263
el18gs 11:e89dbdb74df5 264 Timer t;
el18gs 11:e89dbdb74df5 265 t.start();
el18gs 11:e89dbdb74df5 266
el18gs 11:e89dbdb74df5 267 g_buttonX_flag = 0;
el18gs 11:e89dbdb74df5 268 bool sell = false;
el18gs 11:e89dbdb74df5 269
el18gs 11:e89dbdb74df5 270 while(t.read() <= 5) {
el18gs 11:e89dbdb74df5 271 int time = t.read();
el18gs 11:e89dbdb74df5 272 bool changed = false;
el18gs 11:e89dbdb74df5 273 if(time == 0) {
el18gs 11:e89dbdb74df5 274 lcd.printString("5",60,3);
el18gs 11:e89dbdb74df5 275 changed = true;
el18gs 11:e89dbdb74df5 276 } else if (time == 1) {
el18gs 11:e89dbdb74df5 277 lcd.printString("4",60,3);
el18gs 11:e89dbdb74df5 278 changed = true;
el18gs 11:e89dbdb74df5 279 } else if (time == 2) {
el18gs 11:e89dbdb74df5 280 lcd.printString("3",60,3);
el18gs 11:e89dbdb74df5 281 changed = true;
el18gs 11:e89dbdb74df5 282 } else if (time == 3) {
el18gs 11:e89dbdb74df5 283 lcd.printString("2",60,3);
el18gs 11:e89dbdb74df5 284 changed = true;
el18gs 11:e89dbdb74df5 285 } else if (time == 4) {
el18gs 11:e89dbdb74df5 286 lcd.printString("1",60,3);
el18gs 11:e89dbdb74df5 287 changed = true;
el18gs 11:e89dbdb74df5 288 } else if (time == 5) {
el18gs 11:e89dbdb74df5 289 lcd.printString("0",60,3);
el18gs 11:e89dbdb74df5 290 changed = true;
el18gs 11:e89dbdb74df5 291 }
el18gs 11:e89dbdb74df5 292
el18gs 11:e89dbdb74df5 293 if(g_buttonX_flag) {
el18gs 11:e89dbdb74df5 294 printf("button X pressed\n");
el18gs 11:e89dbdb74df5 295 g_buttonX_flag = 0;
el18gs 11:e89dbdb74df5 296 sell = true;
el18gs 11:e89dbdb74df5 297 }
el18gs 11:e89dbdb74df5 298
el18gs 11:e89dbdb74df5 299 if(changed) {
el18gs 11:e89dbdb74df5 300 lcd.refresh();
el18gs 11:e89dbdb74df5 301 }
el18gs 11:e89dbdb74df5 302
el18gs 11:e89dbdb74df5 303 if(sell) {
el18gs 11:e89dbdb74df5 304 printf("Exiting to sell\n");
el18gs 11:e89dbdb74df5 305 break;
el18gs 11:e89dbdb74df5 306 }
el18gs 11:e89dbdb74df5 307 }
el18gs 11:e89dbdb74df5 308
el18gs 11:e89dbdb74df5 309 if(sell) {
el18gs 11:e89dbdb74df5 310 printf("Running sell function\n");
el18gs 11:e89dbdb74df5 311 sell_ghost_by_uid(ghost_fsm[which_ghost_state].uid, sd);
el18gs 11:e89dbdb74df5 312 regen_inven = true;
el18gs 11:e89dbdb74df5 313 update = true;
el18gs 11:e89dbdb74df5 314 }
el18gs 11:e89dbdb74df5 315
el18gs 16:3b298bea3a70 316
el18gs 11:e89dbdb74df5 317 } else if(g_buttonStart_flag) {
el18gs 11:e89dbdb74df5 318 g_buttonStart_flag = 0;
el18gs 11:e89dbdb74df5 319 return;
el18gs 16:3b298bea3a70 320 } else if(g_buttonA_flag == 1) {
el18gs 16:3b298bea3a70 321 g_buttonA_flag = 0;
el18gs 16:3b298bea3a70 322 feed_ghost_by_uid(ghost_fsm[which_ghost_state].uid, sd);
el18gs 16:3b298bea3a70 323 regen_inven = true;
el18gs 16:3b298bea3a70 324 update = true;
el18gs 11:e89dbdb74df5 325 }
el18gs 11:e89dbdb74df5 326
el18gs 11:e89dbdb74df5 327 }
el18gs 11:e89dbdb74df5 328
el18gs 11:e89dbdb74df5 329 }
el18gs 11:e89dbdb74df5 330
el18gs 11:e89dbdb74df5 331 std::vector<inven_state> Inventory::gen_ghost_fsm()
el18gs 11:e89dbdb74df5 332 {
el18gs 11:e89dbdb74df5 333 std::vector<inven_state> ghost_fsm;
el18gs 11:e89dbdb74df5 334
el18gs 11:e89dbdb74df5 335 std::vector<int> uids = list_ghost_uids();
el18gs 11:e89dbdb74df5 336
el18gs 11:e89dbdb74df5 337 sort(uids.begin(), uids.end());
el18gs 11:e89dbdb74df5 338
el18gs 11:e89dbdb74df5 339 for(int i = 0; i < uids.size(); i++) {
el18gs 11:e89dbdb74df5 340 Ghost ghost_temp = get_ghost_by_uid(uids[i]);
el18gs 11:e89dbdb74df5 341 inven_state temp;
el18gs 11:e89dbdb74df5 342 temp.uid = ghost_temp.get_uid();
el18gs 11:e89dbdb74df5 343 temp.name = ghost_temp.get_name();
el18gs 11:e89dbdb74df5 344 temp.type = ghost_temp.get_type_string();
el18gs 11:e89dbdb74df5 345 temp.attack = ghost_temp.get_attack();
el18gs 11:e89dbdb74df5 346 temp.defense = ghost_temp.get_defense();
el18gs 11:e89dbdb74df5 347 temp.level = ghost_temp.get_level();
el18gs 11:e89dbdb74df5 348 temp.xp = ghost_temp.get_xp();
el18gs 11:e89dbdb74df5 349 temp.value = ghost_temp.get_value();
el18gs 11:e89dbdb74df5 350 temp.hp_max = ghost_temp.get_hp_max();
el18gs 11:e89dbdb74df5 351 temp.hp = ghost_temp.get_hp();
el18gs 11:e89dbdb74df5 352
el18gs 11:e89dbdb74df5 353 ghost_fsm.push_back(temp);
el18gs 11:e89dbdb74df5 354 //printf("Added Ghost UID %i to fsm\n", temp.uid);
el18gs 11:e89dbdb74df5 355 printf("%s\n", temp.name.c_str());
el18gs 11:e89dbdb74df5 356 }
el18gs 11:e89dbdb74df5 357
el18gs 11:e89dbdb74df5 358 for(int i = 0; i < ghost_fsm.size(); i++) {
el18gs 11:e89dbdb74df5 359 if (i == 0) {
el18gs 11:e89dbdb74df5 360 int next[2] = {1, ghost_fsm.size() - 1};
el18gs 11:e89dbdb74df5 361 ghost_fsm[i].next[0] = next[0];
el18gs 11:e89dbdb74df5 362 ghost_fsm[i].next[1] = next[1];
el18gs 11:e89dbdb74df5 363 } else if (i == ghost_fsm.size() - 1) {
el18gs 11:e89dbdb74df5 364 int next[2] = {0, ghost_fsm.size() - 2};
el18gs 11:e89dbdb74df5 365 ghost_fsm[i].next[0] = next[0];
el18gs 11:e89dbdb74df5 366 ghost_fsm[i].next[1] = next[1];
el18gs 11:e89dbdb74df5 367 } else {
el18gs 11:e89dbdb74df5 368 int next[2] = {i + 1, i - 1};
el18gs 11:e89dbdb74df5 369 ghost_fsm[i].next[0] = next[0];
el18gs 11:e89dbdb74df5 370 ghost_fsm[i].next[1] = next[1];
el18gs 11:e89dbdb74df5 371 }
el18gs 11:e89dbdb74df5 372 }
el18gs 11:e89dbdb74df5 373
el18gs 11:e89dbdb74df5 374 return ghost_fsm;
el18gs 3:9d811414d35e 375 }