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:
- 9:3cad581b5419
- Parent:
- 8:ee857f0147aa
- Child:
- 10:59c874d006ab
--- a/main.cpp Fri Apr 17 14:27:13 2015 +0000 +++ b/main.cpp Sun Apr 19 15:56:31 2015 +0000 @@ -42,12 +42,12 @@ //Variables -int buttonFlagA = 0; -int buttonFlagS = 0; -int buttonFlagU = 0; -int buttonFlagD = 0; -int buttonFlagL = 0; -int buttonFlagR = 0; +int ActFlag = 0; +int StartFlag = 0; +int UpFlag = 0; +int DownFlag = 0; +int LeftFlag = 0; +int RightFlag = 0; int map[84][48]; @@ -82,27 +82,27 @@ //ISR void ActPressed() { - buttonFlagA = 0; + ActFlag = 1; } void StartPressed() { - buttonFlagS = 0; + StartFlag = 1; } void UpPressed() { - buttonFlagU = 0; + UpFlag= 1; } void DownPressed() { - buttonFlagD = 0; + DownFlag = 1; } void LeftPressed() { - buttonFlagL = 0; + LeftFlag = 1; } void RightPressed() { - buttonFlagR = 0; + RightFlag = 1; } void Walls() @@ -126,18 +126,31 @@ } } +void FlashPlayerLocation() +{ + + lcd.setPixel(px,py); + lcd.refresh(); + wait(0.5); + lcd.clearPixel(px,py); + lcd.refresh(); + wait(0.5); + +} + void DrawMap() { //Draw map on screen for(int i=0; i<84; i++) { for (int j=0; j<48; j++) { - if(map[i][j] == FLOOR) { + if(map[i][j] == FLOOR || map[i][j] == EXIT) { lcd.clearPixel(i, j); } else { lcd.setPixel(i, j); } } } + lcd.refresh(); } @@ -264,6 +277,21 @@ } } +void RandFloor(int r) +{ + + for(int space = rand()%50 + r; space > 0; space--) { + + int i = rand()% 84; + int j = rand()% 48; + + if(rand()%2 == 0 && map[i][j] == WALL) { + map[i][j] = FLOOR; + } + } + +} + void Maze() { for(int i = 0; i < 84; i+=2) { @@ -284,21 +312,6 @@ } } } - - for(int space = rand()%50 + 51; space > 0; space--) { - - int i = rand()% 84; - int j = rand()% 48; - - if(rand()%2 == 0 && map[i][j] == WALL) { - map[i][j] = FLOOR; - } - } - - Border(); - - DeadEnds(); - } void DungeonBuilder() @@ -307,36 +320,50 @@ FirstRoom(); ExitRoom(); - int rn = rand()%20 + 20; + int rn = rand()%20 + 10; for(int i = rn; i>0; i--) { DungeonRoomBuilder(); } + Maze(); + RandFloor(51); + + Border(); + + DeadEnds(); + +} + +void LabyrinthBuilder() +{ + + FirstRoom(); + ExitRoom(); DrawMap(); wait(2.0); Maze(); + RandFloor(551); + + Border(); + } void World() { Walls(); +//LabyrinthBuilder(); DungeonBuilder(); - DrawMap(); - px = enx; py = eny; wait(1.0); - - - } void PlayerCamera() @@ -351,12 +378,14 @@ if(i == 6 && j == 2) { lcd.printString("@", (6*i)+1, j); } else { - int diffx = i - 6; int diffy = j - 2; - tile = map[px+diffx][py+diffy]; - + if(px+diffx < 84 && px+diffx > 0 && py+diffy < 48 && py+diffy > 0) { + tile = map[px+diffx][py+diffy]; + } else { + tile = WALL; + } lcd.printChar(TileList[tile].Symbol, (6*i)+1, j); } } @@ -367,8 +396,6 @@ void PlayerMove() { - - if(Up) { int tile = map[px][py-1]; if(TileList[tile].Passable) { @@ -394,8 +421,22 @@ } } + } +void StartMenu() +{ + + if(Start) { + lcd.clear(); + DrawMap(); + while(!StartFlag) { + FlashPlayerLocation(); + } + StartFlag = 0; + } + +} int main() { @@ -403,6 +444,14 @@ PHY_PowerDown (); int result = semihost_powerdown(); + Up.rise(&UpPressed); + Down.rise(&DownPressed); + Right.rise(&RightPressed); + Left.rise(&LeftPressed); + Start.rise(&StartPressed); + + + //Generate random seed srand(Noise*1000000); @@ -415,8 +464,23 @@ while(1) { PlayerCamera(); - PlayerMove(); - wait(0.5); + Sleep(); + if(UpFlag || DownFlag || RightFlag || LeftFlag) { + + UpFlag = 0; + DownFlag = 0; + RightFlag = 0; + LeftFlag = 0; + + PlayerMove(); + } + if(StartFlag) { + + StartFlag = 0; + + StartMenu(); + + } } } \ No newline at end of file