Library containing the Game Engine
Diff: GameEngine.cpp
- Revision:
- 10:df8ea4e747e2
- Parent:
- 9:0f359bc0922f
- Child:
- 11:832eb031310b
diff -r 0f359bc0922f -r df8ea4e747e2 GameEngine.cpp --- a/GameEngine.cpp Wed May 03 13:33:23 2017 +0000 +++ b/GameEngine.cpp Wed May 03 15:51:10 2017 +0000 @@ -12,6 +12,8 @@ void GameEngine::init() { + int HP = 8; + _hb.init(HP); } @@ -33,6 +35,8 @@ _t.draw(lcd); _tt.draw(lcd); _ttt.draw(lcd); + _hb.draw(lcd); + } @@ -45,6 +49,9 @@ _ttt.update(); CheckProjTargetCollision(pad); CheckPlayerTargetCollision(pad); + CheckTargetFloorCollision(pad); + _hb.update(); + } void GameEngine::get_pos() @@ -64,10 +71,51 @@ } + +///////////////////////////////////////////// +///////////////////////////////////////////// +///////////////////////////////////////////// + +void GameEngine::CheckTargetFloorCollision(Gamepad &pad) +{ + Vector2D t_pos = _t.get_pos(); + Vector2D tt_pos = _tt.get_pos(); + Vector2D ttt_pos = _ttt.get_pos(); + + //printf("%f t_pos \n", t_pos.y); + //printf("%f tt_pos \n", tt_pos.y); + //printf("%f ttt_pos \n", ttt_pos.y); + + if(t_pos.y == 47){ + printf("t floor \n"); + HPLost2 = HPLost2 - 1; + } + if(tt_pos.y == 47){ + printf("tt floor \n"); + HPLost2 = HPLost2 - 1; + } + if(ttt_pos.y == 47){ + printf("ttt floor \n"); + HPLost2 = HPLost2 - 1; + } + + printf("%d HP \n", HPLost2); + + _hb.MinusHP2(HPLost2); + + } +///////////////////////////////////////////// +///////////////////////////////////////////// +///////////////////////////////////////////// + + + + void GameEngine::CheckProjTargetCollision(Gamepad &pad) { + Vector2D proj_pos = _proj.get_pos(); Vector2D t_pos = _t.get_pos(); Vector2D tt_pos = _tt.get_pos(); @@ -229,11 +277,16 @@ } - +///////////////////////////////////////////// +///////////////////////////////////////////// +///////////////////////////////////////////// void GameEngine::CheckPlayerTargetCollision(Gamepad &pad) { + + + Vector2D t_pos = _t.get_pos(); Vector2D tt_pos = _tt.get_pos(); Vector2D ttt_pos = _ttt.get_pos(); @@ -281,12 +334,14 @@ (player_pos.x + 5 == t_pos.x + 10)) ) { - //printf("collision working \n"); + //printf("collision working3 \n"); // audio feedback //pad.tone(1000.0,0.1); t_pos.x = rand() % 79; t_pos.y = 0; - printf("hit"); + + HPLost1 = HPLost1 - 1; + } if ( @@ -330,12 +385,14 @@ (player_pos.x + 5 == tt_pos.x + 10)) ) { - //printf("collision working \n"); + //printf("collision working2 \n"); // audio feedback //pad.tone(1000.0,0.1); tt_pos.x = rand() % 79; tt_pos.y = 0; - printf("hit"); + + HPLost1 = HPLost1 - 1; + } if ( @@ -379,17 +436,21 @@ (player_pos.x + 5 == ttt_pos.x + 10)) ) { - //printf("collision working \n"); + //printf("collision working1 \n"); // audio feedback //pad.tone(1000.0,0.1); ttt_pos.x = rand() % 79; ttt_pos.y = 0; - printf("hit"); + + HPLost1 = HPLost1 - 1; + } + //printf("%d", HPLost1); //Kind of working?? _t.set_pos(t_pos); _tt.set_pos(tt_pos); _ttt.set_pos(ttt_pos); + _hb.MinusHP1(HPLost1); }