Game For ECE 2035
Dependencies: mbed wave_player 4DGL-uLCD-SE MMA8452
Diff: main.cpp
- Revision:
- 14:7225da81314a
- Parent:
- 13:798a4dd14c7e
- Child:
- 15:05592aaa468c
diff -r 798a4dd14c7e -r 7225da81314a main.cpp --- a/main.cpp Thu Dec 02 20:16:28 2021 +0000 +++ b/main.cpp Fri Dec 03 08:45:49 2021 +0000 @@ -15,9 +15,9 @@ void init_main_map (); int main (); +FILE *wave_file; -FILE *wave_file; @@ -34,6 +34,8 @@ int won; int HP,MP; int talked; + int gobs_slain,eye_slain; + int money; // You can add other properties for the player here } Player; @@ -97,7 +99,8 @@ // Game Life and Magic Points - +int purchase; +bool on_off = false; #define NO_RESULT 0 @@ -106,8 +109,7 @@ int update_game(int action) { //walk_goblin(0); - - + // Save player previous location before updating Player.px = Player.x; @@ -162,39 +164,97 @@ 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); Player.x = Player.y = 7; } - if((east->type == ENEMY1||west->type == ENEMY1||north->type == ENEMY1||south->type == ENEMY1)&& Player.spell == EARTH) { - Player.spell = NULL; + + + if(east->type == ENEMY1||west->type == ENEMY1||north->type == ENEMY1||south->type == ENEMY1) { + Player.HP-=2; + fire_dmg(); + gob_dmg(); + Player.HP-=10; + Player.x--; + Player.y--; + Player.gobs_slain += 1; map_delete(10,10); } - if((east->type == ENEMY2||west->type == ENEMY2||north->type == ENEMY2||south->type == ENEMY2)&& Player.spell == FIRE) { - Player.spell = NULL; - Player.HP-=2; + if(east->type == ENEMY2||west->type == ENEMY2||north->type == ENEMY2||south->type == ENEMY2) { + Player.HP-=12; + gob_dmg(); + Player.x--; + Player.y--; map_delete(5,7); } - if((east->type == ENEMY1||west->type == ENEMY1||north->type == ENEMY1||south->type == ENEMY1) && Player.spell == NULL) { + if(east->type == ENEMY||west->type == ENEMY||north->type == ENEMY||south->type == ENEMY) { Player.HP-=10; + eye_dmg(); + Player.eye_slain += 1; Player.x--; 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; + //wave_file = fopen("/sd/rupee-collect.wav","r"); + //waver.play(wave_file); + //fclose(wave_file); } - if((east->type == ENEMY2||west->type == ENEMY2||north->type == ENEMY2||south->type == ENEMY2) && Player.spell == NULL) { - Player.HP-=10; - Player.x--; - Player.y--; + 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){ + poti(); + Player.money -= 4; + Player.MP += 8; + } + + if (purchase == ELX && Player.money >= 5){ + elx(); + Player.money -= 5; + Player.HP += 10; + } + + if (purchase == FRT && Player.money >= 2){ + frt(); + Player.money -= 2; + Player.HP += 6; + } + if (Player.money <= 1){ + cantbuy(); + } + + merch_speech2(); } - if((north->type == DRAGON||south->type == DRAGON||east->type == DRAGON||west->type == DRAGON )&& Player.spell == WATER) { + 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); } @@ -222,9 +282,6 @@ east->data = NULL; west->data = NULL; curr->data = NULL; - wave_file = fopen("/sd/rupee-collect.wav","r"); - waver.play(wave_file); - fclose(wave_file); } else no_fruit(); @@ -237,8 +294,11 @@ break; case MENU_BUTTON: { init_spells(); - Player.spell = spell(); + + Player.spell = spell(); Player.MP -= 10; + uLCD.locate(15,15); + uLCD.printf("S:%1i",Player.spell); } break; case GOD_MODE: { @@ -269,6 +329,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 @@ -316,7 +379,7 @@ } // Draw status bars - draw_upper_status(Player.x,Player.y); + draw_upper_status(Player.x,Player.y,Player.money); draw_lower_status(Player.HP,Player.MP); } @@ -350,14 +413,29 @@ } } - + add_chest2(20,20); + add_chest2(5,8); + add_chest2(33,20); + add_chest2(14,16); + add_chest2(40,15); add_npc(9,9); add_npc2(30,30); + add_npc2(10,10); + + add_npc2(20,9); + add_merch(12,16); + 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); @@ -393,7 +471,9 @@ // Initialize game state set_active_map(0); Player.x = Player.y = 5; + Player.money = 0; Player.spell = NULL; + draw_start(); @@ -436,7 +516,7 @@ // 3. Update game (update_game) update_game(action); // 3b. Check for game over - if(Player.won == 1) { + if(Player.won == 1 || Player.HP <= 0) { draw_gameover(); break; }