Library containing the Game Engine
Diff: GameEngine.cpp
- Revision:
- 7:cf6304ef44fd
- Parent:
- 6:c710fbc0f48e
- Child:
- 8:bd718162a87c
diff -r c710fbc0f48e -r cf6304ef44fd GameEngine.cpp --- a/GameEngine.cpp Tue May 02 15:46:59 2017 +0000 +++ b/GameEngine.cpp Tue May 02 16:25:26 2017 +0000 @@ -30,8 +30,6 @@ _p.draw(lcd); _proj.draw(lcd); _t.draw(lcd); - _t.draw(lcd); - _t.draw(lcd); } @@ -40,7 +38,7 @@ _p.update(_d,_mag); _proj.update(); _t.update(); - + CheckProjTargetCollision(pad); } void GameEngine::get_pos() @@ -55,9 +53,52 @@ playerx = player_pos.x; playery = player_pos.y; - printf("playerxy in GAME = %d %d \n", playerx, playery); + //printf("playerxy in GAME = %d %d \n", playerx, playery); _proj.init(playerx,playery); + } + - } \ No newline at end of file +void GameEngine::CheckProjTargetCollision(Gamepad &pad) +{ + Vector2D proj_pos = _proj.get_pos(); + Vector2D t_pos = _t.get_pos(); + Vector2D player_pos = _p.get_pos(); + // printf("proj %f %f \n", proj_pos.x, proj_pos.y); + //printf("targ %f %f \n", t_pos.x, t_pos.y); + + if ( + ((proj_pos.y == t_pos.y) || + (proj_pos.y == t_pos.y + 1) || + (proj_pos.y == t_pos.y + 2) || + (proj_pos.y == t_pos.y + 3) || + (proj_pos.y == t_pos.y + 4)) && + ((proj_pos.x == t_pos.x) || + (proj_pos.x == t_pos.x + 1) || + (proj_pos.x == t_pos.x + 2) || + (proj_pos.x == t_pos.x + 3) || + (proj_pos.x == t_pos.x + 4)) + ) { + + printf("yeaaaaaaaaaaaaah boiiiiiiiiiiii \n"); + proj_pos.x = player_pos.x +1; + proj_pos.y = player_pos.y +1; + t_pos.x = rand() % 79; + t_pos.y = 0; + // audio feedback + //pad.tone(1000.0,0.1); + } + + _proj.set_pos(proj_pos); + _t.set_pos(t_pos); + + + } + + + + + + + \ No newline at end of file