Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed wave_player 4DGL-uLCD-SE MMA8452
Diff: main.cpp
- Revision:
- 4:af9d6e3b8a29
- Parent:
- 3:664c79e2ceb5
- Child:
- 5:a16af8f3fea9
--- a/main.cpp Fri Nov 30 03:46:39 2018 +0000
+++ b/main.cpp Fri Nov 30 05:31:06 2018 +0000
@@ -40,6 +40,7 @@
int has_key;
int speed;
bool can_teleport;
+ int money;
} Player;
struct {
@@ -197,7 +198,7 @@
sprintf(buffer," %d - - - ",n[0]);
uLCD.printf(buffer);
solved++;
- wait(0.5);
+ wait(0.25);
}
}
else if(solved == 1){
@@ -206,7 +207,7 @@
sprintf(buffer," %d %d - - ",n[0],n[1]);
uLCD.printf(buffer);
solved++;
- wait(0.5);
+ wait(0.25);
}
}
else if(solved == 2){
@@ -215,7 +216,7 @@
sprintf(buffer," %d %d %d - ",n[0],n[1],n[2]);
uLCD.printf(buffer);
solved++;
- wait(0.5);
+ wait(0.25);
}
}
else if(solved == 3){
@@ -230,6 +231,38 @@
}
}
+void item_menu(){
+ uLCD.cls();
+ uLCD.printf(" INVENTORY");
+ if(Inventory.has_gun){
+ draw_gun(20,40);
+ uLCD.locate(35,40);
+ uLCD.printf("KillInator5000");
+ }
+ if(Inventory.has_printer){
+ draw_printer(20,55);
+ uLCD.locate(35,55);
+ uLCD.printf("Organ Printer");
+ }
+ if(Inventory.has_teleport){
+ draw_teleport(20,70);
+ uLCD.locate(35,70);
+ uLCD.printf("Teleporter");
+ }
+ if(Inventory.has_boots){
+ draw_boots(20,85);
+ uLCD.locate(35,85);
+ uLCD.printf("SpeedyBoots");
+ }
+ in = read_inputs();
+ actions = get_action(in);
+ draw_lower_status(Player.money);
+ while(actions != MENU_BUTTON){
+ in = read_inputs();
+ actions = get_action(in);
+ }
+}
+
/**
* Update the game state based on the user action. For example, if the user
* requests GO_UP, then this function should determine if that is possible by
@@ -311,7 +344,37 @@
speech("chip that will","let you into");
speech("BULLETCORP's","secret tech room");
Player.has_key = true;
+ story++;
}
+ else if(story == 7)
+ {
+ if(Inventory.has_gun && Inventory.has_printer) story++;
+ else{
+ speech("You don't have","everything, go");
+ speech("back and get","the rest of the");
+ speech("tech in order","to get paid");
+ }
+ }
+ else if(story == 8){
+ speech("Nice! Here's your","cash as");
+ speech("promised.","");
+ Inventory.has_printer = false;
+ Inventory.has_gun = false;
+ Player.money = 100;
+ story++;
+ }
+ else if(story == 9){
+ speech("I've got one","more job if");
+ speech("you want it.","");
+ speech("I need you to","take out the");
+ speech("leader of the","Gigem' Boys");
+ speech("He's been the","source of a");
+ speech("lot of trouble","around here");
+ speech("lately","");
+ speech("Head up north","to find him");
+ speech("but before you","go, you'll");
+ speech("need this:","");
+ Inventory.has_gun = true;
return FULL_DRAW;
}
else if(checkType(TERMINAL))
@@ -385,27 +448,53 @@
}
else if(checkType(DOOR) && Player.has_key == true){
if(boi = find_type(DOOR)) boi->walkable = true;
+ return FULL_DRAW;
}
else if(checkType(TELEPORT)){
Inventory.has_teleport = true;
- if(boi = find_type(TELEPORT)) map_erase(boi->x, boi->y);
+ if(boi = find_type(TELEPORT))
+ {
+ boi->walkable = true;
+ boi->draw = draw_nothing;
+ boi->type = WALL;
+ }
+ return FULL_DRAW;
}
else if(checkType(KILL)){
Inventory.has_gun = true;
- if(boi = find_type(KILL)) map_erase(boi->x, boi->y);
+ if(boi = find_type(KILL))
+ {
+ boi->walkable = true;
+ boi->draw = draw_nothing;
+ boi->type = WALL;
+ }
+ return FULL_DRAW;
}
else if(checkType(BOOTS)){
Inventory.has_boots = true;
- Player.speed = 2;
- if(boi = find_type(BOOTS)) map_erase(boi->x, boi->y);
+ Player.speed = 1;
+ if(boi = find_type(BOOTS))
+ {
+ boi->walkable = true;
+ boi->draw = draw_nothing;
+ boi->type = WALL;
+ }
+ return FULL_DRAW;
}
else if(checkType(PRINTER)){
Inventory.has_printer = true;
- if(boi = find_type(PRINTER)) map_erase(boi->x, boi->y);
+ if(boi = find_type(PRINTER))
+ {
+ boi->walkable = true;
+ boi->draw = draw_nothing;
+ boi->type = WALL;
+ }
+ return FULL_DRAW;
}
break;
case MENU_BUTTON:
pc.printf("Menu Button Pressed\r\n");
+ item_menu();
break;
case BUTTON_4:
pc.printf("Button 4 Pressed\r\n");
@@ -481,7 +570,9 @@
// Draw status bars
draw_upper_status(Player.x,Player.y);
- draw_lower_status();
+ uLCD.color(0xFFD700);
+ draw_lower_status(Player.money);
+ uLCD.color(GREEN);
}
@@ -608,6 +699,7 @@
Player.x = 3;
Player.y = 33;
Player.speed = 1;
+ Player.money = 0;
// Initial drawing
draw_game(true);