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:
- 22:dae750e4d749
- Parent:
- 21:aa4feee6aa39
- Child:
- 23:1b8b1d043403
--- a/main.cpp Mon May 04 17:16:31 2015 +0000 +++ b/main.cpp Thu May 07 15:00:04 2015 +0000 @@ -2,6 +2,7 @@ #include "PowerControl/PowerControl.h" #include "PowerControl/EthernetPowerControl.h" #include "WorldBuilder.h" +#include "Graphics.h" // vcc sce rst dc mosi clk led N5110 lcd(p5, p6, p7, p8, p11, p13, p21); @@ -55,19 +56,19 @@ int EHealth; //Enemy health int EDamage; //Enemy damage int EArmour; //Enemy armour - int EDodge; //Enemy dodge chance - int EHit; //Enemy hit chance - int ESpd; //Enemy speed (use for running away during fights) + int EDodge; //Enemy dodge chance + int EHit; //Enemy hit chance + int ESpd; //Enemy speed (used for running away during fights) }; ENEMIES EnemyList[] = { //Name HP Dmg Arm Dg Ht Spd - { "Huge Rat", 5, 3, 0, 25, 70, 40 }, //0- Huge Rat - { "Goblin", 6, 3, 2, 25, 60, 30 }, //1- Goblin - { "Skeleton", 8, 5, 3, 10, 50, 10 }, //2- Skeleton - { "Wraith", 5, 4, 0, 40, 60, 50 }, //3- Wraith - { "Ogre", 10, 7, 3, 10, 35, 15 }, //4- Ogre - { "Minotaur", 15, 8, 5, 20, 45, 100 }, //5- Minotaur + { "Huge Rat", 5, 3, 0, 25, 70, 40 }, //0- Huge Rat + { "Goblin", 6, 3, 1, 25, 60, 30 }, //1- Goblin + { "Skeleton", 8, 4, 2, 10, 50, 10 }, //2- Skeleton + { "Wraith", 5, 4, 0, 40, 60, 50 }, //3- Wraith + { "Ogre", 10, 7, 3, 10, 35, 15 }, //4- Ogre + { "Minotaur", 15, 8, 4, 20, 45, 100 }, //5- Minotaur }; //Variables @@ -111,6 +112,7 @@ //Voids void Intro(); void MainMenu(); +void Options(); void LevelScreen(); void GameLoop(); void PlayerCamera(); @@ -129,6 +131,23 @@ void RevealMap(); void Potion(); void GameOver(); +void DrawGraphic(int p, int x, int y); + +void DrawGraphic(int p, int x, int y) +{ + if(p == 0) { + for(int i = 0; i < 38; i++) { + for(int j = 0; j < 34; j++) { + + + if(HugeRat[i][j] == 1) { + + lcd.setPixel(y+i, x+j); + } + } + } + } +} void Intro() { @@ -160,8 +179,7 @@ lcd.printString("Options", 20, 3); lcd.refresh(); Sleep(); - } - else { + } else { lcd.printString("New Game", 20, 1); lcd.printString("Options <", 20, 3); lcd.refresh(); @@ -180,11 +198,49 @@ if (menu == 0) { GameLoop(); + } else { + Options(); } } } } +void Options() +{ + + bool bright = 1; + + while(1) { + + lcd.setBrightness(bright); + lcd.clear(); + + if(bright == 1) { + lcd.printString("Backlight ON", 6, 2); + } else { + lcd.printString("Backlight OFF", 6, 2); + } + + lcd.refresh(); + if (DirFlag) { + + DirFlag = 0; + + bright = !bright; + } + if (ActFlag) { + ActFlag = 0; + } + if(StartFlag) { + + StartFlag = 0; + + MainMenu(); + + } + } +} + void LevelScreen() { char buffer[14]; @@ -195,7 +251,6 @@ lcd.printString(buffer, 20, 2); lcd.refresh(); wait(1.0); - } void GameLoop() @@ -208,7 +263,7 @@ LevelScreen(); - RevealMap(); + RevealMap(); //Uncomment for debugging to view map while (1) { @@ -237,7 +292,7 @@ PlayerMove(); - if (rand() % 60 == 0) { + if (rand() % 40 == 0) { if (ph < 15) { ph++; } @@ -273,15 +328,13 @@ if (i == 6 && j == 2) { lcd.printString("@", (6 * i) + 1, j); - } - else { + } else { int diffx = i - 6; int diffy = j - 2; if (px + diffx < 84 && px + diffx > 0 && py + diffy < 48 && py + diffy > 0) { tile = map[px + diffx][py + diffy]; - } - else { + } else { tile = WALL; } lcd.printChar(TileList[tile].Symbol, (6 * i) + 1, j); @@ -342,6 +395,13 @@ wait(0.2); } + if(m==0) { + lcd.clear(); + DrawGraphic(m, 1, 1); + lcd.refresh(); + wait(2.0); + } + bool menu = 1; while (1) { @@ -364,8 +424,7 @@ if (menu) { lcd.printString("Fight <", 0, 4); lcd.printString("Run", 0, 5); - } - else { + } else { lcd.printString("Fight", 0, 4); lcd.printString("Run <", 0, 5); } @@ -399,8 +458,7 @@ wait(1.0); Sleep(); - } - else { //Monster dodges + } else { //Monster dodges lcd.clear(); lcd.printString(EnemyList[m].EName, 0, 1); lcd.printString("dodges your", 0, 2); @@ -422,8 +480,7 @@ MonsterAttack(m); - } - else { //Run away + } else { //Run away int b = rand() % 5; @@ -440,8 +497,7 @@ MonsterAttack(m); - } - else { + } else { int s = rand() % 100 + 1; @@ -454,8 +510,7 @@ Sleep(); break; - } - else { + } else { lcd.clear(); lcd.printString("You try to run", 0, 0); @@ -499,8 +554,7 @@ wait(1.0); Sleep(); - } - else { //You dodge + } else { //You dodge lcd.clear(); lcd.printString("You dodge the", 0, 1); lcd.printString("monster's", 0, 2); @@ -533,8 +587,7 @@ lcd.printString("Continue", 0, 5); lcd.refresh(); Sleep(); - } - else if (menu == 1) { + } else if (menu == 1) { lcd.clear(); lcd.printString(buffer, 0, 0); lcd.printString("Map", 0, 2); @@ -543,8 +596,7 @@ lcd.printString("Continue", 0, 5); lcd.refresh(); Sleep(); - } - else if (menu == 2) { + } else if (menu == 2) { lcd.clear(); lcd.printString(buffer, 0, 0); lcd.printString("Map", 0, 2); @@ -553,8 +605,7 @@ lcd.printString("Continue", 0, 5); lcd.refresh(); Sleep(); - } - else if (menu == 3) { + } else if (menu == 3) { lcd.clear(); lcd.printString(buffer, 0, 0); lcd.printString("Map", 0, 2); @@ -569,22 +620,18 @@ DirFlag = 0; if ((Down || Right) && menu < 3) { menu++; - } - else if ((Up || Left) && menu > 0) + } else if ((Up || Left) && menu > 0) menu--; } if (ActFlag) { ActFlag = 0; if (menu == 0) { Map(); - } - else if (menu == 1) { + } else if (menu == 1) { MapLegend(); - } - else if (menu == 2) { + } else if (menu == 2) { Inventory(); - } - else { + } else { break; } } @@ -613,8 +660,7 @@ for (int j = 0; j<48; j++) { if (map[i][j] == FLOOR_SEEN || map[i][j] == CHEST_OPENED) { lcd.clearPixel(i, j); - } - else { + } else { lcd.setPixel(i, j); } } @@ -698,14 +744,11 @@ if (c == 0) { getItem(); - } - else if (c == 1) { + } else if (c == 1) { BoobyTrap(); - } - else if (c == 2) { + } else if (c == 2) { RevealMap(); - } - else { + } else { Potion(); } @@ -737,8 +780,7 @@ if (r > 5) { pa = r; - } - else { + } else { pw = r; } @@ -749,8 +791,7 @@ wait(1.0); Sleep(); - } - else { + } else { StartFlag = 0; DirFlag = 0; @@ -789,8 +830,7 @@ if (ph < 0) { GameOver(); } - } - else { + } else { lcd.clear(); lcd.printString("The chest is", 0, 0); @@ -868,8 +908,7 @@ if (ph < 0) { GameOver(); } - } - else if (p == 1) { //Teleport + } else if (p == 1) { //Teleport lcd.clear(); lcd.printString("You drink the", 0, 0); @@ -884,8 +923,7 @@ GameLoop(); - } - else { //Full heal + } else { //Full heal ph = 15; @@ -899,8 +937,7 @@ wait(1.0); Sleep(); } - } - else { //Leave the potion + } else { //Leave the potion DirFlag = 0; StartFlag = 0; lcd.clear();