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: RosenEngine/RosenEngine.cpp
- Revision:
- 19:3316dba9787e
- Parent:
- 18:2cc6898de6b2
- Child:
- 20:5b4b3bf5795c
--- a/RosenEngine/RosenEngine.cpp Sat Apr 13 14:26:05 2019 +0000 +++ b/RosenEngine/RosenEngine.cpp Sat Apr 13 19:12:05 2019 +0000 @@ -111,8 +111,41 @@ void RosenEngine::check_enemy_ship_collision() { Vector2D ship_pos = _ship.get_pos(); - Vector2D s_pos = _enemy.get_seekerpos(); - if(ship_pos.x == s_pos.x && ship_pos.y == s_pos.y) { + Vector2D seeker_pos = _enemy.get_seekerpos(); + int ship_x[9]; + int ship_y[6]; + int seeker_x[9]; + int seeker_y[6]; + bool xcol = false; + bool ycol = false; + + // create an array of all x positions for the ship sprite i.e along its width (ship_x) + for(int countx = 0; countx>=9; countx=countx+1) { + ship_x[countx] = ship_pos.x + countx; + seeker_x[countx] = seeker_pos.x + countx; + } + + // create an array of all y positions for the ship sprite i.e along its height (ship_y) + for(int county = 0; county>=6; county=county+1) { + ship_y[county] = ship_pos.y + county; + seeker_y[county] = seeker_pos.y + county; + } + // check all values of ship position against all values of seekers x position + for(int nx = 0; nx>=9; nx=nx+1) { + for(int mx = 0; mx>=9; mx=mx+1) { + if(ship_x[nx] == seeker_x[mx]) { + xcol = true; + } + } + } + for(int ny = 0; ny>=6; ny=ny+1) { + for(int my = 0; my>=9; my=my+1) { + if(ship_y[ny] == seeker_y[my]) { + ycol = true; + } + } + } + if(xcol == true && ycol == true) { _health.update(1); _enemy.reset_seeker(); }