Mortal Kombat Game ELEC2645
Dependencies: mbed N5110 ShiftReg Joystick
Diff: GameEngine.cpp
- Revision:
- 12:b4477a312158
- Parent:
- 10:e83899f11e8a
- Child:
- 13:eaf070d5f599
--- a/GameEngine.cpp Sat Apr 24 00:00:14 2021 +0000 +++ b/GameEngine.cpp Sun Apr 25 00:16:59 2021 +0000 @@ -7,10 +7,11 @@ } void GameEngine::start(N5110 &lcd, DigitalIn &buttonA, DigitalIn &buttonB, DigitalIn &buttonC, DigitalIn &buttonD, AnalogIn &joy_v, AnalogIn &joy_h) { + // initializing and drawing enemy + _enemy.init(); + enemy_AI(lcd); // function that draws fighter and allows user to control it _fighter.move_fighter(lcd, buttonA, buttonB, buttonC, buttonD, joy_v, joy_h); - _enemy.init(); - enemy_AI(lcd); lcd.refresh(); } @@ -24,13 +25,16 @@ int input = 0; int diff = fighter_pos - enemy_pos; printf("diff = %i \n", diff); - // if difference is positive, fighter is to the right so enemy must look right (when input is 1, enemy looks right) + // if difference is positive, fighter is to the right so enemy must look right (if input is 1, enemy looks right) and vice versa if (diff > 0) { input = 1; } else {input = 0;} _enemy.draw(lcd, input); - // lcd.refresh(); + if (diff >= -15 && diff <= 15){ // randomize enemy fight moves only in fighting range + _enemy.randomize_moves(lcd, input); + } + }