
Labyrinth of the Minotaur A simple roguelike/RPG using a nokia 5110 screen
Dependencies: N5110 PowerControl mbed
Revision 34:e58c8322884d, committed 2015-05-11
- Comitter:
- ThomasBGill
- Date:
- Mon May 11 12:56:26 2015 +0000
- Parent:
- 33:4fc26476b2e0
- Child:
- 35:2c290fa78f1d
- Commit message:
- Game.h function commenting finished
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 Mon May 11 12:19:13 2015 +0000 +++ b/Game.cpp Mon May 11 12:56:26 2015 +0000 @@ -283,21 +283,28 @@ wait(1.0); } +void NextLevel() +{ + + level++; + + score = score + 100; + + World(); + + LevelScreen(); + + //RevealMap(); //Uncomment for debugging to view map + + srand(Noise * 1000000); + +} + void GameLoop() { while (1) { - level++; - - score = score + 100; - - World(); - - LevelScreen(); - - //RevealMap(); //Uncomment for debugging to view map - - srand(Noise * 1000000); + NextLevel(); PlayerCamera(); @@ -443,7 +450,7 @@ m = rand() % mr; } - int mh = EnemyList[m].EHealth; + mh = EnemyList[m].EHealth; FlashScreen(5); @@ -491,44 +498,8 @@ if (ActFlag) { ActFlag = 0; if (menu) { //Fight - //Hit monster - if (rand() % 100 + 1 > EnemyList[m].EDodge) { //If monster doesn't dodge - int damage = ItemList[pw].ItemValue - EnemyList[m].EArmour + rand() % 3 - rand() % 3; //Calculate damage - if (damage < 0) { - damage = 0; - } - mh = mh - damage; //Apply damage and calculate the monster's health - - char damBuffer[14]; - write = sprintf(damBuffer,"-%d", damage); - - lcd.clear(); - DrawGraphic(m, 23, 7); - lcd.printString(damBuffer, 62, 2); - FlashScreen(3); - - - char buffer3[14]; - write = sprintf(buffer3, "for %d damage", damage); // print formatted data to buffer - - lcd.clear(); - lcd.printString("You hit the", 0, 1); - lcd.printString(EnemyList[m].EName, 0, 2); - lcd.printString(buffer3, 0, 3); - lcd.refresh(); - wait(1.0); - Sleep(); - - } else { //Monster dodges - lcd.clear(); - lcd.printString(EnemyList[m].EName, 0, 1); - lcd.printString("dodges your", 0, 2); - lcd.printString("attack", 0, 3); - lcd.refresh(); - wait(1.0); - Sleep(); - } + PlayerAttack(m); if (mh <= 0) { //Check if monster is dead score = score + EnemyList[m].EPoints; @@ -598,6 +569,49 @@ } } +void PlayerAttack(int m) +{ + + //Hit monster + if (rand() % 100 + 1 > EnemyList[m].EDodge) { //If monster doesn't dodge + + int damage = ItemList[pw].ItemValue - EnemyList[m].EArmour + rand() % 3 - rand() % 3; //Calculate damage + if (damage < 0) { + damage = 0; + } + mh = mh - damage; //Apply damage and calculate the monster's health + + char damBuffer[14]; + int write = sprintf(damBuffer,"-%d", damage); + + lcd.clear(); + DrawGraphic(m, 23, 7); + lcd.printString(damBuffer, 62, 2); + FlashScreen(3); + + + char buffer3[14]; + write = sprintf(buffer3, "for %d damage", damage); // print formatted data to buffer + + lcd.clear(); + lcd.printString("You hit the", 0, 1); + lcd.printString(EnemyList[m].EName, 0, 2); + lcd.printString(buffer3, 0, 3); + lcd.refresh(); + wait(1.0); + Sleep(); + + } else { //Monster dodges + lcd.clear(); + lcd.printString(EnemyList[m].EName, 0, 1); + lcd.printString("dodges your", 0, 2); + lcd.printString("attack", 0, 3); + lcd.refresh(); + wait(1.0); + Sleep(); + } +} + void MonsterAttack(int m) { if (rand() % 100 + 1 < EnemyList[m].EHit) { //If monster hits and isn't dead
--- a/Game.h Mon May 11 12:19:13 2015 +0000 +++ b/Game.h Mon May 11 12:56:26 2015 +0000 @@ -134,6 +134,9 @@ //Player armour int pa = 5; //5 to 9 +//Monster health +int mh; + //Player score int score = -100; //100 level, x monster, 10 chest, -2 running away @@ -220,25 +223,179 @@ * */ void Initilize(); + +/** Main Menu +* +* Displays a menu where the user can choose to start the game, view highscores or view the option menu +* +* +*/ void MainMenu(); + +/** Options Menu +* +* Allows the user to turn the screen backlight on or off +* +* +*/ void Options(); + +/** Level Screen +* +* Displays which level the user is about to enter +* +* +*/ void LevelScreen(); + +/** Next Level +* +* Increases the score, generates the next level and then initilizes the random seed +* +* +*/ +void NextLevel(); + +/** Game Loop +* +* The main loop while the game is running. +* Checks if the user is interacting with a chest, moving the analogue stick or pressing a button and then calls the corresponding function +* +* +*/ void GameLoop(); + +/** Player Camera +* +* Displays the map around the player as characters on the screen +* +*/ void PlayerCamera(); + +/** Player Move +* +* Checks which way the analogue stick was moved and then moves the player into that space if the tile is passable +* +*/ void PlayerMove(); + +/** Fight +* +* Function called during a fight. +* It first displays the opponent and then gives the user the option to fight or run away. +* The loop ends if the player runs away, kills the opponent or is killed. +* +*/ void Fight(); + +/** Monster Attack +* +* Calculates the damage the opponent does to the player +* +*/ void MonsterAttack(int m); + +/** Player Attack +* +* Calculates the damage the player does to the opponent +* +*/ +void PlayerAttack(int m); + +/** Start Menu +* +* Displays a screen showing the player's current health and a menu where the user can view the map, map legend and inventory +* +*/ void StartMenu(); + +/** Map +* +* Calls the functions which displays the map of the current level on the screen and flashes the player's current location +* +*/ void Map(); + +/** Draw Map +* +* Displays the map of the current level on the screen +* +*/ void DrawMap(); + +/** Flash Player Location +* +* Flashes the player's current location on the screen +* +*/ void FlashPlayerLocation(); + +/** Map legend +* +* Displays a screen showing what each character represents on the main game screen +* +*/ void MapLegend(); + +/** Inventory +* +* Displays a screen showing what weapon and armour the player has equipped. +* +*/ void Inventory(); + +/** Chest +* +* Generates either an item, potion, map or booby trap in the chest as it is opened. +* +*/ void Chest(); + +/** Get Item +* +* Generates an item from the list of items and asks if the player wants to equip it. +* +*/ void getItem(); + +/** Booby Trap +* +* Damages the player for 0-5 damage. If the damage is 0 the trap will display as having failed. +* +*/ void BoobyTrap(); + +/** Reveal Map +* +* Turns all the unseen floors into seen ones. +* +*/ void RevealMap(); + +/** Potion +* +* Generates either a potion that heals the player, damages the player or transports them to the next level +* +*/ void Potion(); + +/** Game Over +* +* Displays the game over screen +* +*/ void GameOver(); + +/** Score Screen +* +* Displays the user's final score +* +*/ void ScoreScreen(); + +/** High Score Screen +* +* Displays the top 4 high scores +* +*/ void HighScoreScreen(); \ No newline at end of file