Mortal Kombat Game ELEC2645
Dependencies: mbed N5110 ShiftReg Joystick
GameEngine.cpp@10:e83899f11e8a, 2021-04-23 (annotated)
- Committer:
- ozy
- Date:
- Fri Apr 23 23:49:10 2021 +0000
- Revision:
- 10:e83899f11e8a
- Parent:
- 8:e2e2eb4ea0ca
- Child:
- 12:b4477a312158
Code after In sync fighters
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ozy | 6:a1a7dc264fed | 1 | #include "GameEngine.h" |
ozy | 6:a1a7dc264fed | 2 | |
ozy | 6:a1a7dc264fed | 3 | GameEngine::GameEngine() {} |
ozy | 6:a1a7dc264fed | 4 | |
ozy | 7:737fb0c3dbef | 5 | void GameEngine::init(){ |
ozy | 7:737fb0c3dbef | 6 | _fighter.init(); |
ozy | 6:a1a7dc264fed | 7 | } |
ozy | 6:a1a7dc264fed | 8 | |
ozy | 7:737fb0c3dbef | 9 | void GameEngine::start(N5110 &lcd, DigitalIn &buttonA, DigitalIn &buttonB, DigitalIn &buttonC, DigitalIn &buttonD, AnalogIn &joy_v, AnalogIn &joy_h) { |
ozy | 7:737fb0c3dbef | 10 | // function that draws fighter and allows user to control it |
ozy | 7:737fb0c3dbef | 11 | _fighter.move_fighter(lcd, buttonA, buttonB, buttonC, buttonD, joy_v, joy_h); |
ozy | 8:e2e2eb4ea0ca | 12 | _enemy.init(); |
ozy | 8:e2e2eb4ea0ca | 13 | enemy_AI(lcd); |
ozy | 7:737fb0c3dbef | 14 | lcd.refresh(); |
ozy | 10:e83899f11e8a | 15 | |
ozy | 7:737fb0c3dbef | 16 | } |
ozy | 7:737fb0c3dbef | 17 | |
ozy | 8:e2e2eb4ea0ca | 18 | void GameEngine::enemy_AI(N5110 &lcd) { |
ozy | 8:e2e2eb4ea0ca | 19 | int fighter_pos = _fighter.get_x(); |
ozy | 8:e2e2eb4ea0ca | 20 | printf("f pos = %i \n", fighter_pos); |
ozy | 8:e2e2eb4ea0ca | 21 | int enemy_pos = _enemy.get_x(); |
ozy | 8:e2e2eb4ea0ca | 22 | printf("e pos = %i \n", enemy_pos); |
ozy | 10:e83899f11e8a | 23 | |
ozy | 8:e2e2eb4ea0ca | 24 | int input = 0; |
ozy | 8:e2e2eb4ea0ca | 25 | int diff = fighter_pos - enemy_pos; |
ozy | 8:e2e2eb4ea0ca | 26 | printf("diff = %i \n", diff); |
ozy | 8:e2e2eb4ea0ca | 27 | // if difference is positive, fighter is to the right so enemy must look right (when input is 1, enemy looks right) |
ozy | 8:e2e2eb4ea0ca | 28 | if (diff > 0) { |
ozy | 8:e2e2eb4ea0ca | 29 | input = 1; |
ozy | 8:e2e2eb4ea0ca | 30 | } |
ozy | 8:e2e2eb4ea0ca | 31 | else {input = 0;} |
ozy | 8:e2e2eb4ea0ca | 32 | _enemy.draw(lcd, input); |
ozy | 10:e83899f11e8a | 33 | // lcd.refresh(); |
ozy | 8:e2e2eb4ea0ca | 34 | } |
ozy | 8:e2e2eb4ea0ca | 35 | |
ozy | 8:e2e2eb4ea0ca | 36 |