Game For ECE 2035

Dependencies:   mbed wave_player 4DGL-uLCD-SE MMA8452

Committer:
nasiromar
Date:
Thu Dec 02 20:16:28 2021 +0000
Revision:
13:798a4dd14c7e
Parent:
12:116a4cc85b16
Child:
14:7225da81314a
stuff;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rconnorlawson 0:35660d7952f7 1 // Project includes
rconnorlawson 0:35660d7952f7 2 #include "globals.h"
rconnorlawson 0:35660d7952f7 3 #include "hardware.h"
rconnorlawson 0:35660d7952f7 4 #include "map.h"
rconnorlawson 0:35660d7952f7 5 #include "graphics.h"
rconnorlawson 0:35660d7952f7 6 #include "speech.h"
nasiromar 6:c9695079521d 7 #include "spells.h"
nasiromar 6:c9695079521d 8 #include "actions.h"
nasiromar 9:cbb9cfb1f6c5 9 #include "SDFileSystem.h"
rconnorlawson 0:35660d7952f7 10
rconnorlawson 0:35660d7952f7 11 // Functions in this file
rconnorlawson 0:35660d7952f7 12 int get_action (GameInputs inputs);
rconnorlawson 0:35660d7952f7 13 int update_game (int action);
rconnorlawson 0:35660d7952f7 14 void draw_game (int init);
rconnorlawson 0:35660d7952f7 15 void init_main_map ();
rconnorlawson 0:35660d7952f7 16 int main ();
rconnorlawson 0:35660d7952f7 17
nasiromar 9:cbb9cfb1f6c5 18
nasiromar 10:e18685911e84 19
nasiromar 9:cbb9cfb1f6c5 20 FILE *wave_file;
nasiromar 9:cbb9cfb1f6c5 21
nasiromar 10:e18685911e84 22
nasiromar 10:e18685911e84 23
rconnorlawson 0:35660d7952f7 24 /**
rconnorlawson 0:35660d7952f7 25 * The main game state. Must include Player locations and previous locations for
rconnorlawson 0:35660d7952f7 26 * drawing to work properly. Other items can be added as needed.
rconnorlawson 0:35660d7952f7 27 */
rconnorlawson 0:35660d7952f7 28 struct {
rconnorlawson 0:35660d7952f7 29 int x,y; // Current locations
rconnorlawson 0:35660d7952f7 30 int px, py; // Previous locations
rconnorlawson 0:35660d7952f7 31 int has_key;
nasiromar 6:c9695079521d 32 int spell;
nasiromar 6:c9695079521d 33 int god;
nasiromar 8:fcc333a8f9e1 34 int won;
nasiromar 9:cbb9cfb1f6c5 35 int HP,MP;
nasiromar 11:6cd02a8539d1 36 int talked;
rashidi1saeed 2:1ca97843a334 37 // You can add other properties for the player here
rconnorlawson 0:35660d7952f7 38 } Player;
rconnorlawson 0:35660d7952f7 39
nasiromar 9:cbb9cfb1f6c5 40
nasiromar 9:cbb9cfb1f6c5 41
rconnorlawson 0:35660d7952f7 42 /**
rconnorlawson 0:35660d7952f7 43 * Given the game inputs, determine what kind of update needs to happen.
rconnorlawson 0:35660d7952f7 44 * Possbile return values are defined below.
rconnorlawson 0:35660d7952f7 45 */
rconnorlawson 0:35660d7952f7 46 #define NO_ACTION 0
rconnorlawson 0:35660d7952f7 47 #define ACTION_BUTTON 1
rconnorlawson 0:35660d7952f7 48 #define MENU_BUTTON 2
rconnorlawson 0:35660d7952f7 49 #define GO_LEFT 3
rconnorlawson 0:35660d7952f7 50 #define GO_RIGHT 4
rconnorlawson 0:35660d7952f7 51 #define GO_UP 5
rconnorlawson 0:35660d7952f7 52 #define GO_DOWN 6
nasiromar 6:c9695079521d 53 #define GOD_MODE 7
nasiromar 6:c9695079521d 54
nasiromar 6:c9695079521d 55 #define TILT .25
rconnorlawson 0:35660d7952f7 56 int get_action(GameInputs inputs)
rconnorlawson 0:35660d7952f7 57 {
nasiromar 6:c9695079521d 58
nasiromar 6:c9695079521d 59 if(inputs.ay > TILT) { //Go in north direction if it is not blocked
nasiromar 6:c9695079521d 60 return GO_UP;
nasiromar 6:c9695079521d 61 }
nasiromar 6:c9695079521d 62 if(inputs.ay < TILT *-1) { //Go in south direction if it is not blocked
nasiromar 6:c9695079521d 63 return GO_DOWN;
nasiromar 6:c9695079521d 64 }
nasiromar 6:c9695079521d 65 if(inputs.ax > TILT) { //Go in north direction if it is not blocked
nasiromar 6:c9695079521d 66 return GO_RIGHT;
nasiromar 6:c9695079521d 67 }
nasiromar 6:c9695079521d 68 if(inputs.ax < TILT *-1) { //Go in north direction if it is not blocked
nasiromar 6:c9695079521d 69 return GO_LEFT;
nasiromar 6:c9695079521d 70 }
nasiromar 6:c9695079521d 71 if(!inputs.b1) {
nasiromar 6:c9695079521d 72 wait(.5);
nasiromar 6:c9695079521d 73 return ACTION_BUTTON;
nasiromar 6:c9695079521d 74 }
nasiromar 6:c9695079521d 75 if(!inputs.b2) {
nasiromar 6:c9695079521d 76 wait(.5);
nasiromar 6:c9695079521d 77 return MENU_BUTTON;
nasiromar 6:c9695079521d 78 }
nasiromar 6:c9695079521d 79 if (!inputs.b3) {
nasiromar 6:c9695079521d 80 wait(.5);
nasiromar 6:c9695079521d 81 return GOD_MODE;
nasiromar 6:c9695079521d 82 } else {
nasiromar 6:c9695079521d 83 return NO_ACTION;
nasiromar 6:c9695079521d 84 }
rconnorlawson 0:35660d7952f7 85 }
rconnorlawson 0:35660d7952f7 86
nasiromar 6:c9695079521d 87
rconnorlawson 0:35660d7952f7 88 /**
rconnorlawson 0:35660d7952f7 89 * Update the game state based on the user action. For example, if the user
rconnorlawson 0:35660d7952f7 90 * requests GO_UP, then this function should determine if that is possible by
rconnorlawson 0:35660d7952f7 91 * consulting the map, and update the Player position accordingly.
nasiromar 6:c9695079521d 92 *
rconnorlawson 0:35660d7952f7 93 * Return values are defined below. FULL_DRAW indicates that for this frame,
rconnorlawson 0:35660d7952f7 94 * draw_game should not optimize drawing and should draw every tile, even if
rconnorlawson 0:35660d7952f7 95 * the player has not moved.
rconnorlawson 0:35660d7952f7 96 */
nasiromar 9:cbb9cfb1f6c5 97 // Game Life and Magic Points
nasiromar 6:c9695079521d 98
nasiromar 6:c9695079521d 99
nasiromar 6:c9695079521d 100
nasiromar 10:e18685911e84 101
nasiromar 10:e18685911e84 102
rconnorlawson 0:35660d7952f7 103 #define NO_RESULT 0
rconnorlawson 0:35660d7952f7 104 #define GAME_OVER 1
rconnorlawson 0:35660d7952f7 105 #define FULL_DRAW 2
rconnorlawson 0:35660d7952f7 106 int update_game(int action)
rconnorlawson 0:35660d7952f7 107 {
nasiromar 11:6cd02a8539d1 108 //walk_goblin(0);
nasiromar 10:e18685911e84 109
nasiromar 10:e18685911e84 110
nasiromar 10:e18685911e84 111
nasiromar 10:e18685911e84 112 // Save player previous location before updating
rconnorlawson 0:35660d7952f7 113 Player.px = Player.x;
rconnorlawson 0:35660d7952f7 114 Player.py = Player.y;
nasiromar 6:c9695079521d 115
rconnorlawson 0:35660d7952f7 116 // Do different things based on the each action.
rconnorlawson 0:35660d7952f7 117 // You can define functions like "go_up()" that get called for each case.
nasiromar 6:c9695079521d 118
nasiromar 6:c9695079521d 119 // Need to check if Claue has changed as well if whats in front of me is able to be walked into
nasiromar 6:c9695079521d 120 switch(action) {
nasiromar 6:c9695079521d 121 case GO_UP: {
nasiromar 6:c9695079521d 122 MapItem* north = get_north(Player.x,Player.y);
nasiromar 6:c9695079521d 123 if (north->walkable && north == NULL || north->type == (PORTAL || PLANT) && Player.y != 0 || Player.god ) {
nasiromar 6:c9695079521d 124 Player.y--;
nasiromar 10:e18685911e84 125
nasiromar 6:c9695079521d 126 }
nasiromar 6:c9695079521d 127 break;
nasiromar 6:c9695079521d 128 }
nasiromar 6:c9695079521d 129 case GO_RIGHT: {
nasiromar 6:c9695079521d 130 MapItem* east = get_east(Player.x,Player.y);
nasiromar 6:c9695079521d 131 if (east->walkable && east == NULL || east->type == (PORTAL || PLANT) && Player.x != 0 || Player.god ) {
nasiromar 6:c9695079521d 132 Player.x++;
nasiromar 6:c9695079521d 133 }
nasiromar 6:c9695079521d 134 break;
nasiromar 6:c9695079521d 135 }
nasiromar 6:c9695079521d 136 case GO_DOWN: {
nasiromar 6:c9695079521d 137 MapItem* south = get_south(Player.x,Player.y);
nasiromar 6:c9695079521d 138 if (south->walkable && south == NULL || south->type ==(PORTAL || PLANT) && Player.y != 0 || Player.god ) {
nasiromar 6:c9695079521d 139 Player.y++;
nasiromar 6:c9695079521d 140 }
nasiromar 6:c9695079521d 141 break;
nasiromar 6:c9695079521d 142 }
nasiromar 6:c9695079521d 143 case GO_LEFT: {
nasiromar 6:c9695079521d 144 MapItem* west = get_west(Player.x,Player.y);
nasiromar 6:c9695079521d 145 if (west->walkable && west == NULL || west->type == (PORTAL || PLANT) && Player.x != 0 || Player.god ) {
nasiromar 6:c9695079521d 146 Player.x--;
nasiromar 6:c9695079521d 147 }
nasiromar 6:c9695079521d 148 break;
nasiromar 6:c9695079521d 149 }
nasiromar 6:c9695079521d 150 case ACTION_BUTTON: {
nasiromar 6:c9695079521d 151 MapItem* west = get_west(Player.x,Player.y);
nasiromar 6:c9695079521d 152 MapItem* south = get_south(Player.x,Player.y);
nasiromar 6:c9695079521d 153 MapItem* north = get_north(Player.x,Player.y);
nasiromar 6:c9695079521d 154 MapItem* east = get_east(Player.x,Player.y);
nasiromar 6:c9695079521d 155 MapItem* curr = get_here(Player.x,Player.y);
nasiromar 9:cbb9cfb1f6c5 156
nasiromar 9:cbb9cfb1f6c5 157 if((east->type == NPC||west->type == NPC||north->type == NPC||south->type == NPC)&& Player.has_key == 1) {
nasiromar 7:862062ffca62 158 npc_speech2();
nasiromar 9:cbb9cfb1f6c5 159 }
nasiromar 9:cbb9cfb1f6c5 160
nasiromar 9:cbb9cfb1f6c5 161 if(east->type == NPC||west->type == NPC||north->type == NPC||south->type == NPC && Player.has_key == 0 ) {
nasiromar 6:c9695079521d 162 npc_speech1();
nasiromar 11:6cd02a8539d1 163 Player.talked = 1;
nasiromar 9:cbb9cfb1f6c5 164 }
nasiromar 9:cbb9cfb1f6c5 165
nasiromar 9:cbb9cfb1f6c5 166 if(north->type == PORTAL||south->type == PORTAL||east->type == PORTAL||west->type == PORTAL) {
nasiromar 11:6cd02a8539d1 167 set_active_map(1);
nasiromar 7:862062ffca62 168 Player.x = Player.y = 7;
nasiromar 9:cbb9cfb1f6c5 169 }
nasiromar 11:6cd02a8539d1 170
nasiromar 13:798a4dd14c7e 171 if((east->type == ENEMY1||west->type == ENEMY1||north->type == ENEMY1||south->type == ENEMY1)&& Player.spell == EARTH) {
nasiromar 13:798a4dd14c7e 172 Player.spell = NULL;
nasiromar 13:798a4dd14c7e 173 map_delete(10,10);
nasiromar 11:6cd02a8539d1 174 }
nasiromar 11:6cd02a8539d1 175
nasiromar 13:798a4dd14c7e 176 if((east->type == ENEMY2||west->type == ENEMY2||north->type == ENEMY2||south->type == ENEMY2)&& Player.spell == FIRE) {
nasiromar 13:798a4dd14c7e 177 Player.spell = NULL;
nasiromar 11:6cd02a8539d1 178 Player.HP-=2;
nasiromar 13:798a4dd14c7e 179 map_delete(5,7);
nasiromar 11:6cd02a8539d1 180 }
nasiromar 11:6cd02a8539d1 181
nasiromar 13:798a4dd14c7e 182 if((east->type == ENEMY1||west->type == ENEMY1||north->type == ENEMY1||south->type == ENEMY1) && Player.spell == NULL) {
nasiromar 13:798a4dd14c7e 183 Player.HP-=10;
nasiromar 13:798a4dd14c7e 184 Player.x--;
nasiromar 13:798a4dd14c7e 185 Player.y--;
nasiromar 13:798a4dd14c7e 186 }
nasiromar 13:798a4dd14c7e 187
nasiromar 13:798a4dd14c7e 188 if((east->type == ENEMY2||west->type == ENEMY2||north->type == ENEMY2||south->type == ENEMY2) && Player.spell == NULL) {
nasiromar 11:6cd02a8539d1 189 Player.HP-=10;
nasiromar 11:6cd02a8539d1 190 Player.x--;
nasiromar 11:6cd02a8539d1 191 Player.y--;
nasiromar 11:6cd02a8539d1 192 }
nasiromar 11:6cd02a8539d1 193
nasiromar 9:cbb9cfb1f6c5 194
nasiromar 9:cbb9cfb1f6c5 195 if((north->type == DRAGON||south->type == DRAGON||east->type == DRAGON||west->type == DRAGON )&& Player.spell == WATER) {
nasiromar 7:862062ffca62 196 slay_dragon();
nasiromar 7:862062ffca62 197 Player.has_key = 1;
nasiromar 13:798a4dd14c7e 198 //walk_goblin(0);
nasiromar 9:cbb9cfb1f6c5 199 }
rconnorlawson 0:35660d7952f7 200
nasiromar 9:cbb9cfb1f6c5 201 if(north->type == PORTAl||south->type == PORTAl||east->type == PORTAl||west->type == PORTAl) {
nasiromar 11:6cd02a8539d1 202 set_active_map(0);
nasiromar 11:6cd02a8539d1 203 Player.x=20;
nasiromar 11:6cd02a8539d1 204 Player.y = 36;
nasiromar 9:cbb9cfb1f6c5 205 }
nasiromar 6:c9695079521d 206
nasiromar 9:cbb9cfb1f6c5 207 if((north->type == DOOR||south->type == DOOR||east->type == DOOR||west->type == DOOR)&&Player.has_key == 1) {
nasiromar 9:cbb9cfb1f6c5 208 Player.won = door_open();
rconnorlawson 0:35660d7952f7 209 }
nasiromar 11:6cd02a8539d1 210
nasiromar 11:6cd02a8539d1 211 if((north->type == DOOR||south->type == DOOR||east->type == DOOR||west->type == DOOR)&&Player.has_key == 0) {
nasiromar 11:6cd02a8539d1 212 door_locked();
nasiromar 11:6cd02a8539d1 213 }
rconnorlawson 0:35660d7952f7 214
nasiromar 9:cbb9cfb1f6c5 215 if((north->type == PLANT||south->type == PLANT||east->type == PLANT||west->type == PLANT||curr->type == PLANT)&&
nasiromar 10:e18685911e84 216 (north->data == FRUIT||south->data == FRUIT||east->data == FRUIT||west->data == FRUIT||curr->data == FRUIT)) {
nasiromar 9:cbb9cfb1f6c5 217 if(Player.HP < 100) {
nasiromar 9:cbb9cfb1f6c5 218 fruit();
nasiromar 9:cbb9cfb1f6c5 219 Player.HP += 5;
nasiromar 9:cbb9cfb1f6c5 220 north->data = NULL;
nasiromar 9:cbb9cfb1f6c5 221 south->data = NULL;
nasiromar 9:cbb9cfb1f6c5 222 east->data = NULL;
nasiromar 9:cbb9cfb1f6c5 223 west->data = NULL;
nasiromar 9:cbb9cfb1f6c5 224 curr->data = NULL;
nasiromar 13:798a4dd14c7e 225 wave_file = fopen("/sd/rupee-collect.wav","r");
nasiromar 13:798a4dd14c7e 226 waver.play(wave_file);
nasiromar 13:798a4dd14c7e 227 fclose(wave_file);
nasiromar 10:e18685911e84 228 } else
nasiromar 9:cbb9cfb1f6c5 229 no_fruit();
nasiromar 13:798a4dd14c7e 230
nasiromar 10:e18685911e84 231
nasiromar 10:e18685911e84 232
nasiromar 10:e18685911e84 233
nasiromar 10:e18685911e84 234
nasiromar 9:cbb9cfb1f6c5 235 }
nasiromar 10:e18685911e84 236 }
nasiromar 10:e18685911e84 237 break;
nasiromar 10:e18685911e84 238 case MENU_BUTTON: {
nasiromar 10:e18685911e84 239 init_spells();
nasiromar 10:e18685911e84 240 Player.spell = spell();
nasiromar 11:6cd02a8539d1 241 Player.MP -= 10;
nasiromar 10:e18685911e84 242 }
nasiromar 10:e18685911e84 243 break;
nasiromar 10:e18685911e84 244 case GOD_MODE: {
nasiromar 10:e18685911e84 245
nasiromar 10:e18685911e84 246 Player.god = !Player.god;
nasiromar 10:e18685911e84 247 if (Player.god) {
nasiromar 10:e18685911e84 248 god_modeOn();
nasiromar 10:e18685911e84 249 } else
nasiromar 10:e18685911e84 250 god_modeOff();
nasiromar 10:e18685911e84 251
nasiromar 10:e18685911e84 252 }
nasiromar 10:e18685911e84 253 break;
nasiromar 10:e18685911e84 254
nasiromar 10:e18685911e84 255 default:
nasiromar 10:e18685911e84 256
nasiromar 9:cbb9cfb1f6c5 257 break;
nasiromar 10:e18685911e84 258 }
nasiromar 10:e18685911e84 259
nasiromar 10:e18685911e84 260
nasiromar 10:e18685911e84 261 return NO_RESULT;
nasiromar 10:e18685911e84 262
nasiromar 10:e18685911e84 263
nasiromar 10:e18685911e84 264 }
nasiromar 10:e18685911e84 265
nasiromar 10:e18685911e84 266 /**
nasiromar 10:e18685911e84 267 * Entry point for frame drawing. This should be called once per iteration of
nasiromar 10:e18685911e84 268 * the game loop. This draws all tiles on the screen, followed by the status
nasiromar 10:e18685911e84 269 * bars. Unless init is nonzero, this function will optimize drawing by only
nasiromar 10:e18685911e84 270 * drawing tiles that have changed from the previous frame.
nasiromar 10:e18685911e84 271 */
nasiromar 10:e18685911e84 272 void draw_game(int init)
nasiromar 10:e18685911e84 273 {
nasiromar 10:e18685911e84 274 // Draw game border first
nasiromar 10:e18685911e84 275 if(init) draw_border();
nasiromar 10:e18685911e84 276
nasiromar 10:e18685911e84 277 // Iterate over all visible map tiles
nasiromar 10:e18685911e84 278 for (int i = -5; i <= 5; i++) { // Iterate over columns of tiles
nasiromar 10:e18685911e84 279 for (int j = -4; j <= 4; j++) { // Iterate over one column of tiles
nasiromar 10:e18685911e84 280 // Here, we have a given (i,j)
nasiromar 10:e18685911e84 281
nasiromar 10:e18685911e84 282 // Compute the current map (x,y) of this tile
nasiromar 10:e18685911e84 283 int x = i + Player.x;
nasiromar 10:e18685911e84 284 int y = j + Player.y;
nasiromar 9:cbb9cfb1f6c5 285
nasiromar 10:e18685911e84 286 // Compute the previous map (px, py) of this tile
nasiromar 10:e18685911e84 287 int px = i + Player.px;
nasiromar 10:e18685911e84 288 int py = j + Player.py;
nasiromar 10:e18685911e84 289
nasiromar 10:e18685911e84 290 // Compute u,v coordinates for drawing
nasiromar 10:e18685911e84 291 int u = (i+5)*11 + 3;
nasiromar 10:e18685911e84 292 int v = (j+4)*11 + 15;
nasiromar 10:e18685911e84 293
nasiromar 10:e18685911e84 294 // Figure out what to draw
nasiromar 10:e18685911e84 295 DrawFunc draw = NULL;
nasiromar 10:e18685911e84 296 if (init && i == 0 && j == 0) { // Only draw the player on init
nasiromar 10:e18685911e84 297 draw_player(u, v, Player.has_key);
nasiromar 10:e18685911e84 298 continue;
nasiromar 10:e18685911e84 299 } else if (x >= 0 && y >= 0 && x < map_width() && y < map_height()) { // Current (i,j) in the map
nasiromar 10:e18685911e84 300 MapItem* curr_item = get_here(x, y);
nasiromar 10:e18685911e84 301 MapItem* prev_item = get_here(px, py);
nasiromar 10:e18685911e84 302 if (init || curr_item != prev_item) { // Only draw if they're different
nasiromar 10:e18685911e84 303 if (curr_item) { // There's something here! Draw it
nasiromar 10:e18685911e84 304 draw = curr_item->draw;
nasiromar 10:e18685911e84 305 } else { // There used to be something, but now there isn't
nasiromar 10:e18685911e84 306 draw = draw_nothing;
nasiromar 10:e18685911e84 307 }
nasiromar 10:e18685911e84 308 }
nasiromar 10:e18685911e84 309 } else if (init) { // If doing a full draw, but we're out of bounds, draw the walls.
nasiromar 10:e18685911e84 310 draw = draw_wall;
nasiromar 9:cbb9cfb1f6c5 311 }
nasiromar 9:cbb9cfb1f6c5 312
nasiromar 10:e18685911e84 313 // Actually draw the tile
nasiromar 10:e18685911e84 314 if (draw) draw(u, v);
nasiromar 10:e18685911e84 315 }
rconnorlawson 0:35660d7952f7 316 }
rconnorlawson 0:35660d7952f7 317
nasiromar 10:e18685911e84 318 // Draw status bars
nasiromar 10:e18685911e84 319 draw_upper_status(Player.x,Player.y);
nasiromar 10:e18685911e84 320 draw_lower_status(Player.HP,Player.MP);
nasiromar 10:e18685911e84 321 }
nasiromar 9:cbb9cfb1f6c5 322
nasiromar 9:cbb9cfb1f6c5 323
nasiromar 10:e18685911e84 324 /**
nasiromar 10:e18685911e84 325 * Initialize the main world map. Add walls around the edges, interior chambers,
nasiromar 10:e18685911e84 326 * and plants in the background so you can see motion. Note: using the similar
nasiromar 10:e18685911e84 327 * procedure you can init the secondary map(s).
nasiromar 10:e18685911e84 328 */
nasiromar 10:e18685911e84 329 void init_main_map()
nasiromar 10:e18685911e84 330 {
nasiromar 10:e18685911e84 331 // "Random" plants
nasiromar 10:e18685911e84 332 Map* map = set_active_map(0);
nasiromar 11:6cd02a8539d1 333 for(int i = map_width() + 9; i < map_area(); i += 39) {
nasiromar 10:e18685911e84 334 add_plant(i % map_width(), i / map_width());
nasiromar 10:e18685911e84 335 }
nasiromar 10:e18685911e84 336 pc.printf("plants\r\n");
nasiromar 9:cbb9cfb1f6c5 337
nasiromar 10:e18685911e84 338 pc.printf("Adding walls!\r\n");
nasiromar 10:e18685911e84 339 add_wall(0, 0, HORIZONTAL, map_width());
nasiromar 10:e18685911e84 340 add_wall(0, map_height()-1, HORIZONTAL, map_width());
nasiromar 10:e18685911e84 341 add_wall(0, 0, VERTICAL, map_height());
nasiromar 10:e18685911e84 342 add_wall(map_width()-1, 0, VERTICAL, map_height());
nasiromar 10:e18685911e84 343 pc.printf("Walls done!\r\n");
nasiromar 10:e18685911e84 344
nasiromar 10:e18685911e84 345
nasiromar 10:e18685911e84 346
nasiromar 10:e18685911e84 347 for(int i = 7; i < 13; i++) {
nasiromar 10:e18685911e84 348 for (int j = 23; j <31; j++) {
nasiromar 10:e18685911e84 349 add_kindom(j,i);
nasiromar 9:cbb9cfb1f6c5 350 }
nasiromar 9:cbb9cfb1f6c5 351 }
rconnorlawson 0:35660d7952f7 352
rconnorlawson 0:35660d7952f7 353
nasiromar 10:e18685911e84 354
nasiromar 11:6cd02a8539d1 355 add_npc(9,9);
nasiromar 11:6cd02a8539d1 356
nasiromar 11:6cd02a8539d1 357 add_npc2(30,30);
nasiromar 11:6cd02a8539d1 358
nasiromar 13:798a4dd14c7e 359 add_merch(12,16);
nasiromar 11:6cd02a8539d1 360
nasiromar 10:e18685911e84 361 add_door(26,12);
nasiromar 10:e18685911e84 362
nasiromar 10:e18685911e84 363 add_portal(20,35);
nasiromar 10:e18685911e84 364
nasiromar 10:e18685911e84 365 print_map();
nasiromar 10:e18685911e84 366 }
nasiromar 10:e18685911e84 367
nasiromar 10:e18685911e84 368 /**
nasiromar 10:e18685911e84 369 * Program entry point! This is where it all begins.
nasiromar 10:e18685911e84 370 * This function orchestrates all the parts of the game. Most of your
nasiromar 10:e18685911e84 371 * implementation should be elsewhere - this holds the game loop, and should
nasiromar 10:e18685911e84 372 * read like a road map for the rest of the code.
nasiromar 10:e18685911e84 373 */
nasiromar 10:e18685911e84 374 int main()
nasiromar 10:e18685911e84 375 {
nasiromar 10:e18685911e84 376
nasiromar 10:e18685911e84 377 Player.HP = 100;
nasiromar 10:e18685911e84 378 Player.MP = 100;
nasiromar 10:e18685911e84 379
nasiromar 10:e18685911e84 380 // MapItem* north = get_north(Player.x,Player.y);
rconnorlawson 0:35660d7952f7 381
nasiromar 6:c9695079521d 382
nasiromar 10:e18685911e84 383 // First things first: initialize hardware
nasiromar 10:e18685911e84 384 ASSERT_P(hardware_init() == ERROR_NONE, "Hardware init failed!");
nasiromar 9:cbb9cfb1f6c5 385
nasiromar 10:e18685911e84 386 // Initialize the maps
nasiromar 10:e18685911e84 387 maps_init();
nasiromar 10:e18685911e84 388 init_main_map();
nasiromar 11:6cd02a8539d1 389 init_dung();
nasiromar 11:6cd02a8539d1 390
nasiromar 12:116a4cc85b16 391
nasiromar 10:e18685911e84 392
nasiromar 10:e18685911e84 393 // Initialize game state
nasiromar 10:e18685911e84 394 set_active_map(0);
nasiromar 10:e18685911e84 395 Player.x = Player.y = 5;
nasiromar 12:116a4cc85b16 396 Player.spell = NULL;
nasiromar 10:e18685911e84 397
nasiromar 10:e18685911e84 398 draw_start();
nasiromar 10:e18685911e84 399
nasiromar 12:116a4cc85b16 400 //wave_file = fopen("/sd/godfather.wav","r");
nasiromar 12:116a4cc85b16 401 //waver.play(wave_file);
nasiromar 12:116a4cc85b16 402 //fclose(wave_file);
nasiromar 10:e18685911e84 403
nasiromar 10:e18685911e84 404 while(1) {
nasiromar 10:e18685911e84 405
nasiromar 10:e18685911e84 406 Timer t;
nasiromar 10:e18685911e84 407 t.start();
nasiromar 10:e18685911e84 408 GameInputs inp = read_inputs();
nasiromar 10:e18685911e84 409 int action = get_action(inp);
nasiromar 10:e18685911e84 410
nasiromar 10:e18685911e84 411
nasiromar 10:e18685911e84 412 if( action == ACTION_BUTTON) {
nasiromar 10:e18685911e84 413
nasiromar 10:e18685911e84 414 break;
nasiromar 9:cbb9cfb1f6c5 415 }
nasiromar 10:e18685911e84 416 t.stop();
nasiromar 10:e18685911e84 417 int dt = t.read_ms();
nasiromar 10:e18685911e84 418 if (dt < 100) wait_ms(100-dt);
nasiromar 9:cbb9cfb1f6c5 419
nasiromar 9:cbb9cfb1f6c5 420 }
nasiromar 9:cbb9cfb1f6c5 421
nasiromar 6:c9695079521d 422
nasiromar 10:e18685911e84 423 // Initial drawing
nasiromar 10:e18685911e84 424 draw_game(true);
nasiromar 10:e18685911e84 425 // Main game loop
nasiromar 10:e18685911e84 426 while(1) {
nasiromar 10:e18685911e84 427 // Timer to measure game update speed
nasiromar 10:e18685911e84 428 Timer t;
nasiromar 10:e18685911e84 429 t.start();
nasiromar 6:c9695079521d 430
nasiromar 10:e18685911e84 431 // Actually do the game update:
nasiromar 10:e18685911e84 432 // 1. Read inputs
nasiromar 10:e18685911e84 433 GameInputs input = read_inputs();
nasiromar 10:e18685911e84 434 // 2. Determine action (get_action)
nasiromar 10:e18685911e84 435 int action = get_action(input);
nasiromar 10:e18685911e84 436 // 3. Update game (update_game)
nasiromar 10:e18685911e84 437 update_game(action);
nasiromar 10:e18685911e84 438 // 3b. Check for game over
nasiromar 10:e18685911e84 439 if(Player.won == 1) {
nasiromar 10:e18685911e84 440 draw_gameover();
nasiromar 10:e18685911e84 441 break;
nasiromar 10:e18685911e84 442 }
nasiromar 10:e18685911e84 443 // 4. Draw frame (draw_game)
nasiromar 10:e18685911e84 444 draw_game(true);
nasiromar 9:cbb9cfb1f6c5 445
nasiromar 10:e18685911e84 446 // 5. Frame delay
nasiromar 10:e18685911e84 447 t.stop();
nasiromar 10:e18685911e84 448 int dt = t.read_ms();
nasiromar 10:e18685911e84 449 if (dt < 100) wait_ms(100 - dt);
nasiromar 10:e18685911e84 450 }
nasiromar 10:e18685911e84 451 //
nasiromar 9:cbb9cfb1f6c5 452
nasiromar 9:cbb9cfb1f6c5 453
nasiromar 10:e18685911e84 454 }