
Labyrinth of the Minotaur A simple roguelike/RPG using a nokia 5110 screen
Dependencies: N5110 PowerControl mbed
Revision 32:99ca304085e6, committed 2015-05-10
- Comitter:
- ThomasBGill
- Date:
- Sun May 10 22:25:19 2015 +0000
- Parent:
- 31:5b4a4d225ab4
- Child:
- 33:4fc26476b2e0
- Commit message:
- Chest items fixed
Changed in this revision
Game.cpp | Show annotated file Show diff for this revision Revisions of this file |
Game.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/Game.cpp Sat May 09 17:37:40 2015 +0000 +++ b/Game.cpp Sun May 10 22:25:19 2015 +0000 @@ -16,12 +16,6 @@ { StartFlag = 1; } -/* -void DirPressed() -{ - DirFlag = 1; -} -*/ //Joystick functions // read default positions of the joystick to calibrate later readings @@ -45,9 +39,9 @@ if ( fabs(joystick.y) < DIRECTION_TOLERANCE && fabs(joystick.x) < DIRECTION_TOLERANCE) { joystick.direction = Centre; } else if ( joystick.y > DIRECTION_TOLERANCE && fabs(joystick.x) < DIRECTION_TOLERANCE) { - joystick.direction = Up; + joystick.direction = Down; } else if ( joystick.y < DIRECTION_TOLERANCE && fabs(joystick.x) < DIRECTION_TOLERANCE) { - joystick.direction = Down; + joystick.direction = Up; } else if ( joystick.x > DIRECTION_TOLERANCE && fabs(joystick.y) < DIRECTION_TOLERANCE) { joystick.direction = Right; } else if ( joystick.x < DIRECTION_TOLERANCE && fabs(joystick.y) < DIRECTION_TOLERANCE) { @@ -103,7 +97,6 @@ } //Graphic functions - void DrawGraphic(int p, int y, int x) { @@ -185,27 +178,29 @@ int menu = 0; while (1) { + + ActFlag = 0; + lcd.clear(); if (menu == 0) { lcd.printString("New Game <", 6, 1); lcd.printString("High Scores", 6, 2); lcd.printString("Options", 6, 3); lcd.refresh(); - Sleep(); } else if (menu == 1) { lcd.printString("New Game", 6, 1); lcd.printString("High Scores <", 6, 2); lcd.printString("Options", 6, 3); lcd.refresh(); - Sleep(); } else { lcd.printString("New Game", 6, 1); lcd.printString("High Scores", 6, 2); lcd.printString("Options <", 6, 3); lcd.refresh(); - Sleep(); } + Sleep(); + if (joystick.direction == Up) { if(menu > 0) { menu--; @@ -248,7 +243,7 @@ } lcd.refresh(); - + if (joystick.direction != Centre) { bright = !bright; @@ -292,9 +287,9 @@ //RevealMap(); //Uncomment for debugging to view map -srand(Noise * 1000000); + srand(Noise * 1000000); -PlayerCamera(); + PlayerCamera(); while (1) { @@ -327,21 +322,23 @@ if (ph < PH_MAX) { ph++; } - - PlayerCamera(); - + } if (rand() % 50 == 0) { Fight(); } + PlayerCamera(); + } if (StartFlag) { StartFlag = 0; StartMenu(); + + PlayerCamera(); } if (ActFlag) { @@ -385,25 +382,25 @@ void PlayerMove() { - if (Up) { + if (joystick.direction == Up) { int tile = map[px][py - 1]; if (TileList[tile].Passable) { py--; } } - if (Down) { + if (joystick.direction == Down) { int tile = map[px][py + 1]; if (TileList[tile].Passable) { py++; } } - if (Right) { + if (joystick.direction == Right) { int tile = map[px + 1][py]; if (TileList[tile].Passable) { px++; } } - if (Left) { + if (joystick.direction == Left) { int tile = map[px - 1][py]; if (TileList[tile].Passable) { px--; @@ -446,7 +443,7 @@ lcd.clear(); lcd.printString(EnemyList[m].EName, 0, 0); lcd.printString(buffer1, 54, 0); - DrawGraphic(m, 23, 6); + DrawGraphic(m, 23, 7); lcd.refresh(); wait(2.0); @@ -497,7 +494,7 @@ write = sprintf(damBuffer,"-%d", damage); lcd.clear(); - DrawGraphic(m, 23, 6); + DrawGraphic(m, 23, 7); lcd.printString(damBuffer, 62, 2); FlashScreen(3); @@ -818,39 +815,42 @@ lcd.printString("take the", 0, 2); lcd.printString(ItemList[r].ItemName, 0, 3); lcd.printString("-Yes (Action)", 0, 4); - lcd.printString("-No (Other)", 0, 5); + lcd.printString("-No (Start)", 0, 5); lcd.refresh(); wait(1.0); - Sleep(); - - if (ActFlag) { - - ActFlag = 0; - - if (r > 5) { - pa = r; - } else { - pw = r; - } - - lcd.clear(); - lcd.printString("You take the", 0, 1); - lcd.printString(ItemList[r].ItemName, 0, 2); - lcd.refresh(); - wait(1.0); + while(1) { Sleep(); - } else { + if (ActFlag) { + + ActFlag = 0; + + if (r > 5) { + pa = r; + } else { + pw = r; + } - StartFlag = 0; - - lcd.clear(); - lcd.printString("You leave the", 0, 1); - lcd.printString(ItemList[r].ItemName, 0, 2); - lcd.refresh(); - wait(1.0); - Sleep(); + lcd.clear(); + lcd.printString("You take the", 0, 1); + lcd.printString(ItemList[r].ItemName, 0, 2); + lcd.refresh(); + wait(1.0); + Sleep(); + + } + if(StartFlag) { + + StartFlag = 0; + + lcd.clear(); + lcd.printString("You leave the", 0, 1); + lcd.printString(ItemList[r].ItemName, 0, 2); + lcd.refresh(); + wait(1.0); + Sleep(); + } } } @@ -1028,7 +1028,6 @@ void HighScoreScreen() { - HighScoreCheck(); //readDataFromFile(); @@ -1053,10 +1052,15 @@ lcd.printString(buffer4, 6, 5); lcd.refresh(); wait(1.0); - Sleep(); + + while(1) { + Sleep(); - MainMenu(); - + if(ActFlag) { + ActFlag = 0; + MainMenu(); + } + } } int main()
--- a/Game.h Sat May 09 17:37:40 2015 +0000 +++ b/Game.h Sun May 10 22:25:19 2015 +0000 @@ -4,20 +4,16 @@ #include "WorldBuilder.h" #include "Graphics.h" -#define PH_MAX 20 - -// vcc sce rst dc mosi clk led +// vcc sce rst dc mosi clk led N5110 lcd(p7, p8, p9, p10, p11, p13, p26); InterruptIn Act(p27); InterruptIn Start(p28); -//InterruptIn Up(p25); -//InterruptIn Down(p24); -//InterruptIn Left(p22); -//InterruptIn Right(p21); AnalogIn Noise(p19); AnalogIn xPot(p15); AnalogIn yPot(p16); +#define PH_MAX 20 + //Joystick stuff // timer to regularly read the joystick Ticker pollJoystick;