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:
- 16:331be5c7ed80
- Parent:
- 15:876c047a6ec9
- Child:
- 17:f377df4ea7b1
--- a/Engine/Engine.cpp Sat Apr 06 17:13:37 2019 +0000 +++ b/Engine/Engine.cpp Wed Apr 10 13:40:58 2019 +0000 @@ -14,6 +14,7 @@ _upper_map.init(22); _skater.set_reset_flag(false); _coin.init(); + _spikes.init(); _coin_collision_flag = false; _player_score = 0; srand(time(NULL)); @@ -28,6 +29,7 @@ _upper_map.init(22); _skater.set_reset_flag(false); _coin.init(); + _spikes.init(); _player_score = 0; wait(1); } @@ -113,10 +115,12 @@ } } -void Engine::generate_map() { +void Engine::generate_level() { + // Generate parameters for all objects in the level (except skater) generate_lower_lines(); generate_upper_lines(); _coin.generate_coin(); + generate_spikes(); } void Engine::generate_lower_lines() { @@ -143,11 +147,14 @@ _upper_line_3 = _upper_map.get_line_3(); } +void Engine::generate_spikes() { + _spikes.update_spikes(); +} + void Engine::update_lcd(N5110 &lcd){ lcd.drawSprite(_x,_y,17,10,(int *)_skater.get_sprite(_sprite)); - // if (!_coin_collision_flag) { - lcd.drawSprite(_coin.get_coin_x(),_coin.get_coin_y(),5,5,(int*)_coin.get_coin_sprite()); - // } + lcd.drawSprite(_coin.get_coin_x(),_coin.get_coin_y(),5,5,(int*)_coin.get_coin_sprite()); + lcd.drawSprite(_spikes.get_spikes_x(),23,5,8,(int*)_spikes.get_spikes_sprite()); 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); @@ -166,9 +173,20 @@ } void Engine::check_coin_collision() { - if (_x == _coin.get_coin_x()) { + // If the skater coords match the coins, add 1 to the players score and print + // a new coin in a random position + if (_x == _coin.get_coin_x() && (_y == _coin.get_coin_y() - 10)) { _coin_collision_flag = true; _player_score++; _coin.update_coin((rand() % 100),(abs(rand() % 100 - 20))); } -} \ No newline at end of file +} + +void Engine::check_spikes_collision() { + // If the skaters coord match the spikes and he is not ducking, the player has died + // and the game is reset. + if (_input.coord.y > -0.1 && _x == _spikes.get_spikes_x() && _y == 23) { + _skater.set_reset_flag(true); + } +} + \ No newline at end of file