Mortal Kombat Game ELEC2645
Dependencies: mbed N5110 ShiftReg Joystick
Diff: Enemy.cpp
- Revision:
- 14:7f23841685ad
- Parent:
- 13:eaf070d5f599
- Child:
- 15:7fd2d34f3be5
diff -r eaf070d5f599 -r 7f23841685ad Enemy.cpp --- a/Enemy.cpp Sun Apr 25 15:04:06 2021 +0000 +++ b/Enemy.cpp Mon Apr 26 22:19:28 2021 +0000 @@ -28,29 +28,12 @@ _y += y; } -void Enemy::init(int input) { - // function to initialize position of each enemy god - if (input == 1){ - set_x(50); - set_y(34); - } - else if (input == 2) { - set_x(10); - set_y(34); - } - else if (input == 3) { - set_x(55); - set_y(34); - } - else if (input == 4) { - set_x(15); - set_y(34); - } - else if (input == 5) { - set_x(56); - set_y(34); - } - +void Enemy::init() { + // function to randomly initialize position of each enemy god + int rrandom = rand()%64; + set_x(20); + set_y(34); + } void Enemy::draw(N5110 &lcd, int input) { @@ -111,7 +94,7 @@ { 0,0,0,0,1,1,0,0,0,0 }, }; - const int run_left2[12][10] = { + const int midrun_left[12][10] = { { 0,0,1,1,1,0,0,0,0,0 }, { 0,0,1,1,1,0,0,0,0,0 }, { 0,0,0,1,1,1,1,1,1,0 }, @@ -125,18 +108,15 @@ { 0,0,0,0,1,0,1,0,0,0 }, { 0,0,0,1,0,0,0,1,0,0 }, }; - // x position - add_x(-4); // move enemy to the left across lcd through increments - - // code to toggle between both move left animations (show some leg movement!) - int x = rand() % 5; + // code to toggle between both move left animations + int x = rand() % 2; if (x == 0) { - // x = 1; + x = 1; lcd.drawSprite(_x,_y,12,10,(int *)run_left); } else if(x == 1) { - // x = 0; - lcd.drawSprite(_x,_y,12,10,(int *)run_left2); + x = 0; + lcd.drawSprite(_x,_y,12,10,(int *)midrun_left); } } @@ -159,11 +139,7 @@ { 0,0,0,0,0,1,1,0,0,0 }, { 0,0,0,0,1,1,0,0,0,0 }, }; -lcd.drawSprite(_x,_y,12,10,(int *)run_right); -} - -void Enemy::move_right2(N5110 &lcd) { -const int midrun_right[12][10] = { + const int midrun_right[12][10] = { { 0,0,0,0,0,1,1,1,0,0 }, { 0,0,0,0,0,1,1,1,0,0 }, { 0,0,0,1,1,1,1,0,0,0 }, @@ -177,10 +153,20 @@ { 0,0,0,1,0,1,0,0,0,0 }, { 0,0,1,0,0,0,1,0,0,0 }, }; -lcd.drawSprite(_x,_y,12,10,(int *)midrun_right); +// code to toggle between both move right animations + int x = rand() % 2; + if (x == 0) { + x = 1; + lcd.drawSprite(_x,_y,12,10,(int *)run_right); + } + else if(x == 1) { + x = 0; + lcd.drawSprite(_x,_y,12,10,(int *)midrun_right); + } } + void Enemy::sword_right(N5110 &lcd) { const int swordsprite[12][10] = { { 0,0,1,1,1,1,0,0,0,0 }, @@ -267,15 +253,15 @@ void Enemy::twoway_punch(N5110 &lcd){ const int punchpunch[12][10] = { { 0,0,0,0,0,0,0,0,0,0 }, - { 0,0,0,0,1,1,0,0,0,0 }, + { 1,0,0,0,1,1,0,0,0,1 }, + { 0,1,0,0,1,1,0,1,1,0 }, + { 0,0,1,0,1,1,0,1,1,0 }, + { 0,0,0,1,1,1,1,0,0,0 }, { 0,0,0,0,1,1,0,0,0,0 }, - { 0,0,0,0,1,1,0,0,1,0 }, - { 1,1,1,1,1,1,1,1,1,1 }, - { 0,0,0,0,1,1,0,0,1,0 }, { 0,0,0,0,1,1,0,0,0,0 }, { 0,0,0,1,1,1,1,0,0,0 }, { 0,0,1,1,0,0,1,1,0,0 }, - { 0,1,0,0,0,0,0,0,1,0 }, + { 0,1,1,0,0,0,0,1,1,0 }, { 0,1,0,0,0,0,0,0,1,0 }, { 0,1,0,0,0,0,0,0,1,0 }, };