Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Diff: Engine/Engine.cpp
- Revision:
- 10:8bf3713d9e9c
- Parent:
- 9:fff2009f826e
- Child:
- 11:b66170249a26
--- a/Engine/Engine.cpp Sun Mar 24 19:22:50 2019 +0000 +++ b/Engine/Engine.cpp Tue Mar 26 11:03:05 2019 +0000 @@ -7,7 +7,8 @@ void Engine::check_reset() { if (_skater.get_reset_flag()) { reset_skater(); - _map.init(); + _lower_map.init(40); + _upper_map.init(22); _skater.set_reset_flag(false); wait(1); } @@ -17,14 +18,15 @@ _moving_counter = 0; _jump_counter = 0; _direction = Left; - _level = 0; + _level_condition = 0; _x = 40; _y = 40; } void Engine::init() { reset_skater(); - _map.init(); + _lower_map.init(40); + _upper_map.init(22); srand(time(NULL)); } @@ -38,7 +40,7 @@ if (_fall_flag) { _skater.fall(_fall_flag); } else { - _skater.set_y_position( _input.A_flag, _jump_counter, _level ); + _skater.set_y_position( _input.A_flag, _jump_counter, _level_condition ); } _fall_flag = _skater.get_fall_flag(); _y = _skater.get_y_position(); @@ -46,11 +48,11 @@ } void Engine::set_fall_flag() { - if (((_line_1.x_end < _x) && (_x < (_line_2.x_start - 6))) && _y == 23) { + if (((_lower_line_1.x_end < _x) && (_x < (_lower_line_2.x_start - 6))) && _y == 23) { _fall_flag = true; - } else if (((_line_2.x_end < _x) && (_x < (_line_3.x_start - 6))) && _y == 23) { + } else if (((_lower_line_2.x_end < _x) && (_x < (_lower_line_3.x_start - 6))) && _y == 23) { _fall_flag = true; - } else if (((_line_3.x_end < _x) && (_x < (_line_1.x_start - 6))) && _y == 23) { + } else if (((_lower_line_3.x_end < _x) && (_x < (_lower_line_1.x_start - 6))) && _y == 23) { _fall_flag = true; } } @@ -65,7 +67,7 @@ _input.coord.y); _x = _skater.get_x_position(); _moving_counter = _skater.get_moving_counter(); - if ((t % 6 == 0 || t % 8 == 0) && (_input.coord.x > -0.1)) { + if ((t % 4 == 0) && (_input.coord.x > -0.1)) { _moving_counter--; } } @@ -77,31 +79,51 @@ } -void Engine::find_level() { - if ((_x >= 1 && _x <= 30 && _y < 15) || (_x >= 45 && _x <= 80 && _y < 15)) { - _level = 1; +void Engine::set_level_condition() { + if (((_upper_line_1.x_start - 6) <= _x) && (_x <= _upper_line_1.x_end)) { + _level_condition = 1; + } else if (((_upper_line_2.x_start - 6) <= _x) && (_x <= _upper_line_2.x_end)) { + _level_condition = 1; + } else if (((_upper_line_3.x_start - 6) <= _x) && (_x <= _upper_line_3.x_end)) { + _level_condition = 1; } else { - _level = 0; - } + _level_condition = 0; + } } void Engine::generate_map() { - _length_1 = (rand() %20) + 10; - _map.generate_line_1(_length_1); - _line_1 = _map.get_line_1(); - _length_2 = (rand() %20) + 10; - _map.generate_line_2(_length_2); - _line_2 = _map.get_line_2(); - _length_3 = (rand() %20) + 10; - _map.generate_line_3(_length_3); - _line_3 = _map.get_line_3(); + generate_lower_lines(); + generate_upper_lines(); } +void Engine::generate_lower_lines() { + _length_1 = (rand() %20) + 10; + _lower_map.generate_line_1(_length_1); + _lower_line_1 = _lower_map.get_line_1(); + _length_2 = (rand() %20) + 10; + _lower_map.generate_line_2(_length_2); + _lower_line_2 = _lower_map.get_line_2(); + _length_3 = (rand() %20) + 10; + _lower_map.generate_line_3(_length_3); + _lower_line_3 = _lower_map.get_line_3(); +} + +void Engine::generate_upper_lines() { + _upper_map.generate_line_1(_length_1 / 2); + _upper_line_1 = _upper_map.get_line_1(); + _upper_map.generate_line_2(_length_2 / 2); + _upper_line_2 = _upper_map.get_line_2(); + _upper_map.generate_line_3(_length_3 / 2); + _upper_line_3 = _upper_map.get_line_3(); +} void Engine::update_lcd(N5110 &lcd){ _skate_sprite = _skater.get_sprite(_sprite); lcd.drawSprite(_x,_y,17,10,(int *)_skate_sprite); - lcd.drawLine(_line_2.x_start,_line_2.y,_line_2.x_end,_line_2.y,FILL_BLACK); - lcd.drawLine(_line_1.x_start,_line_1.y,_line_1.x_end,_line_1.y,FILL_BLACK); - lcd.drawLine(_line_3.x_start,_line_3.y,_line_3.x_end,_line_3.y,FILL_BLACK); + lcd.drawLine(_lower_line_2.x_start,_lower_line_2.y,_lower_line_2.x_end,_lower_line_2.y,FILL_BLACK); + lcd.drawLine(_lower_line_1.x_start,_lower_line_1.y,_lower_line_1.x_end,_lower_line_1.y,FILL_BLACK); + lcd.drawLine(_lower_line_3.x_start,_lower_line_3.y,_lower_line_3.x_end,_lower_line_3.y,FILL_BLACK); + lcd.drawLine(_upper_line_2.x_start,_upper_line_2.y,_upper_line_2.x_end,_upper_line_2.y,FILL_BLACK); + lcd.drawLine(_upper_line_1.x_start,_upper_line_1.y,_upper_line_1.x_end,_upper_line_1.y,FILL_BLACK); + lcd.drawLine(_upper_line_3.x_start,_upper_line_3.y,_upper_line_3.x_end,_upper_line_3.y,FILL_BLACK); } \ No newline at end of file