Mochu Yao explorer game
Dependencies: mbed
Diff: Gameengine/Gameengine.cpp
- Revision:
- 19:14c5427b30d1
- Parent:
- 17:1b4ecc01b79f
- Child:
- 20:20e6ba54e15c
--- a/Gameengine/Gameengine.cpp Tue Apr 28 12:52:16 2020 +0000 +++ b/Gameengine/Gameengine.cpp Tue Apr 28 13:37:26 2020 +0000 @@ -46,7 +46,18 @@ check_reset(lcd, gamepad);} _start_flag = get_start_flag(); } - + +void Gameengine::get_explorer_y(Gamepad &gamepad) { + set_fall_flag(); + if (_f_flag == true) + { + _player.fall(_f_flag, gamepad); + } else { + _player.set_y_coordinate(false, _jump_height); } + _f_flag = _player.get_fall_flag(); + _player_y = _player.get_y(); + _jump_height = _player.get_jump_height(); } + void Gameengine::set_fall_flag() { if (((set_line_1.right < _player_x) && (_player_x < (set_line_1.left - 5))) && _player_y == 20) { _f_flag = true; } @@ -57,7 +68,8 @@ } void Gameengine::check_collision(Gamepad &gamepad) { - if (((_player_x - _item.get_item_x())< 7) && ((_player_y - _item.get_item_y()) < 7)) { + if ((_player_x == _item.get_item_x() + && (_player_y == _item.get_item_y() - 8)) { _collision_flag = true; _player_score++; _item.set_item(((rand()%80)+ 5) , ((rand()%80)+ 5)); // use the rand()%m function to generate a number from 80 to 1 @@ -94,17 +106,7 @@ void Gameengine::get_explorer_direction() {_player_direction = _player.get_direction(); } void Gameengine::get_sprite() {_explorer_sprite = _player.get_explorer_sprite(); } - -void Gameengine::get_explorer_y(Gamepad &gamepad) { - set_fall_flag(); - if (_f_flag == true) - { - _player.fall(_f_flag, gamepad); - } else { - _player.set_y_coordinate(false, _jump_height); } - _f_flag = _player.get_fall_flag(); - _player_y = _player.get_y(); - _jump_height = _player.get_jump_height(); } + void Gameengine::get_explorer_x() { _player_x = _player.get_x();