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: N5110 PowerControl mbed
Diff: main.cpp
- Revision:
- 12:30a242706847
- Parent:
- 11:b86a15d26de9
- Child:
- 13:2195ec8bc9ff
--- a/main.cpp Sat Apr 25 11:10:06 2015 +0000 +++ b/main.cpp Sat Apr 25 14:35:27 2015 +0000 @@ -20,6 +20,8 @@ #define ENTER 2 #define EXIT 3 #define FLOOR_SEEN 4 +#define CHEST 5 +#define CHEST_OPENED 6 #define RIGHT 0 #define LEFT 1 @@ -40,6 +42,18 @@ { '+', true }, // 2- ENTER { 'x', true }, // 3- EXIT { '.', true}, // 4- FLOOR_SEEN + { '=', true}, // 5- CHEST + { '/', true}, // 6- CHEST_OPENED +}; + +struct ITEMS { + char ItemName[14]; // Symbol for this tile + bool isWeapon; // Can tile be walked on +}; + +ITEMS ItemList[] = { + { "Sword", true }, // + //{ 'Sword', true}, // }; @@ -64,8 +78,6 @@ int n; -bool menu; - int level; //Space type player is on @@ -136,7 +148,7 @@ //Draw map on screen for(int i=0; i<84; i++) { for (int j=0; j<48; j++) { - if(map[i][j] == FLOOR_SEEN) { + if(map[i][j] == FLOOR_SEEN || map[i][j] == CHEST_OPENED) { lcd.clearPixel(i, j); } else { lcd.setPixel(i, j); @@ -215,6 +227,11 @@ } } } + if(rand()%2) { + int i = rand()%sw + sx; + int j = rand()%sh + sy; + map[i][j] = CHEST; + } } void Neighbours() @@ -346,9 +363,11 @@ void World() { Walls(); - - //LabyrinthBuilder(); - DungeonBuilder(); + if(level == 5) { + LabyrinthBuilder(); + } else { + DungeonBuilder(); + } px = enx; py = eny; @@ -385,7 +404,6 @@ } } } - lcd.refresh(); } @@ -442,8 +460,9 @@ void LevelScreen() { - char buffer[1]; - int length = sprintf(buffer,"Level %d",level); // print formatted data to buffer + char buffer[14]; + + int write = sprintf(buffer,"Level %d",level); // print formatted data to buffer lcd.clear(); lcd.printString(buffer, 20, 2); @@ -452,6 +471,42 @@ } +void Chest() +{ + + DirFlag = 0; + + lcd.clear(); + lcd.printString("Do you want to", 0, 1); + lcd.printString("take the", 0, 2); + lcd.printString(ItemList[0].ItemName, 54, 2); + lcd.printString("-Yes (Action)", 0, 3); + lcd.printString("-No (Other)", 0, 4); + lcd.refresh(); + Sleep(); + + + if(ActFlag) { + + ActFlag = 0; + + lcd.clear(); + lcd.printString("You take the", 6, 1); + lcd.printString(ItemList[0].ItemName, 24, 2); + lcd.refresh(); + } + if(DirFlag) { + + DirFlag = 0; + + lcd.clear(); + lcd.printString("You leave the", 3, 1); + lcd.printString(ItemList[0].ItemName, 24, 2); + lcd.refresh(); + } + map[px][py] = CHEST_OPENED; +} + void GameLoop() { while(1) { @@ -466,6 +521,17 @@ while(1) { PlayerCamera(); + + if(map[px][py] == CHEST) { + Chest(); + } + + if(px == exx && py == exy) { + + break; + + } + Sleep(); @@ -481,17 +547,13 @@ StartMenu(); } - if(px == exx && py == exy) { - - break; - - } } } } void MainMenu() { + bool menu = 0; while(1) { lcd.clear();