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
Game.h@32:99ca304085e6, 2015-05-10 (annotated)
- Committer:
- ThomasBGill
- Date:
- Sun May 10 22:25:19 2015 +0000
- Revision:
- 32:99ca304085e6
- Parent:
- 31:5b4a4d225ab4
- Child:
- 33:4fc26476b2e0
Chest items fixed
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| ThomasBGill | 26:0dd71fc0ede4 | 1 | #include "N5110.h" |
| ThomasBGill | 26:0dd71fc0ede4 | 2 | #include "PowerControl/PowerControl.h" |
| ThomasBGill | 26:0dd71fc0ede4 | 3 | #include "PowerControl/EthernetPowerControl.h" |
| ThomasBGill | 26:0dd71fc0ede4 | 4 | #include "WorldBuilder.h" |
| ThomasBGill | 26:0dd71fc0ede4 | 5 | #include "Graphics.h" |
| ThomasBGill | 26:0dd71fc0ede4 | 6 | |
| ThomasBGill | 32:99ca304085e6 | 7 | // vcc sce rst dc mosi clk led |
| ThomasBGill | 31:5b4a4d225ab4 | 8 | N5110 lcd(p7, p8, p9, p10, p11, p13, p26); |
| ThomasBGill | 31:5b4a4d225ab4 | 9 | InterruptIn Act(p27); |
| ThomasBGill | 31:5b4a4d225ab4 | 10 | InterruptIn Start(p28); |
| ThomasBGill | 26:0dd71fc0ede4 | 11 | AnalogIn Noise(p19); |
| ThomasBGill | 31:5b4a4d225ab4 | 12 | AnalogIn xPot(p15); |
| ThomasBGill | 31:5b4a4d225ab4 | 13 | AnalogIn yPot(p16); |
| ThomasBGill | 31:5b4a4d225ab4 | 14 | |
| ThomasBGill | 32:99ca304085e6 | 15 | #define PH_MAX 20 |
| ThomasBGill | 32:99ca304085e6 | 16 | |
| ThomasBGill | 31:5b4a4d225ab4 | 17 | //Joystick stuff |
| ThomasBGill | 31:5b4a4d225ab4 | 18 | // timer to regularly read the joystick |
| ThomasBGill | 31:5b4a4d225ab4 | 19 | Ticker pollJoystick; |
| ThomasBGill | 31:5b4a4d225ab4 | 20 | |
| ThomasBGill | 31:5b4a4d225ab4 | 21 | // change this to alter tolerance of joystick direction |
| ThomasBGill | 31:5b4a4d225ab4 | 22 | #define DIRECTION_TOLERANCE 0.05 |
| ThomasBGill | 31:5b4a4d225ab4 | 23 | |
| ThomasBGill | 31:5b4a4d225ab4 | 24 | // create enumerated type (0,1,2,3 etc. for direction) |
| ThomasBGill | 31:5b4a4d225ab4 | 25 | // could be extended for diagonals etc. |
| ThomasBGill | 31:5b4a4d225ab4 | 26 | enum DirectionName { |
| ThomasBGill | 31:5b4a4d225ab4 | 27 | Up, |
| ThomasBGill | 31:5b4a4d225ab4 | 28 | Down, |
| ThomasBGill | 31:5b4a4d225ab4 | 29 | Left, |
| ThomasBGill | 31:5b4a4d225ab4 | 30 | Right, |
| ThomasBGill | 31:5b4a4d225ab4 | 31 | Centre, |
| ThomasBGill | 31:5b4a4d225ab4 | 32 | Unknown |
| ThomasBGill | 31:5b4a4d225ab4 | 33 | }; |
| ThomasBGill | 31:5b4a4d225ab4 | 34 | |
| ThomasBGill | 31:5b4a4d225ab4 | 35 | // struct for Joystick |
| ThomasBGill | 31:5b4a4d225ab4 | 36 | typedef struct JoyStick Joystick; |
| ThomasBGill | 31:5b4a4d225ab4 | 37 | struct JoyStick { |
| ThomasBGill | 31:5b4a4d225ab4 | 38 | float x; // current x value |
| ThomasBGill | 31:5b4a4d225ab4 | 39 | float x0; // 'centred' x value |
| ThomasBGill | 31:5b4a4d225ab4 | 40 | float y; // current y value |
| ThomasBGill | 31:5b4a4d225ab4 | 41 | float y0; // 'centred' y value |
| ThomasBGill | 31:5b4a4d225ab4 | 42 | int button; // button state (assume pull-down used, so 1 = pressed, 0 = unpressed) |
| ThomasBGill | 31:5b4a4d225ab4 | 43 | DirectionName direction; // current direction |
| ThomasBGill | 31:5b4a4d225ab4 | 44 | }; |
| ThomasBGill | 31:5b4a4d225ab4 | 45 | // create struct variable |
| ThomasBGill | 31:5b4a4d225ab4 | 46 | Joystick joystick; |
| ThomasBGill | 31:5b4a4d225ab4 | 47 | |
| ThomasBGill | 31:5b4a4d225ab4 | 48 | // function prototypes |
| ThomasBGill | 31:5b4a4d225ab4 | 49 | void calibrateJoystick(); |
| ThomasBGill | 31:5b4a4d225ab4 | 50 | void updateJoystick(); |
| ThomasBGill | 26:0dd71fc0ede4 | 51 | |
| ThomasBGill | 26:0dd71fc0ede4 | 52 | #define USR_POWERDOWN (0x104) |
| ThomasBGill | 26:0dd71fc0ede4 | 53 | |
| ThomasBGill | 26:0dd71fc0ede4 | 54 | LocalFileSystem local("local"); // create local filesystem |
| ThomasBGill | 26:0dd71fc0ede4 | 55 | |
| ThomasBGill | 26:0dd71fc0ede4 | 56 | struct TILES { |
| ThomasBGill | 26:0dd71fc0ede4 | 57 | char Symbol; // Symbol for this tile |
| ThomasBGill | 26:0dd71fc0ede4 | 58 | bool Passable; // Can tile be walked on |
| ThomasBGill | 26:0dd71fc0ede4 | 59 | }; |
| ThomasBGill | 26:0dd71fc0ede4 | 60 | |
| ThomasBGill | 26:0dd71fc0ede4 | 61 | TILES TileList[] = { |
| ThomasBGill | 26:0dd71fc0ede4 | 62 | { '#', false }, // 0- WALL |
| ThomasBGill | 26:0dd71fc0ede4 | 63 | { '.', true }, // 1- FLOOR |
| ThomasBGill | 26:0dd71fc0ede4 | 64 | { '+', true }, // 2- ENTER |
| ThomasBGill | 26:0dd71fc0ede4 | 65 | { 'x', true }, // 3- EXIT |
| ThomasBGill | 26:0dd71fc0ede4 | 66 | { '.', true }, // 4- FLOOR_SEEN |
| ThomasBGill | 26:0dd71fc0ede4 | 67 | { '=', true }, // 5- CHEST |
| ThomasBGill | 26:0dd71fc0ede4 | 68 | { '/', true }, // 6- CHEST_OPENED |
| ThomasBGill | 26:0dd71fc0ede4 | 69 | }; |
| ThomasBGill | 26:0dd71fc0ede4 | 70 | |
| ThomasBGill | 26:0dd71fc0ede4 | 71 | struct ITEMS { |
| ThomasBGill | 26:0dd71fc0ede4 | 72 | char ItemName[15]; //Item name |
| ThomasBGill | 26:0dd71fc0ede4 | 73 | int ItemValue; //Damage/ armour value |
| ThomasBGill | 26:0dd71fc0ede4 | 74 | }; |
| ThomasBGill | 26:0dd71fc0ede4 | 75 | |
| ThomasBGill | 26:0dd71fc0ede4 | 76 | ITEMS ItemList[] = { |
| ThomasBGill | 26:0dd71fc0ede4 | 77 | //Weapons |
| ThomasBGill | 26:0dd71fc0ede4 | 78 | { "Dagger", 4 }, //0 |
| ThomasBGill | 26:0dd71fc0ede4 | 79 | { "Axe", 5 }, //1 |
| ThomasBGill | 26:0dd71fc0ede4 | 80 | { "Mace", 6 }, //2 |
| ThomasBGill | 26:0dd71fc0ede4 | 81 | { "Sword", 7 }, //3 |
| ThomasBGill | 26:0dd71fc0ede4 | 82 | { "Warhammer", 8 }, //4 |
| ThomasBGill | 26:0dd71fc0ede4 | 83 | //Armour |
| ThomasBGill | 30:4a03611a3d99 | 84 | { "Cloth armour", 0 }, //5 |
| ThomasBGill | 30:4a03611a3d99 | 85 | { "Leather armour", 1 }, //6 |
| ThomasBGill | 30:4a03611a3d99 | 86 | { "Studded armour", 2 }, //7 |
| ThomasBGill | 30:4a03611a3d99 | 87 | { "Chainmail vest", 3 }, //8 |
| ThomasBGill | 30:4a03611a3d99 | 88 | { "Plate armour", 4 }, //9 |
| ThomasBGill | 26:0dd71fc0ede4 | 89 | }; |
| ThomasBGill | 26:0dd71fc0ede4 | 90 | |
| ThomasBGill | 26:0dd71fc0ede4 | 91 | struct ENEMIES { |
| ThomasBGill | 26:0dd71fc0ede4 | 92 | char EName[9]; //Enemy name |
| ThomasBGill | 26:0dd71fc0ede4 | 93 | int EHealth; //Enemy health |
| ThomasBGill | 26:0dd71fc0ede4 | 94 | int EDamage; //Enemy damage |
| ThomasBGill | 26:0dd71fc0ede4 | 95 | int EArmour; //Enemy armour |
| ThomasBGill | 26:0dd71fc0ede4 | 96 | int EDodge; //Enemy dodge chance |
| ThomasBGill | 26:0dd71fc0ede4 | 97 | int EHit; //Enemy hit chance |
| ThomasBGill | 26:0dd71fc0ede4 | 98 | int ESpd; //Enemy speed (used for running away during fights) |
| ThomasBGill | 26:0dd71fc0ede4 | 99 | int EPoints; //How many points the monster is worth |
| ThomasBGill | 26:0dd71fc0ede4 | 100 | }; |
| ThomasBGill | 26:0dd71fc0ede4 | 101 | |
| ThomasBGill | 26:0dd71fc0ede4 | 102 | ENEMIES EnemyList[] = { |
| ThomasBGill | 26:0dd71fc0ede4 | 103 | //Name HP Dmg Arm Dg Ht Spd Pts |
| ThomasBGill | 26:0dd71fc0ede4 | 104 | { "Huge Rat", 5, 3, 0, 25, 70, 40, 1 }, //0- Huge Rat |
| ThomasBGill | 26:0dd71fc0ede4 | 105 | { "Goblin", 6, 3, 1, 25, 60, 30, 3 }, //1- Goblin |
| ThomasBGill | 26:0dd71fc0ede4 | 106 | { "Skeleton", 8, 4, 2, 10, 50, 10, 5 }, //2- Skeleton |
| ThomasBGill | 26:0dd71fc0ede4 | 107 | { "Wraith", 5, 4, 0, 40, 60, 50, 10 }, //3- Wraith |
| ThomasBGill | 26:0dd71fc0ede4 | 108 | { "Ogre", 10, 7, 3, 10, 35, 15, 15 }, //4- Ogre |
| ThomasBGill | 26:0dd71fc0ede4 | 109 | { "Minotaur", 15, 8, 4, 20, 45, 100, 50 }, //5- Minotaur |
| ThomasBGill | 26:0dd71fc0ede4 | 110 | }; |
| ThomasBGill | 26:0dd71fc0ede4 | 111 | |
| ThomasBGill | 26:0dd71fc0ede4 | 112 | //Variables |
| ThomasBGill | 26:0dd71fc0ede4 | 113 | int ActFlag = 0; |
| ThomasBGill | 26:0dd71fc0ede4 | 114 | int StartFlag = 0; |
| ThomasBGill | 31:5b4a4d225ab4 | 115 | //int DirFlag = 0; |
| ThomasBGill | 26:0dd71fc0ede4 | 116 | |
| ThomasBGill | 26:0dd71fc0ede4 | 117 | //Space type player is on |
| ThomasBGill | 26:0dd71fc0ede4 | 118 | int pSpace; |
| ThomasBGill | 26:0dd71fc0ede4 | 119 | |
| ThomasBGill | 26:0dd71fc0ede4 | 120 | //Player Health |
| ThomasBGill | 29:89bc8c8aa8ac | 121 | int ph = PH_MAX; |
| ThomasBGill | 26:0dd71fc0ede4 | 122 | |
| ThomasBGill | 26:0dd71fc0ede4 | 123 | //Player weapon |
| ThomasBGill | 26:0dd71fc0ede4 | 124 | int pw = 0; //0 to 4 |
| ThomasBGill | 26:0dd71fc0ede4 | 125 | |
| ThomasBGill | 26:0dd71fc0ede4 | 126 | //Player armour |
| ThomasBGill | 26:0dd71fc0ede4 | 127 | int pa = 5; //5 to 9 |
| ThomasBGill | 26:0dd71fc0ede4 | 128 | |
| ThomasBGill | 26:0dd71fc0ede4 | 129 | //Player score |
| ThomasBGill | 26:0dd71fc0ede4 | 130 | int score = -100; //100 level, x monster, 10 chest, -2 running away |
| ThomasBGill | 26:0dd71fc0ede4 | 131 | |
| ThomasBGill | 26:0dd71fc0ede4 | 132 | //High scores |
| ThomasBGill | 26:0dd71fc0ede4 | 133 | int HScore1; |
| ThomasBGill | 26:0dd71fc0ede4 | 134 | int HScore2; |
| ThomasBGill | 26:0dd71fc0ede4 | 135 | int HScore3; |
| ThomasBGill | 26:0dd71fc0ede4 | 136 | int HScore4; |
| ThomasBGill | 26:0dd71fc0ede4 | 137 | |
| ThomasBGill | 26:0dd71fc0ede4 | 138 | bool BossFight = false; |
| ThomasBGill | 26:0dd71fc0ede4 | 139 | |
| ThomasBGill | 26:0dd71fc0ede4 | 140 | //Voids |
| ThomasBGill | 26:0dd71fc0ede4 | 141 | int semihost_powerdown(); |
| ThomasBGill | 26:0dd71fc0ede4 | 142 | |
| ThomasBGill | 26:0dd71fc0ede4 | 143 | void ActPressed(); |
| ThomasBGill | 26:0dd71fc0ede4 | 144 | void StartPressed(); |
| ThomasBGill | 31:5b4a4d225ab4 | 145 | //void DirPressed(); |
| ThomasBGill | 26:0dd71fc0ede4 | 146 | |
| ThomasBGill | 26:0dd71fc0ede4 | 147 | void writeDataToFile(); |
| ThomasBGill | 27:1ad2408ba702 | 148 | void readDataFromFile(); |
| ThomasBGill | 27:1ad2408ba702 | 149 | void HighScoreCheck(); |
| ThomasBGill | 26:0dd71fc0ede4 | 150 | |
| ThomasBGill | 28:b3a597b38b60 | 151 | void FlashScreen(); |
| ThomasBGill | 28:b3a597b38b60 | 152 | void DrawGraphic(int p, int x, int y); |
| ThomasBGill | 28:b3a597b38b60 | 153 | |
| ThomasBGill | 26:0dd71fc0ede4 | 154 | void Intro(); |
| ThomasBGill | 26:0dd71fc0ede4 | 155 | void MainMenu(); |
| ThomasBGill | 26:0dd71fc0ede4 | 156 | void Options(); |
| ThomasBGill | 26:0dd71fc0ede4 | 157 | void LevelScreen(); |
| ThomasBGill | 26:0dd71fc0ede4 | 158 | void GameLoop(); |
| ThomasBGill | 26:0dd71fc0ede4 | 159 | void PlayerCamera(); |
| ThomasBGill | 26:0dd71fc0ede4 | 160 | void PlayerMove(); |
| ThomasBGill | 26:0dd71fc0ede4 | 161 | void Fight(); |
| ThomasBGill | 26:0dd71fc0ede4 | 162 | void MonsterAttack(int m); |
| ThomasBGill | 26:0dd71fc0ede4 | 163 | void StartMenu(); |
| ThomasBGill | 26:0dd71fc0ede4 | 164 | void Map(); |
| ThomasBGill | 26:0dd71fc0ede4 | 165 | void DrawMap(); |
| ThomasBGill | 26:0dd71fc0ede4 | 166 | void FlashPlayerLocation(); |
| ThomasBGill | 26:0dd71fc0ede4 | 167 | void MapLegend(); |
| ThomasBGill | 26:0dd71fc0ede4 | 168 | void Inventory(); |
| ThomasBGill | 26:0dd71fc0ede4 | 169 | void Chest(); |
| ThomasBGill | 26:0dd71fc0ede4 | 170 | void getItem(); |
| ThomasBGill | 26:0dd71fc0ede4 | 171 | void BoobyTrap(); |
| ThomasBGill | 26:0dd71fc0ede4 | 172 | void RevealMap(); |
| ThomasBGill | 26:0dd71fc0ede4 | 173 | void Potion(); |
| ThomasBGill | 26:0dd71fc0ede4 | 174 | void GameOver(); |
| ThomasBGill | 26:0dd71fc0ede4 | 175 | void ScoreScreen(); |
| ThomasBGill | 26:0dd71fc0ede4 | 176 | void HighScoreScreen(); |