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: Floors/Floors.cpp
- Revision:
- 35:b99b563c3eb6
- Parent:
- 34:a9b14a4ccd46
--- a/Floors/Floors.cpp Thu May 09 14:07:09 2019 +0000
+++ b/Floors/Floors.cpp Thu May 09 14:17:12 2019 +0000
@@ -24,12 +24,14 @@
}
+// Prints the floor into the LCD screen by calling a function from the LCD to draw a 14 x 1 rectangle
void Floors::draw(N5110 &lcd)
{
lcd.drawRect(_position.x, _position.y, _width, _height, FILL_BLACK);
eny.draw(lcd); // draws enemy
}
+// Updates the position of the floor
void Floors::update(float doodler_pos_x, float doodler_pos_y, float _bullet_pos_x, float _bullet_pos_y)
{ // when they leave the screen they will re-appear in random x-coordinate so that 10 floors are always on screen
// rectangle (1-82 & 9 - 48 )
@@ -47,14 +49,15 @@
put_enemy = false;
}
}
- if (_doodler_pos_y < 16) { // shift floors once doodler reaches this value on the screen
+ if (_doodler_pos_y < 16) { // shift floors once doodler reaches 16 y-coordinate position threshold on the screen
// I chose this value because testing with the doodler's jump, it allows the doodler to keep jumping on a floor
// without it moving down and dissapearing
_position.y += 1;
}
- check_enemy(_bullet_pos_x, _bullet_pos_y);
+ check_enemy(_bullet_pos_x, _bullet_pos_y);
}
+// Function to check if doodler or bullet have collided with the enemy
void Floors::check_enemy(float _bullet_pos_x, float _bullet_pos_y)
{
enemy_position = eny.get_position();
@@ -67,7 +70,7 @@
(_doodler_pos_y <= enemy_position.y + 11) &&
(_doodler_pos_y >= enemy_position.y)
) {
- end_game = true;
+ end_game = true; // if doodler collides with enemy, the end_game variable will state the game should end
}
if ( // to check if the bullet has collided with the ghost
(_bullet_pos_x <= enemy_position.x + 12) &&
@@ -75,12 +78,16 @@
(_bullet_pos_y <= enemy_position.y + 11) &&
(_bullet_pos_y >= enemy_position.y)
) {
- eny.erase();
+ eny.erase(); // if bullet collides with enemy the erase function is called
}
}
+
+// Returns the current floor's position. It is called in the engine to compare its position with the other classes.
Vector2D Floors::get_position() { Vector2D p = {_position.x,_position.y}; return p; }
+
+// Sets the position within the floor class by inputing the new values from the engine, where the function is called.
void Floors::set_position(Vector2D pos) { _position.x = pos.x; _position.y = pos.y; }
// The get_end_game function can be called in the engine to check if the game should end or not (if the doodler has collided