Game For ECE 2035
Dependencies: mbed wave_player 4DGL-uLCD-SE MMA8452
Diff: main.cpp
- Revision:
- 15:05592aaa468c
- Parent:
- 14:7225da81314a
- Child:
- 16:06a88c0110ff
diff -r 7225da81314a -r 05592aaa468c main.cpp --- a/main.cpp Fri Dec 03 08:45:49 2021 +0000 +++ b/main.cpp Fri Dec 03 09:50:47 2021 +0000 @@ -39,7 +39,7 @@ // You can add other properties for the player here } Player; - +int i = 3; /** * Given the game inputs, determine what kind of update needs to happen. @@ -108,10 +108,10 @@ #define FULL_DRAW 2 int update_game(int action) { - //walk_goblin(0); - - - // Save player previous location before updating + walk_npc(); + + +// Save player previous location before updating Player.px = Player.x; Player.py = Player.y; @@ -162,21 +162,22 @@ if(east->type == NPC||west->type == NPC||north->type == NPC||south->type == NPC && Player.has_key == 0 ) { npc_speech1(); + Player.talked = 1; } - + if(east->type == NPCT||west->type == NPCT||north->type == NPCT||south->type == NPCT && Player.has_key == 0 ) { npc2_speech(); Player.talked = 1; } if(north->type == PORTAL||south->type == PORTAL||east->type == PORTAL||west->type == PORTAL) { - set_active_map(1); + set_active_map(1); Player.x = Player.y = 7; } - - - + + + if(east->type == ENEMY1||west->type == ENEMY1||north->type == ENEMY1||south->type == ENEMY1) { Player.HP-=2; fire_dmg(); @@ -187,7 +188,7 @@ Player.gobs_slain += 1; map_delete(10,10); } - + if(east->type == ENEMY2||west->type == ENEMY2||north->type == ENEMY2||south->type == ENEMY2) { Player.HP-=12; gob_dmg(); @@ -195,7 +196,7 @@ Player.y--; map_delete(5,7); } - + if(east->type == ENEMY||west->type == ENEMY||north->type == ENEMY||south->type == ENEMY) { Player.HP-=10; eye_dmg(); @@ -204,12 +205,12 @@ Player.y--; map_delete(15,15); } - + if(east->type == CHEST||west->type == CHEST||north->type == CHEST||south->type == CHEST && Player.MP < 100) { potion(); Player.MP += 5; } - + if(east->type == CHESTT||west->type == CHESTT||north->type == CHESTT||south->type == CHESTT) { money_chest(); Player.money += 2; @@ -217,110 +218,124 @@ //waver.play(wave_file); //fclose(wave_file); } - + if(east->type == VILL||west->type == VILL||north->type == VILL||south->type == VILL) { merch_speech1(); init_store(); purchase = store(); - - if (purchase == POT && Player.money >= 4){ + + if (purchase == POT && Player.money >= 4) { poti(); Player.money -= 4; Player.MP += 8; - } - - if (purchase == ELX && Player.money >= 5){ + } + + if (purchase == ELX && Player.money >= 5) { elx(); Player.money -= 5; Player.HP += 10; - } - - if (purchase == FRT && Player.money >= 2){ + } + + if (purchase == FRT && Player.money >= 2) { frt(); Player.money -= 2; Player.HP += 6; - } - if (Player.money <= 1){ + } + if (Player.money <= 1) { cantbuy(); - } - - merch_speech2(); - } - + } - if(north->type == DRAGON||south->type == DRAGON||east->type == DRAGON||west->type == DRAGON) { - if ( Player.spell == WATER){ - - slay_dragon(); - Player.has_key = 1; - } - - //walk_goblin(0); + merch_speech2(); } - if(north->type == PORTAl||south->type == PORTAl||east->type == PORTAl||west->type == PORTAl) { - set_active_map(0); - Player.x=20; - Player.y = 36; - } + + if(north->type == DRAGON||south->type == DRAGON||east->type == DRAGON||west->type == DRAGON && i >0) { + + if ( Player.spell == WATER && Player.gobs_slain == 1 && Player.eye_slain == 1) { + drg(); + i--; - if((north->type == DOOR||south->type == DOOR||east->type == DOOR||west->type == DOOR)&&Player.has_key == 1) { - Player.won = door_open(); - } + } else + Player.HP-=50; + Player.x--; + Player.y--; + + + if (i <=0) { + slay_dragon(); + map_erase(15,9); + Player.has_key = 1; + - if((north->type == DOOR||south->type == DOOR||east->type == DOOR||west->type == DOOR)&&Player.has_key == 0) { - door_locked(); - } +} +} + + + - if((north->type == PLANT||south->type == PLANT||east->type == PLANT||west->type == PLANT||curr->type == PLANT)&& - (north->data == FRUIT||south->data == FRUIT||east->data == FRUIT||west->data == FRUIT||curr->data == FRUIT)) { - if(Player.HP < 100) { - fruit(); - Player.HP += 5; - north->data = NULL; - south->data = NULL; - east->data = NULL; - west->data = NULL; - curr->data = NULL; - } else - no_fruit(); - + if(north->type == PORTAl||south->type == PORTAl||east->type == PORTAl||west->type == PORTAl) { + set_active_map(0); + Player.x=20; + Player.y = 36; + } + + if((north->type == DOOR||south->type == DOOR||east->type == DOOR||west->type == DOOR)&&Player.has_key == 1) { + Player.won = door_open(); + } + + if((north->type == DOOR||south->type == DOOR||east->type == DOOR||west->type == DOOR)&&Player.has_key == 0) { + door_locked(); + } + + if((north->type == PLANT||south->type == PLANT||east->type == PLANT||west->type == PLANT||curr->type == PLANT)&& + (north->data == FRUIT||south->data == FRUIT||east->data == FRUIT||west->data == FRUIT||curr->data == FRUIT)) { + if(Player.HP < 100) { + fruit(); + Player.HP += 5; + north->data = NULL; + south->data = NULL; + east->data = NULL; + west->data = NULL; + curr->data = NULL; + } else + no_fruit(); - } - } - break; - case MENU_BUTTON: { - init_spells(); - - Player.spell = spell(); - Player.MP -= 10; - uLCD.locate(15,15); - uLCD.printf("S:%1i",Player.spell); - } - break; - case GOD_MODE: { - - Player.god = !Player.god; - if (Player.god) { - god_modeOn(); - } else - god_modeOff(); } - break; + } + break; +case MENU_BUTTON: { + init_spells(); - default: - - break; + Player.spell = spell(); + Player.MP -= 10; + uLCD.locate(15,15); + uLCD.printf("S:%1i",Player.spell); } - - - return NO_RESULT; + break; +case GOD_MODE: { + + Player.god = !Player.god; + if (Player.god) { + god_modeOn(); + } else + god_modeOff(); - + } + break; + +default: + + break; +} + + +return NO_RESULT; + + } /** @@ -329,9 +344,9 @@ * bars. Unless init is nonzero, this function will optimize drawing by only * drawing tiles that have changed from the previous frame. */ - + - + void draw_game(int init) { // Draw game border first @@ -419,23 +434,23 @@ add_chest2(14,16); add_chest2(40,15); - add_npc(9,9); - + add_npc(10,5); + add_npc2(30,30); - - add_npc2(10,10); - + + add_npc2(11,11); + add_npc2(20,9); - + add_merch(12,16); - - for(int i = 11; i <= 13; i++){ + + for(int i = 11; i <= 13; i++) { add_store(i,15); - } - + } + add_fire(27,13); add_fire(25,13); - + add_door(26,12); add_portal(20,35); @@ -465,15 +480,15 @@ maps_init(); init_main_map(); init_dung(); - - + + // Initialize game state set_active_map(0); Player.x = Player.y = 5; Player.money = 0; Player.spell = NULL; - + draw_start();