Randall Kliman / Mbed 2 deprecated NEOPUNK

Dependencies:   mbed wave_player 4DGL-uLCD-SE MMA8452

Committer:
Sterofin
Date:
Fri Nov 30 05:31:06 2018 +0000
Revision:
4:af9d6e3b8a29
Parent:
3:664c79e2ceb5
Child:
5:a16af8f3fea9
big boi;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rconnorlawson 0:35660d7952f7 1 // Project includes
rconnorlawson 0:35660d7952f7 2 #include "globals.h"
rconnorlawson 0:35660d7952f7 3 #include "hardware.h"
rconnorlawson 0:35660d7952f7 4 #include "map.h"
rconnorlawson 0:35660d7952f7 5 #include "graphics.h"
rconnorlawson 0:35660d7952f7 6 #include "speech.h"
Sterofin 2:06c63d567719 7 #include "hash_table.h"
Sterofin 2:06c63d567719 8
Sterofin 2:06c63d567719 9 GameInputs in;
Sterofin 2:06c63d567719 10 int actions;
Sterofin 2:06c63d567719 11 int update;
Sterofin 2:06c63d567719 12 bool god;
Sterofin 2:06c63d567719 13 bool puzzle = false;
Sterofin 2:06c63d567719 14 bool mapact = 0;
Sterofin 2:06c63d567719 15 int story = 0;
Sterofin 2:06c63d567719 16 unsigned int m_z=12434,m_w=33254;
Sterofin 2:06c63d567719 17 unsigned int rnd() {
Sterofin 2:06c63d567719 18 m_z = 36969 * (m_z & 65535) + (m_z >>16);
Sterofin 2:06c63d567719 19 m_w = 18000 * (m_w & 65535) + (m_w >>16);
Sterofin 2:06c63d567719 20 return ((m_z <<16) + m_w);
Sterofin 2:06c63d567719 21 }
Sterofin 2:06c63d567719 22
Sterofin 2:06c63d567719 23 unsigned int n[4];
Sterofin 2:06c63d567719 24
rconnorlawson 0:35660d7952f7 25
rconnorlawson 0:35660d7952f7 26 // Functions in this file
rconnorlawson 0:35660d7952f7 27 int get_action (GameInputs inputs);
rconnorlawson 0:35660d7952f7 28 int update_game (int action);
rconnorlawson 0:35660d7952f7 29 void draw_game (int init);
rconnorlawson 0:35660d7952f7 30 void init_main_map ();
rconnorlawson 0:35660d7952f7 31 int main ();
rconnorlawson 0:35660d7952f7 32
rconnorlawson 0:35660d7952f7 33 /**
rconnorlawson 0:35660d7952f7 34 * The main game state. Must include Player locations and previous locations for
rconnorlawson 0:35660d7952f7 35 * drawing to work properly. Other items can be added as needed.
rconnorlawson 0:35660d7952f7 36 */
rconnorlawson 0:35660d7952f7 37 struct {
rconnorlawson 0:35660d7952f7 38 int x,y; // Current locations
rconnorlawson 0:35660d7952f7 39 int px, py; // Previous locations
rconnorlawson 0:35660d7952f7 40 int has_key;
Sterofin 2:06c63d567719 41 int speed;
Sterofin 2:06c63d567719 42 bool can_teleport;
Sterofin 4:af9d6e3b8a29 43 int money;
rconnorlawson 0:35660d7952f7 44 } Player;
rconnorlawson 0:35660d7952f7 45
Sterofin 2:06c63d567719 46 struct {
Sterofin 2:06c63d567719 47 bool has_boots;
Sterofin 2:06c63d567719 48 bool has_teleport;
Sterofin 2:06c63d567719 49 bool has_gun;
Sterofin 2:06c63d567719 50 bool has_printer;
Sterofin 2:06c63d567719 51 } Inventory;
Sterofin 2:06c63d567719 52
rconnorlawson 0:35660d7952f7 53 /**
rconnorlawson 0:35660d7952f7 54 * Given the game inputs, determine what kind of update needs to happen.
rconnorlawson 0:35660d7952f7 55 * Possbile return values are defined below.
rconnorlawson 0:35660d7952f7 56 */
rconnorlawson 0:35660d7952f7 57 #define NO_ACTION 0
rconnorlawson 0:35660d7952f7 58 #define ACTION_BUTTON 1
rconnorlawson 0:35660d7952f7 59 #define MENU_BUTTON 2
rconnorlawson 0:35660d7952f7 60 #define GO_LEFT 3
rconnorlawson 0:35660d7952f7 61 #define GO_RIGHT 4
rconnorlawson 0:35660d7952f7 62 #define GO_UP 5
rconnorlawson 0:35660d7952f7 63 #define GO_DOWN 6
Sterofin 2:06c63d567719 64 #define THRESH 0.3
Sterofin 2:06c63d567719 65 #define GOD_MODE 7
Sterofin 2:06c63d567719 66 #define BUTTON_3 8
Sterofin 2:06c63d567719 67 #define BUTTON_4 9
Sterofin 2:06c63d567719 68 int walkk;
rconnorlawson 0:35660d7952f7 69 int get_action(GameInputs inputs)
rconnorlawson 0:35660d7952f7 70 {
Sterofin 2:06c63d567719 71 //pc.printf("%d,%d\r\n",inputs.ax,inputs.ay);
Sterofin 2:06c63d567719 72 if(inputs.ax < -THRESH) return GO_UP;
Sterofin 2:06c63d567719 73 if(inputs.ax >= THRESH) return GO_DOWN;
Sterofin 2:06c63d567719 74 if(inputs.ay >= THRESH) return GO_RIGHT;
Sterofin 2:06c63d567719 75 if(inputs.ay < -THRESH) return GO_LEFT;
Sterofin 2:06c63d567719 76 if(!inputs.b1) return ACTION_BUTTON;
Sterofin 2:06c63d567719 77 if(!inputs.b2) return MENU_BUTTON;
Sterofin 2:06c63d567719 78 if(!inputs.b3 && !puzzle){
Sterofin 2:06c63d567719 79 pc.printf("Button 3 pressed");
Sterofin 2:06c63d567719 80 god = !god;
Sterofin 2:06c63d567719 81 if(god) uLCD.filled_rectangle(128,0,119,7,WHITE);
Sterofin 2:06c63d567719 82 else if(!god) uLCD.filled_rectangle(128,0,119,7,BLACK);
Sterofin 2:06c63d567719 83 }
Sterofin 2:06c63d567719 84 else if(!inputs.b3) return BUTTON_3;
Sterofin 2:06c63d567719 85 if(!inputs.b4) return BUTTON_4;
rconnorlawson 0:35660d7952f7 86 return NO_ACTION;
rconnorlawson 0:35660d7952f7 87 }
rconnorlawson 0:35660d7952f7 88
Sterofin 2:06c63d567719 89 int go_up()
Sterofin 2:06c63d567719 90 {
Sterofin 2:06c63d567719 91 if(get_north(Player.x,Player.y)->walkable || god)
Sterofin 2:06c63d567719 92 {
Sterofin 2:06c63d567719 93 for(walkk = 1;walkk < Player.speed;walkk++){
Sterofin 2:06c63d567719 94 if(!get_north(Player.x,Player.y-walkk)->walkable) break;
Sterofin 2:06c63d567719 95 }
Sterofin 2:06c63d567719 96 Player.y-=walkk;
Sterofin 2:06c63d567719 97 return 1;
Sterofin 2:06c63d567719 98 }else return 0;
Sterofin 2:06c63d567719 99 }
Sterofin 2:06c63d567719 100
Sterofin 2:06c63d567719 101 int go_down()
Sterofin 2:06c63d567719 102 {
Sterofin 2:06c63d567719 103 if(get_south(Player.x,Player.y)->walkable || god)
Sterofin 2:06c63d567719 104 {
Sterofin 2:06c63d567719 105 for(walkk = 1;walkk < Player.speed;walkk++){
Sterofin 2:06c63d567719 106 if(!get_south(Player.x,Player.y+walkk)->walkable) break;
Sterofin 2:06c63d567719 107 }
Sterofin 2:06c63d567719 108 Player.y+=walkk;
Sterofin 2:06c63d567719 109 return 1;
Sterofin 2:06c63d567719 110 }else return 0;
Sterofin 2:06c63d567719 111 }
Sterofin 2:06c63d567719 112
Sterofin 2:06c63d567719 113 int go_left()
Sterofin 2:06c63d567719 114 {
Sterofin 2:06c63d567719 115 if(get_west(Player.x,Player.y)->walkable || god)
Sterofin 2:06c63d567719 116 {
Sterofin 2:06c63d567719 117 for(walkk = 1;walkk < Player.speed;walkk++){
Sterofin 2:06c63d567719 118 if(!get_west(Player.x-walkk,Player.y)->walkable) break;
Sterofin 2:06c63d567719 119 }
Sterofin 2:06c63d567719 120 Player.x-=walkk;
Sterofin 2:06c63d567719 121 return 1;
Sterofin 2:06c63d567719 122 }else return 0;
Sterofin 2:06c63d567719 123 }
Sterofin 2:06c63d567719 124
Sterofin 2:06c63d567719 125 int go_right()
Sterofin 2:06c63d567719 126 {
Sterofin 2:06c63d567719 127 if(get_east(Player.x,Player.y)->walkable || god)
Sterofin 2:06c63d567719 128 {
Sterofin 2:06c63d567719 129 for(walkk = 1;walkk < Player.speed;walkk++){
Sterofin 2:06c63d567719 130 if(!get_east(Player.x+walkk,Player.y)->walkable) break;
Sterofin 2:06c63d567719 131 }
Sterofin 2:06c63d567719 132 Player.x+=walkk;
Sterofin 2:06c63d567719 133 return 1;
Sterofin 2:06c63d567719 134 }else return 0;
Sterofin 2:06c63d567719 135 }
Sterofin 2:06c63d567719 136
Sterofin 2:06c63d567719 137 //Looks at if there's a block of the desired type next to the player
Sterofin 2:06c63d567719 138 int checkType(int t)
Sterofin 2:06c63d567719 139 {
Sterofin 2:06c63d567719 140 MapItem* n = get_north(Player.x,Player.y);
Sterofin 2:06c63d567719 141 MapItem* s = get_south(Player.x,Player.y);
Sterofin 2:06c63d567719 142 MapItem* e = get_east(Player.x,Player.y);
Sterofin 2:06c63d567719 143 MapItem* w = get_west(Player.x,Player.y);
Sterofin 2:06c63d567719 144 //pc.printf("%d\r\n",n->type);
Sterofin 2:06c63d567719 145 // pc.printf("%d\r\n",s->type);
Sterofin 2:06c63d567719 146 // pc.printf("%d\r\n",e->type);
Sterofin 2:06c63d567719 147 // pc.printf("%d\r\n",w->type);
Sterofin 2:06c63d567719 148 if(n->type == t || s->type == t || e->type == t || w->type == t)
Sterofin 2:06c63d567719 149 {
Sterofin 2:06c63d567719 150 return 1;
Sterofin 2:06c63d567719 151 }else return 0;
Sterofin 2:06c63d567719 152 }
Sterofin 2:06c63d567719 153
Sterofin 2:06c63d567719 154 MapItem* find_type(int t)
Sterofin 2:06c63d567719 155 {
Sterofin 2:06c63d567719 156 MapItem* n = get_north(Player.x,Player.y);
Sterofin 2:06c63d567719 157 MapItem* s = get_south(Player.x,Player.y);
Sterofin 2:06c63d567719 158 MapItem* e = get_east(Player.x,Player.y);
Sterofin 2:06c63d567719 159 MapItem* w = get_west(Player.x,Player.y);
Sterofin 2:06c63d567719 160 //pc.printf("%d\r\n",n->type);
Sterofin 2:06c63d567719 161 // pc.printf("%d\r\n",s->type);
Sterofin 2:06c63d567719 162 // pc.printf("%d\r\n",e->type);
Sterofin 2:06c63d567719 163 // pc.printf("%d\r\n",w->type);
Sterofin 2:06c63d567719 164 if(n->type == t) return n;
Sterofin 2:06c63d567719 165 else if(s->type == t) return s;
Sterofin 2:06c63d567719 166 else if(e->type == t) return e;
Sterofin 2:06c63d567719 167 else if(w->type == t) return w;
Sterofin 2:06c63d567719 168 else return NULL;
Sterofin 2:06c63d567719 169 }
Sterofin 2:06c63d567719 170
Sterofin 2:06c63d567719 171 int convert(int num)
Sterofin 2:06c63d567719 172 {
Sterofin 2:06c63d567719 173 if(num == 1) return ACTION_BUTTON;
Sterofin 2:06c63d567719 174 else if(num == 2) return MENU_BUTTON;
Sterofin 2:06c63d567719 175 else if(num == 3) return BUTTON_3;
Sterofin 2:06c63d567719 176 else if(num == 4) return BUTTON_4;
Sterofin 2:06c63d567719 177 return 5;
Sterofin 2:06c63d567719 178 }
Sterofin 2:06c63d567719 179
Sterofin 2:06c63d567719 180 #define mx 4
Sterofin 2:06c63d567719 181 #define my 3
Sterofin 2:06c63d567719 182 void run_minigame(){
Sterofin 2:06c63d567719 183 char buffer[100];
Sterofin 2:06c63d567719 184 n[0] = rnd()%4+1;
Sterofin 2:06c63d567719 185 n[1] = rnd()%4+1;
Sterofin 2:06c63d567719 186 n[2] = rnd()%4+1;
Sterofin 2:06c63d567719 187 n[3] = rnd()%4+1;
Sterofin 2:06c63d567719 188 sprintf(buffer,"of numbers: %d%d%d%d",n[0],n[1],n[2],n[3]);
Sterofin 2:06c63d567719 189 speech(buffer,"");
Sterofin 2:06c63d567719 190 int solved = 0;
Sterofin 2:06c63d567719 191 while(solved < 4)
Sterofin 2:06c63d567719 192 {
Sterofin 2:06c63d567719 193 in = read_inputs();
Sterofin 2:06c63d567719 194 actions = get_action(in);
Sterofin 2:06c63d567719 195 if(solved == 0){
Sterofin 2:06c63d567719 196 if(actions == convert(n[0])){
Sterofin 2:06c63d567719 197 uLCD.locate(mx,my);
Sterofin 2:06c63d567719 198 sprintf(buffer," %d - - - ",n[0]);
Sterofin 2:06c63d567719 199 uLCD.printf(buffer);
Sterofin 2:06c63d567719 200 solved++;
Sterofin 4:af9d6e3b8a29 201 wait(0.25);
Sterofin 2:06c63d567719 202 }
Sterofin 2:06c63d567719 203 }
Sterofin 2:06c63d567719 204 else if(solved == 1){
Sterofin 2:06c63d567719 205 if(actions == convert(n[1])){
Sterofin 2:06c63d567719 206 uLCD.locate(mx,my);
Sterofin 2:06c63d567719 207 sprintf(buffer," %d %d - - ",n[0],n[1]);
Sterofin 2:06c63d567719 208 uLCD.printf(buffer);
Sterofin 2:06c63d567719 209 solved++;
Sterofin 4:af9d6e3b8a29 210 wait(0.25);
Sterofin 2:06c63d567719 211 }
Sterofin 2:06c63d567719 212 }
Sterofin 2:06c63d567719 213 else if(solved == 2){
Sterofin 2:06c63d567719 214 if(actions == convert(n[2])){
Sterofin 2:06c63d567719 215 uLCD.locate(mx,my);
Sterofin 2:06c63d567719 216 sprintf(buffer," %d %d %d - ",n[0],n[1],n[2]);
Sterofin 2:06c63d567719 217 uLCD.printf(buffer);
Sterofin 2:06c63d567719 218 solved++;
Sterofin 4:af9d6e3b8a29 219 wait(0.25);
Sterofin 2:06c63d567719 220 }
Sterofin 2:06c63d567719 221 }
Sterofin 2:06c63d567719 222 else if(solved == 3){
Sterofin 2:06c63d567719 223 if(actions == convert(n[3])){
Sterofin 2:06c63d567719 224 uLCD.locate(mx,my);
Sterofin 2:06c63d567719 225 sprintf(buffer," %d %d %d %d ",n[0],n[1],n[2],n[3]);
Sterofin 2:06c63d567719 226 uLCD.printf(buffer);
Sterofin 2:06c63d567719 227 solved++;
Sterofin 2:06c63d567719 228 wait(0.5);
Sterofin 2:06c63d567719 229 }
Sterofin 2:06c63d567719 230 }
Sterofin 2:06c63d567719 231 }
Sterofin 2:06c63d567719 232 }
Sterofin 2:06c63d567719 233
Sterofin 4:af9d6e3b8a29 234 void item_menu(){
Sterofin 4:af9d6e3b8a29 235 uLCD.cls();
Sterofin 4:af9d6e3b8a29 236 uLCD.printf(" INVENTORY");
Sterofin 4:af9d6e3b8a29 237 if(Inventory.has_gun){
Sterofin 4:af9d6e3b8a29 238 draw_gun(20,40);
Sterofin 4:af9d6e3b8a29 239 uLCD.locate(35,40);
Sterofin 4:af9d6e3b8a29 240 uLCD.printf("KillInator5000");
Sterofin 4:af9d6e3b8a29 241 }
Sterofin 4:af9d6e3b8a29 242 if(Inventory.has_printer){
Sterofin 4:af9d6e3b8a29 243 draw_printer(20,55);
Sterofin 4:af9d6e3b8a29 244 uLCD.locate(35,55);
Sterofin 4:af9d6e3b8a29 245 uLCD.printf("Organ Printer");
Sterofin 4:af9d6e3b8a29 246 }
Sterofin 4:af9d6e3b8a29 247 if(Inventory.has_teleport){
Sterofin 4:af9d6e3b8a29 248 draw_teleport(20,70);
Sterofin 4:af9d6e3b8a29 249 uLCD.locate(35,70);
Sterofin 4:af9d6e3b8a29 250 uLCD.printf("Teleporter");
Sterofin 4:af9d6e3b8a29 251 }
Sterofin 4:af9d6e3b8a29 252 if(Inventory.has_boots){
Sterofin 4:af9d6e3b8a29 253 draw_boots(20,85);
Sterofin 4:af9d6e3b8a29 254 uLCD.locate(35,85);
Sterofin 4:af9d6e3b8a29 255 uLCD.printf("SpeedyBoots");
Sterofin 4:af9d6e3b8a29 256 }
Sterofin 4:af9d6e3b8a29 257 in = read_inputs();
Sterofin 4:af9d6e3b8a29 258 actions = get_action(in);
Sterofin 4:af9d6e3b8a29 259 draw_lower_status(Player.money);
Sterofin 4:af9d6e3b8a29 260 while(actions != MENU_BUTTON){
Sterofin 4:af9d6e3b8a29 261 in = read_inputs();
Sterofin 4:af9d6e3b8a29 262 actions = get_action(in);
Sterofin 4:af9d6e3b8a29 263 }
Sterofin 4:af9d6e3b8a29 264 }
Sterofin 4:af9d6e3b8a29 265
rconnorlawson 0:35660d7952f7 266 /**
rconnorlawson 0:35660d7952f7 267 * Update the game state based on the user action. For example, if the user
rconnorlawson 0:35660d7952f7 268 * requests GO_UP, then this function should determine if that is possible by
rconnorlawson 0:35660d7952f7 269 * consulting the map, and update the Player position accordingly.
rconnorlawson 0:35660d7952f7 270 *
rconnorlawson 0:35660d7952f7 271 * Return values are defined below. FULL_DRAW indicates that for this frame,
rconnorlawson 0:35660d7952f7 272 * draw_game should not optimize drawing and should draw every tile, even if
rconnorlawson 0:35660d7952f7 273 * the player has not moved.
rconnorlawson 0:35660d7952f7 274 */
rconnorlawson 0:35660d7952f7 275 #define NO_RESULT 0
rconnorlawson 0:35660d7952f7 276 #define GAME_OVER 1
rconnorlawson 0:35660d7952f7 277 #define FULL_DRAW 2
Sterofin 2:06c63d567719 278 MapItem* boi;
rconnorlawson 0:35660d7952f7 279 int update_game(int action)
rconnorlawson 0:35660d7952f7 280 {
rconnorlawson 0:35660d7952f7 281 // Save player previous location before updating
rconnorlawson 0:35660d7952f7 282 Player.px = Player.x;
rconnorlawson 0:35660d7952f7 283 Player.py = Player.y;
rconnorlawson 0:35660d7952f7 284
rconnorlawson 0:35660d7952f7 285 // Do different things based on the each action.
rconnorlawson 0:35660d7952f7 286 // You can define functions like "go_up()" that get called for each case.
rconnorlawson 0:35660d7952f7 287 switch(action)
rconnorlawson 0:35660d7952f7 288 {
Sterofin 2:06c63d567719 289 case GO_UP:
Sterofin 2:06c63d567719 290 go_up();
Sterofin 2:06c63d567719 291 break;
Sterofin 2:06c63d567719 292 case GO_LEFT:
Sterofin 2:06c63d567719 293 go_left();
Sterofin 2:06c63d567719 294 break;
Sterofin 2:06c63d567719 295 case GO_DOWN:
Sterofin 2:06c63d567719 296 go_down();
Sterofin 2:06c63d567719 297 break;
Sterofin 2:06c63d567719 298 case GO_RIGHT:
Sterofin 2:06c63d567719 299 go_right();
Sterofin 2:06c63d567719 300 break;
Sterofin 2:06c63d567719 301 case ACTION_BUTTON:
Sterofin 2:06c63d567719 302 pc.printf("Action Button Pressed\r\n");
Sterofin 2:06c63d567719 303 if(checkType(NPORTAL))
Sterofin 2:06c63d567719 304 {
Sterofin 2:06c63d567719 305 if(story == 2 || story == 3 || story == 4){
Sterofin 2:06c63d567719 306 speech("Don't leave! The","hack is almost");
Sterofin 2:06c63d567719 307 speech("finished!","");
Sterofin 2:06c63d567719 308 return FULL_DRAW;
Sterofin 2:06c63d567719 309 }
Sterofin 2:06c63d567719 310 pc.printf("Entering Portal");
Sterofin 2:06c63d567719 311 if(!mapact){
Sterofin 2:06c63d567719 312 set_active_map(1);
Sterofin 2:06c63d567719 313 mapact = 1;
Sterofin 2:06c63d567719 314 Player.x = 2;
Sterofin 2:06c63d567719 315 Player.y = 5;
Sterofin 2:06c63d567719 316 }
Sterofin 2:06c63d567719 317 else if(mapact){
Sterofin 2:06c63d567719 318 set_active_map(0);
Sterofin 2:06c63d567719 319 mapact = 0;
Sterofin 2:06c63d567719 320 Player.x = 37;
Sterofin 2:06c63d567719 321 Player.y = 44;
Sterofin 2:06c63d567719 322 }
Sterofin 2:06c63d567719 323 uLCD.filled_rectangle(0,0,127,9, 0x0);
Sterofin 2:06c63d567719 324 return FULL_DRAW;
Sterofin 2:06c63d567719 325 }
Sterofin 2:06c63d567719 326 else if(checkType(NPC))
Sterofin 2:06c63d567719 327 {
Sterofin 2:06c63d567719 328 if(story == 0){
Sterofin 2:06c63d567719 329 speech("Hey, want to make","some quick cash?");
Sterofin 2:06c63d567719 330 speech("Head over to the","netPortal next");
Sterofin 2:06c63d567719 331 speech("door. Hack","BULLETCORPs server");
Sterofin 2:06c63d567719 332 speech("so we can steal","some of their");
Sterofin 2:06c63d567719 333 speech("advanced tech.","That is, if");
Sterofin 2:06c63d567719 334 speech("you're up for","the job");
Sterofin 2:06c63d567719 335 story++;
Sterofin 2:06c63d567719 336 }
Sterofin 2:06c63d567719 337 else if(story == 1)
Sterofin 2:06c63d567719 338 {
Sterofin 2:06c63d567719 339 speech("C'mon! What are","you waiting for?");
Sterofin 2:06c63d567719 340 }
Sterofin 2:06c63d567719 341 else if(story == 6)
Sterofin 2:06c63d567719 342 {
Sterofin 2:06c63d567719 343 speech("Thanks for the","codes. here's a ");
Sterofin 2:06c63d567719 344 speech("chip that will","let you into");
Sterofin 2:06c63d567719 345 speech("BULLETCORP's","secret tech room");
Sterofin 2:06c63d567719 346 Player.has_key = true;
Sterofin 4:af9d6e3b8a29 347 story++;
Sterofin 2:06c63d567719 348 }
Sterofin 4:af9d6e3b8a29 349 else if(story == 7)
Sterofin 4:af9d6e3b8a29 350 {
Sterofin 4:af9d6e3b8a29 351 if(Inventory.has_gun && Inventory.has_printer) story++;
Sterofin 4:af9d6e3b8a29 352 else{
Sterofin 4:af9d6e3b8a29 353 speech("You don't have","everything, go");
Sterofin 4:af9d6e3b8a29 354 speech("back and get","the rest of the");
Sterofin 4:af9d6e3b8a29 355 speech("tech in order","to get paid");
Sterofin 4:af9d6e3b8a29 356 }
Sterofin 4:af9d6e3b8a29 357 }
Sterofin 4:af9d6e3b8a29 358 else if(story == 8){
Sterofin 4:af9d6e3b8a29 359 speech("Nice! Here's your","cash as");
Sterofin 4:af9d6e3b8a29 360 speech("promised.","");
Sterofin 4:af9d6e3b8a29 361 Inventory.has_printer = false;
Sterofin 4:af9d6e3b8a29 362 Inventory.has_gun = false;
Sterofin 4:af9d6e3b8a29 363 Player.money = 100;
Sterofin 4:af9d6e3b8a29 364 story++;
Sterofin 4:af9d6e3b8a29 365 }
Sterofin 4:af9d6e3b8a29 366 else if(story == 9){
Sterofin 4:af9d6e3b8a29 367 speech("I've got one","more job if");
Sterofin 4:af9d6e3b8a29 368 speech("you want it.","");
Sterofin 4:af9d6e3b8a29 369 speech("I need you to","take out the");
Sterofin 4:af9d6e3b8a29 370 speech("leader of the","Gigem' Boys");
Sterofin 4:af9d6e3b8a29 371 speech("He's been the","source of a");
Sterofin 4:af9d6e3b8a29 372 speech("lot of trouble","around here");
Sterofin 4:af9d6e3b8a29 373 speech("lately","");
Sterofin 4:af9d6e3b8a29 374 speech("Head up north","to find him");
Sterofin 4:af9d6e3b8a29 375 speech("but before you","go, you'll");
Sterofin 4:af9d6e3b8a29 376 speech("need this:","");
Sterofin 4:af9d6e3b8a29 377 Inventory.has_gun = true;
Sterofin 2:06c63d567719 378 return FULL_DRAW;
Sterofin 2:06c63d567719 379 }
Sterofin 2:06c63d567719 380 else if(checkType(TERMINAL))
Sterofin 2:06c63d567719 381 {
Sterofin 2:06c63d567719 382 if(story == 1){
Sterofin 2:06c63d567719 383 speech("Pondsmith:","~ksshhk~");
Sterofin 2:06c63d567719 384 speech("Nice, you're in.","Use the terminals");
Sterofin 2:06c63d567719 385 speech("to decypher the","BULLETCORP access");
Sterofin 2:06c63d567719 386 speech("codes. There are","4 codes. Each");
Sterofin 2:06c63d567719 387 speech("terminal will","give one of the");
Sterofin 2:06c63d567719 388 speech("access codes.","");
Sterofin 2:06c63d567719 389 uLCD.cls();
Sterofin 2:06c63d567719 390 puzzle = true;
Sterofin 2:06c63d567719 391 uLCD.locate(mx,my);
Sterofin 2:06c63d567719 392 uLCD.printf(" - - - - ");
Sterofin 2:06c63d567719 393 speech("Ok, here is","the first string");
Sterofin 2:06c63d567719 394 run_minigame();
Sterofin 2:06c63d567719 395 story++;
Sterofin 2:06c63d567719 396 if((boi = find_type(TERMINAL))){
Sterofin 2:06c63d567719 397 boi->type = HACKED_TERMINAL;
Sterofin 2:06c63d567719 398 boi->draw = draw_hacked_terminal;
Sterofin 2:06c63d567719 399 }
Sterofin 2:06c63d567719 400 puzzle = false;
Sterofin 2:06c63d567719 401 return FULL_DRAW;
Sterofin 2:06c63d567719 402 }
Sterofin 2:06c63d567719 403 else if(story == 2){
Sterofin 2:06c63d567719 404 uLCD.cls();
Sterofin 2:06c63d567719 405 puzzle = true;
Sterofin 2:06c63d567719 406 uLCD.locate(mx,my);
Sterofin 2:06c63d567719 407 uLCD.printf(" - - - - ");
Sterofin 2:06c63d567719 408 speech("Ok, here is","the second string");
Sterofin 2:06c63d567719 409 run_minigame();
Sterofin 2:06c63d567719 410 story++;
Sterofin 2:06c63d567719 411 if((boi = find_type(TERMINAL))){
Sterofin 2:06c63d567719 412 boi->type = HACKED_TERMINAL;
Sterofin 2:06c63d567719 413 boi->draw = draw_hacked_terminal;
Sterofin 2:06c63d567719 414 }
Sterofin 2:06c63d567719 415 puzzle = false;
Sterofin 2:06c63d567719 416 return FULL_DRAW;
Sterofin 2:06c63d567719 417 }
Sterofin 2:06c63d567719 418 else if(story == 3){
Sterofin 2:06c63d567719 419 uLCD.cls();
Sterofin 2:06c63d567719 420 puzzle = true;
Sterofin 2:06c63d567719 421 uLCD.locate(mx,my);
Sterofin 2:06c63d567719 422 uLCD.printf(" - - - - ");
Sterofin 2:06c63d567719 423 speech("Ok, here is","the third string");
Sterofin 2:06c63d567719 424 run_minigame();
Sterofin 2:06c63d567719 425 story++;
Sterofin 2:06c63d567719 426 if((boi = find_type(TERMINAL))){
Sterofin 2:06c63d567719 427 boi->type = HACKED_TERMINAL;
Sterofin 2:06c63d567719 428 boi->draw = draw_hacked_terminal;
Sterofin 2:06c63d567719 429 }
Sterofin 2:06c63d567719 430 puzzle = false;
Sterofin 2:06c63d567719 431 return FULL_DRAW;
Sterofin 2:06c63d567719 432 }
Sterofin 2:06c63d567719 433 else if(story == 4){
Sterofin 2:06c63d567719 434 uLCD.cls();
Sterofin 2:06c63d567719 435 puzzle = true;
Sterofin 2:06c63d567719 436 uLCD.locate(mx,my);
Sterofin 2:06c63d567719 437 uLCD.printf(" - - - - ");
Sterofin 2:06c63d567719 438 speech("Ok, here is","the fourth string");
Sterofin 2:06c63d567719 439 run_minigame();
Sterofin 2:06c63d567719 440 story++;
Sterofin 2:06c63d567719 441 if((boi = find_type(TERMINAL))){
Sterofin 2:06c63d567719 442 boi->type = HACKED_TERMINAL;
Sterofin 2:06c63d567719 443 boi->draw = draw_hacked_terminal;
Sterofin 2:06c63d567719 444 }
Sterofin 2:06c63d567719 445 puzzle = false;
Sterofin 2:06c63d567719 446 return FULL_DRAW;
Sterofin 2:06c63d567719 447 }
Sterofin 2:06c63d567719 448 }
Sterofin 2:06c63d567719 449 else if(checkType(DOOR) && Player.has_key == true){
Sterofin 2:06c63d567719 450 if(boi = find_type(DOOR)) boi->walkable = true;
Sterofin 4:af9d6e3b8a29 451 return FULL_DRAW;
Sterofin 2:06c63d567719 452 }
Sterofin 2:06c63d567719 453 else if(checkType(TELEPORT)){
Sterofin 2:06c63d567719 454 Inventory.has_teleport = true;
Sterofin 4:af9d6e3b8a29 455 if(boi = find_type(TELEPORT))
Sterofin 4:af9d6e3b8a29 456 {
Sterofin 4:af9d6e3b8a29 457 boi->walkable = true;
Sterofin 4:af9d6e3b8a29 458 boi->draw = draw_nothing;
Sterofin 4:af9d6e3b8a29 459 boi->type = WALL;
Sterofin 4:af9d6e3b8a29 460 }
Sterofin 4:af9d6e3b8a29 461 return FULL_DRAW;
Sterofin 2:06c63d567719 462 }
Sterofin 2:06c63d567719 463 else if(checkType(KILL)){
Sterofin 2:06c63d567719 464 Inventory.has_gun = true;
Sterofin 4:af9d6e3b8a29 465 if(boi = find_type(KILL))
Sterofin 4:af9d6e3b8a29 466 {
Sterofin 4:af9d6e3b8a29 467 boi->walkable = true;
Sterofin 4:af9d6e3b8a29 468 boi->draw = draw_nothing;
Sterofin 4:af9d6e3b8a29 469 boi->type = WALL;
Sterofin 4:af9d6e3b8a29 470 }
Sterofin 4:af9d6e3b8a29 471 return FULL_DRAW;
Sterofin 2:06c63d567719 472 }
Sterofin 2:06c63d567719 473 else if(checkType(BOOTS)){
Sterofin 2:06c63d567719 474 Inventory.has_boots = true;
Sterofin 4:af9d6e3b8a29 475 Player.speed = 1;
Sterofin 4:af9d6e3b8a29 476 if(boi = find_type(BOOTS))
Sterofin 4:af9d6e3b8a29 477 {
Sterofin 4:af9d6e3b8a29 478 boi->walkable = true;
Sterofin 4:af9d6e3b8a29 479 boi->draw = draw_nothing;
Sterofin 4:af9d6e3b8a29 480 boi->type = WALL;
Sterofin 4:af9d6e3b8a29 481 }
Sterofin 4:af9d6e3b8a29 482 return FULL_DRAW;
Sterofin 2:06c63d567719 483 }
Sterofin 2:06c63d567719 484 else if(checkType(PRINTER)){
Sterofin 2:06c63d567719 485 Inventory.has_printer = true;
Sterofin 4:af9d6e3b8a29 486 if(boi = find_type(PRINTER))
Sterofin 4:af9d6e3b8a29 487 {
Sterofin 4:af9d6e3b8a29 488 boi->walkable = true;
Sterofin 4:af9d6e3b8a29 489 boi->draw = draw_nothing;
Sterofin 4:af9d6e3b8a29 490 boi->type = WALL;
Sterofin 4:af9d6e3b8a29 491 }
Sterofin 4:af9d6e3b8a29 492 return FULL_DRAW;
Sterofin 2:06c63d567719 493 }
Sterofin 2:06c63d567719 494 break;
Sterofin 2:06c63d567719 495 case MENU_BUTTON:
Sterofin 2:06c63d567719 496 pc.printf("Menu Button Pressed\r\n");
Sterofin 4:af9d6e3b8a29 497 item_menu();
Sterofin 2:06c63d567719 498 break;
Sterofin 2:06c63d567719 499 case BUTTON_4:
Sterofin 2:06c63d567719 500 pc.printf("Button 4 Pressed\r\n");
Sterofin 2:06c63d567719 501 //NVIC_SystemReset();
Sterofin 2:06c63d567719 502 break;
rconnorlawson 0:35660d7952f7 503 default: break;
rconnorlawson 0:35660d7952f7 504 }
rconnorlawson 0:35660d7952f7 505 return NO_RESULT;
rconnorlawson 0:35660d7952f7 506 }
rconnorlawson 0:35660d7952f7 507
rconnorlawson 0:35660d7952f7 508 /**
rconnorlawson 0:35660d7952f7 509 * Entry point for frame drawing. This should be called once per iteration of
rconnorlawson 0:35660d7952f7 510 * the game loop. This draws all tiles on the screen, followed by the status
rconnorlawson 0:35660d7952f7 511 * bars. Unless init is nonzero, this function will optimize drawing by only
rconnorlawson 0:35660d7952f7 512 * drawing tiles that have changed from the previous frame.
rconnorlawson 0:35660d7952f7 513 */
rconnorlawson 0:35660d7952f7 514 void draw_game(int init)
rconnorlawson 0:35660d7952f7 515 {
rconnorlawson 0:35660d7952f7 516 // Draw game border first
rconnorlawson 0:35660d7952f7 517 if(init) draw_border();
rconnorlawson 0:35660d7952f7 518
rconnorlawson 0:35660d7952f7 519 // Iterate over all visible map tiles
rconnorlawson 0:35660d7952f7 520 for (int i = -5; i <= 5; i++) // Iterate over columns of tiles
rconnorlawson 0:35660d7952f7 521 {
rconnorlawson 0:35660d7952f7 522 for (int j = -4; j <= 4; j++) // Iterate over one column of tiles
rconnorlawson 0:35660d7952f7 523 {
rconnorlawson 0:35660d7952f7 524 // Here, we have a given (i,j)
rconnorlawson 0:35660d7952f7 525
rconnorlawson 0:35660d7952f7 526 // Compute the current map (x,y) of this tile
rconnorlawson 0:35660d7952f7 527 int x = i + Player.x;
rconnorlawson 0:35660d7952f7 528 int y = j + Player.y;
rconnorlawson 0:35660d7952f7 529
rconnorlawson 0:35660d7952f7 530 // Compute the previous map (px, py) of this tile
rconnorlawson 0:35660d7952f7 531 int px = i + Player.px;
rconnorlawson 0:35660d7952f7 532 int py = j + Player.py;
rconnorlawson 0:35660d7952f7 533
rconnorlawson 0:35660d7952f7 534 // Compute u,v coordinates for drawing
rconnorlawson 0:35660d7952f7 535 int u = (i+5)*11 + 3;
rconnorlawson 0:35660d7952f7 536 int v = (j+4)*11 + 15;
rconnorlawson 0:35660d7952f7 537
rconnorlawson 0:35660d7952f7 538 // Figure out what to draw
rconnorlawson 0:35660d7952f7 539 DrawFunc draw = NULL;
Sterofin 2:06c63d567719 540 if (i == 0 && j == 0) // Only draw the player on init
rconnorlawson 0:35660d7952f7 541 {
rconnorlawson 0:35660d7952f7 542 draw_player(u, v, Player.has_key);
rconnorlawson 0:35660d7952f7 543 continue;
rconnorlawson 0:35660d7952f7 544 }
rconnorlawson 0:35660d7952f7 545 else if (x >= 0 && y >= 0 && x < map_width() && y < map_height()) // Current (i,j) in the map
rconnorlawson 0:35660d7952f7 546 {
rconnorlawson 0:35660d7952f7 547 MapItem* curr_item = get_here(x, y);
rconnorlawson 0:35660d7952f7 548 MapItem* prev_item = get_here(px, py);
rconnorlawson 0:35660d7952f7 549 if (init || curr_item != prev_item) // Only draw if they're different
rconnorlawson 0:35660d7952f7 550 {
rconnorlawson 0:35660d7952f7 551 if (curr_item) // There's something here! Draw it
rconnorlawson 0:35660d7952f7 552 {
rconnorlawson 0:35660d7952f7 553 draw = curr_item->draw;
rconnorlawson 0:35660d7952f7 554 }
rconnorlawson 0:35660d7952f7 555 else // There used to be something, but now there isn't
rconnorlawson 0:35660d7952f7 556 {
rconnorlawson 0:35660d7952f7 557 draw = draw_nothing;
rconnorlawson 0:35660d7952f7 558 }
rconnorlawson 0:35660d7952f7 559 }
rconnorlawson 0:35660d7952f7 560 }
rconnorlawson 0:35660d7952f7 561 else if (init) // If doing a full draw, but we're out of bounds, draw the walls.
rconnorlawson 0:35660d7952f7 562 {
rconnorlawson 0:35660d7952f7 563 draw = draw_wall;
rconnorlawson 0:35660d7952f7 564 }
rconnorlawson 0:35660d7952f7 565
rconnorlawson 0:35660d7952f7 566 // Actually draw the tile
rconnorlawson 0:35660d7952f7 567 if (draw) draw(u, v);
rconnorlawson 0:35660d7952f7 568 }
rconnorlawson 0:35660d7952f7 569 }
rconnorlawson 0:35660d7952f7 570
Sterofin 2:06c63d567719 571 // Draw status bars
Sterofin 2:06c63d567719 572 draw_upper_status(Player.x,Player.y);
Sterofin 4:af9d6e3b8a29 573 uLCD.color(0xFFD700);
Sterofin 4:af9d6e3b8a29 574 draw_lower_status(Player.money);
Sterofin 4:af9d6e3b8a29 575 uLCD.color(GREEN);
rconnorlawson 0:35660d7952f7 576 }
rconnorlawson 0:35660d7952f7 577
rconnorlawson 0:35660d7952f7 578
rconnorlawson 0:35660d7952f7 579 /**
rconnorlawson 0:35660d7952f7 580 * Initialize the main world map. Add walls around the edges, interior chambers,
rconnorlawson 0:35660d7952f7 581 * and plants in the background so you can see motion.
rconnorlawson 0:35660d7952f7 582 */
rconnorlawson 0:35660d7952f7 583 void init_main_map()
rconnorlawson 0:35660d7952f7 584 {
rconnorlawson 0:35660d7952f7 585 Map* map = set_active_map(0);
rconnorlawson 0:35660d7952f7 586
rconnorlawson 0:35660d7952f7 587 pc.printf("Adding walls!\r\n");
rconnorlawson 0:35660d7952f7 588 add_wall(0, 0, HORIZONTAL, map_width());
rconnorlawson 0:35660d7952f7 589 add_wall(0, map_height()-1, HORIZONTAL, map_width());
rconnorlawson 0:35660d7952f7 590 add_wall(0, 0, VERTICAL, map_height());
rconnorlawson 0:35660d7952f7 591 add_wall(map_width()-1, 0, VERTICAL, map_height());
Sterofin 2:06c63d567719 592
Sterofin 2:06c63d567719 593
Sterofin 2:06c63d567719 594 add_wall(0,38,HORIZONTAL,4);
Sterofin 2:06c63d567719 595 add_wall(6,38,HORIZONTAL,15);
Sterofin 2:06c63d567719 596 add_wall(0,29,HORIZONTAL,2);
Sterofin 2:06c63d567719 597 add_wall(4,29,HORIZONTAL,26);
Sterofin 2:06c63d567719 598 add_door(2,29,false);
Sterofin 2:06c63d567719 599 add_door(3,29,false);
Sterofin 2:06c63d567719 600 add_boots(3,22);
Sterofin 2:06c63d567719 601 add_teleport(5,24);
Sterofin 2:06c63d567719 602 add_orgprint(8,21);
Sterofin 2:06c63d567719 603 add_kill(15,19);
Sterofin 2:06c63d567719 604 add_wall(0,17,HORIZONTAL,40);
Sterofin 2:06c63d567719 605 add_wall(0,13,HORIZONTAL,2);
Sterofin 2:06c63d567719 606 add_door(2,13,false);
Sterofin 2:06c63d567719 607 add_door(3,13,false);
Sterofin 2:06c63d567719 608 add_wall(4,13,HORIZONTAL,36);
Sterofin 2:06c63d567719 609 add_wall(39,0,VERTICAL,13);
Sterofin 2:06c63d567719 610 add_wall(11,0,VERTICAL,13);
Sterofin 2:06c63d567719 611 add_wall(39,17,VERTICAL,13);
Sterofin 2:06c63d567719 612 add_wall(39,38,VERTICAL,12);
Sterofin 2:06c63d567719 613 add_wall(26,38,VERTICAL,10);
Sterofin 2:06c63d567719 614 add_wall(21,38,VERTICAL,4);
Sterofin 2:06c63d567719 615 add_wall(21,44,VERTICAL,5);
Sterofin 2:06c63d567719 616 add_wall(31,38,HORIZONTAL,9);
Sterofin 2:06c63d567719 617 add_wall(27,38,HORIZONTAL,2);
Sterofin 2:06c63d567719 618 add_netPortal(38,44);
Sterofin 2:06c63d567719 619 add_NPC(5,42);
rconnorlawson 0:35660d7952f7 620 pc.printf("Walls done!\r\n");
rconnorlawson 0:35660d7952f7 621
Sterofin 2:06c63d567719 622 //print_map();
Sterofin 2:06c63d567719 623 }
Sterofin 2:06c63d567719 624
Sterofin 2:06c63d567719 625 void init_sub_map()
Sterofin 2:06c63d567719 626 {
Sterofin 2:06c63d567719 627 set_active_map(1);
Sterofin 2:06c63d567719 628 pc.printf("Adding walls!\r\n");
Sterofin 2:06c63d567719 629 add_wall(0, 0, HORIZONTAL, map_width());
Sterofin 2:06c63d567719 630 add_wall(0, map_height()-1, HORIZONTAL, map_width());
Sterofin 2:06c63d567719 631 add_wall(0, 0, VERTICAL, map_height());
Sterofin 2:06c63d567719 632 add_wall(map_width()-1, 0, VERTICAL, map_height());
Sterofin 2:06c63d567719 633 add_terminal(3,3);
Sterofin 2:06c63d567719 634 add_terminal(7,3);
Sterofin 2:06c63d567719 635 add_terminal(3,7);
Sterofin 2:06c63d567719 636 add_terminal(7,7);
Sterofin 2:06c63d567719 637 add_netPortal(1,5);
rconnorlawson 0:35660d7952f7 638 }
rconnorlawson 0:35660d7952f7 639
rconnorlawson 0:35660d7952f7 640 /**
rconnorlawson 0:35660d7952f7 641 * Program entry point! This is where it all begins.
rconnorlawson 0:35660d7952f7 642 * This function orchestrates all the parts of the game. Most of your
rconnorlawson 0:35660d7952f7 643 * implementation should be elsewhere - this holds the game loop, and should
rconnorlawson 0:35660d7952f7 644 * read like a road map for the rest of the code.
rconnorlawson 0:35660d7952f7 645 */
Sterofin 2:06c63d567719 646
Sterofin 2:06c63d567719 647
Sterofin 2:06c63d567719 648
rconnorlawson 0:35660d7952f7 649 int main()
rconnorlawson 0:35660d7952f7 650 {
rconnorlawson 0:35660d7952f7 651 // First things first: initialize hardware
rconnorlawson 0:35660d7952f7 652 ASSERT_P(hardware_init() == ERROR_NONE, "Hardware init failed!");
Sterofin 2:06c63d567719 653 //hardware_init();
Sterofin 2:06c63d567719 654 pc.printf("Initializing Game\r\n");
Sterofin 2:06c63d567719 655 in = read_inputs();
Sterofin 2:06c63d567719 656 actions = get_action(in);
Sterofin 2:06c63d567719 657 uLCD.text_width(2); //4X size text
Sterofin 2:06c63d567719 658 uLCD.text_height(2);
Sterofin 2:06c63d567719 659 uLCD.color(0x00ffd8);
Sterofin 2:06c63d567719 660 uLCD.set_font(FONT_5X7);
Sterofin 2:06c63d567719 661 uLCD.text_bold(true);
Sterofin 2:06c63d567719 662 uLCD.printf("\n\n N E O\n");
Sterofin 2:06c63d567719 663 uLCD.color(0xff00e4);
Sterofin 2:06c63d567719 664 uLCD.printf("\n P U N K\n");
Sterofin 2:06c63d567719 665 uLCD.text_width(1); //4X size text
Sterofin 2:06c63d567719 666 uLCD.text_height(1);
Sterofin 2:06c63d567719 667 uLCD.color(RED);
Sterofin 2:06c63d567719 668 bool swap = 0;
Sterofin 2:06c63d567719 669 int flash = 0;
Sterofin 2:06c63d567719 670 while(actions != ACTION_BUTTON)
Sterofin 2:06c63d567719 671 {
Sterofin 2:06c63d567719 672 if(flash >= 600){
Sterofin 2:06c63d567719 673 swap = !swap;
Sterofin 2:06c63d567719 674 flash = 0;
Sterofin 2:06c63d567719 675 if(swap) draw_menu_2();
Sterofin 2:06c63d567719 676 else if(!swap) draw_menu_1();
Sterofin 2:06c63d567719 677 }
Sterofin 2:06c63d567719 678 if(swap) flash+=3;
Sterofin 2:06c63d567719 679 else if(!swap) flash++;
Sterofin 2:06c63d567719 680
Sterofin 2:06c63d567719 681
Sterofin 2:06c63d567719 682 in = read_inputs();
Sterofin 2:06c63d567719 683 actions = get_action(in);
Sterofin 2:06c63d567719 684 }
Sterofin 2:06c63d567719 685 uLCD.cls();
Sterofin 2:06c63d567719 686 uLCD.text_width(1); //4X size text
Sterofin 2:06c63d567719 687 uLCD.text_height(1);
Sterofin 2:06c63d567719 688 uLCD.color(GREEN);
Sterofin 2:06c63d567719 689 uLCD.set_font(FONT_7X8);
rconnorlawson 0:35660d7952f7 690 // Initialize the maps
rconnorlawson 0:35660d7952f7 691 maps_init();
rconnorlawson 0:35660d7952f7 692 init_main_map();
Sterofin 2:06c63d567719 693 init_sub_map();
Sterofin 2:06c63d567719 694 set_active_map(0);
Sterofin 2:06c63d567719 695 print_map();
Sterofin 2:06c63d567719 696 pc.printf("Map initialized\r\n");
rconnorlawson 0:35660d7952f7 697
rconnorlawson 0:35660d7952f7 698 // Initialize game state
Sterofin 2:06c63d567719 699 Player.x = 3;
Sterofin 2:06c63d567719 700 Player.y = 33;
Sterofin 2:06c63d567719 701 Player.speed = 1;
Sterofin 4:af9d6e3b8a29 702 Player.money = 0;
rconnorlawson 0:35660d7952f7 703 // Initial drawing
rconnorlawson 0:35660d7952f7 704 draw_game(true);
rconnorlawson 0:35660d7952f7 705
rconnorlawson 0:35660d7952f7 706 // Main game loop
rconnorlawson 0:35660d7952f7 707 while(1)
rconnorlawson 0:35660d7952f7 708 {
Sterofin 2:06c63d567719 709 //pc.printf("Game Running\r\n");
rconnorlawson 0:35660d7952f7 710 // Timer to measure game update speed
rconnorlawson 0:35660d7952f7 711 Timer t; t.start();
rconnorlawson 0:35660d7952f7 712
Sterofin 2:06c63d567719 713 // Actually do the game update:
Sterofin 2:06c63d567719 714 // 1. Read inputs
Sterofin 2:06c63d567719 715 in = read_inputs();
Sterofin 2:06c63d567719 716 //pc.printf("Gathering Sensor Data\r\n");
Sterofin 2:06c63d567719 717 // 2. Determine action (get_action)
Sterofin 2:06c63d567719 718 actions = get_action(in);
Sterofin 2:06c63d567719 719 //pc.printf("Determining Action\r\n");
rconnorlawson 0:35660d7952f7 720 // 3. Update game (update_game)
Sterofin 2:06c63d567719 721 update = update_game(actions);
Sterofin 2:06c63d567719 722 //pc.printf("Updating Game State\r\n");
Sterofin 2:06c63d567719 723 //pc.printf("Game State: %d\r\n", gameState);
rconnorlawson 0:35660d7952f7 724 // 3b. Check for game over
Sterofin 2:06c63d567719 725 //if(update == 0) break;
rconnorlawson 0:35660d7952f7 726 // 4. Draw frame (draw_game)
Sterofin 2:06c63d567719 727 //pc.printf("Drawing Game\r\n");
Sterofin 2:06c63d567719 728 draw_game(update);
rconnorlawson 0:35660d7952f7 729
rconnorlawson 0:35660d7952f7 730 // 5. Frame delay
rconnorlawson 0:35660d7952f7 731 t.stop();
rconnorlawson 0:35660d7952f7 732 int dt = t.read_ms();
rconnorlawson 0:35660d7952f7 733 if (dt < 100) wait_ms(100 - dt);
Sterofin 2:06c63d567719 734
Sterofin 2:06c63d567719 735 if(story == 5){
Sterofin 2:06c63d567719 736 speech("Nice! You got","the codes.");
Sterofin 2:06c63d567719 737 speech("Come back to me","and i'll");
Sterofin 2:06c63d567719 738 speech("compile them into","a security chip");
Sterofin 2:06c63d567719 739 speech("you can use to","break into");
Sterofin 2:06c63d567719 740 speech("BULLETCORP","");
Sterofin 2:06c63d567719 741 story++;
Sterofin 2:06c63d567719 742 draw_game(FULL_DRAW);
Sterofin 2:06c63d567719 743 }
rconnorlawson 0:35660d7952f7 744 }
rconnorlawson 0:35660d7952f7 745 }