Dependencies: mbed
Diff: Game/Game.cpp
- Revision:
- 28:215e8327d4e6
- Parent:
- 26:04b2d7742a84
- Child:
- 29:532e5c371be4
--- a/Game/Game.cpp Mon May 25 19:52:37 2020 +0000 +++ b/Game/Game.cpp Tue May 26 14:45:02 2020 +0000 @@ -51,9 +51,9 @@ readInput(); if (_is_goal) { _score++; } else { - // ball should not go through obstacle hence y value limited to 21 - // this is done after calculations to ensure accurate results - if (_shot_y >= 9) { _shot_y = 21; } + //ball should not go through obstacle hence y value limited to 21 + //this is done after calculations to ensure accurate isGoal checking + if (_shot_y >= 9 && _shot_y <= 19) { _shot_y = 21; } if (_shot_y <= 5) { _shot_y = 3; } _lives--; } @@ -175,7 +175,7 @@ if (fp == NULL) { // if it can't open the file then print error message printf("Error! Unable to open file!\n"); } else { // opened file so can write - printf("Writing to file highscore: %d", _highscore); + printf("Writing to file highscore: %d \n", _highscore); fprintf(fp, "%d", _highscore); // ensure data type matches printf("Done.\n"); fclose(fp); // ensure you close the file after writing @@ -226,12 +226,12 @@ //fill and empty power meter _lcd -> drawRect(77, 27, 6, _y_val, FILL_BLACK); _y_val += _speed / 2; - if ((int) _y_val >= 20) { + if ((int) _y_val >= 20) { //power meter full _speed = (-1 * _speed); - } //power meter full - else if ((int) _y_val <= 0) { + } + else if ((int) _y_val <= 0) { // power meter empty _speed = abs(_speed); - } // power meter empty + } _lcd -> refresh(); _lcd -> clear(); wait(0.01); @@ -248,9 +248,9 @@ } void Game::convert_to_shot_y() { _shot_y = ((((int) _y_val) * (24)) / (20)); - if (_shot_y >= 19) { - _shot_y = 19; - } //shot is low, but must enter goal + if( _shot_y >= 21) { + _shot_y = 28; // Very little power, so ball does not reach goal + } } int Game::random_level_gen(int limit) { int number = (rand() % limit) + 1; //random level between 1-limit