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: GameEngine/GameEngine.cpp
- Revision:
- 4:87f3f3e5cdd9
- Parent:
- 3:97cd7b3d89d0
- Child:
- 5:8bd09c675f28
--- a/GameEngine/GameEngine.cpp Sun Apr 28 16:55:24 2019 +0000
+++ b/GameEngine/GameEngine.cpp Sun May 05 20:46:26 2019 +0000
@@ -2,34 +2,6 @@
-int bulletSymbol[8][4] = {
- { 0,1,1,0 },
- { 1,1,1,1 },
- { 1,1,1,1 },
- { 1,1,1,1 },
- { 1,1,1,1 },
- { 1,1,1,1 },
- { 0,0,0,0 },
- { 1,1,1,1 },
-};
-
-int healthSymbol[5][5] = {
- { 1,1,1,1,1 },
- { 1,1,0,1,1 },
- { 1,0,0,0,1 },
- { 1,1,0,1,1 },
- { 1,1,1,1,1 },
-};
-
-int shot[5][5] = {
- { 0,0,1,0,0 },
- { 0,1,1,1,0 },
- { 1,1,1,1,1 },
- { 0,1,1,1,0 },
- { 0,0,1,0,0 },
-};
-
-
GameEngine::GameEngine()
{
@@ -75,12 +47,15 @@
void GameEngine::draw(N5110 &lcd)
{
+
+
+
char level[14]; // each character is 6 pixels wide, screen is 84 pixels (84/6 = 14)
// so can display a string of a maximum 14 characters in length
// or create formatted strings - ensure they aren't more than 14 characters long
- int length = sprintf(level,"lvl: %i",_levelNumber); // print formatted data to buffer
+ int length = sprintf(level,"lvl:%i",_levelNumber); // print formatted data to buffer
// it is important the format specifier ensures the length will fit in the buffer
if (length <= 14) { // if string will fit on display (assuming printing at x=0)
lcd.printString(level,23,0);
@@ -141,35 +116,43 @@
void GameEngine::fireShot(Gamepad &gpad)
{
+ gpad.tone(400, 0.1);
Vector2D shotLoc = _crossHairs.get_pos();
for(int i = 0; i < _level.get_number_of_enemies(); i++) {
if (_enemies[i].get_alive()) {
- Vector2D enemyLoc = _enemies[i].get_pos();
- if (abs(enemyLoc.x - shotLoc.x) < 4) {
- if (abs(enemyLoc.y - shotLoc.y) < 4) {
- _killCount = _killCount + 1;
- _enemies[i].set_alive(false);
- Action myAc;
- myAc = dying;
- _enemies[i].set_current_action(myAc);
-
-
- if (_killCount == _level.get_number_of_enemies()) {
- _killCount = 0;
- _levelNumber = _levelNumber + 1;
- _enemies = _level.init(_levelNumber);
-
- }
-
- }
- }
+ was_enemy_shot(i, shotLoc);
}
}
}
+void GameEngine::was_enemy_shot(int i, Vector2D shotLoc)
+{
+
+ Vector2D enemyLoc = _enemies[i].get_pos();
+ if (abs(enemyLoc.x - shotLoc.x) < 4 && abs(enemyLoc.y - shotLoc.y) < 4) {
+ _killCount = _killCount + 1;
+ _enemies[i].set_alive(false);
+ Action myAc;
+ myAc = dying;
+ _enemies[i].set_current_action(myAc);
+
+
+ if (_killCount == _level.get_number_of_enemies()) {
+ _killCount = 0;
+ _levelNumber = _levelNumber + 1;
+ _enemies = _level.init(_levelNumber);
+ }
+ }
+
+
+}
+
+
+
+
bool GameEngine::get_game_over() {
return _game_over;