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: engine/engine.cpp
- Revision:
- 7:1964f649676e
- Parent:
- 6:46d0caedf217
- Child:
- 8:4a5e96ed2347
--- a/engine/engine.cpp Tue Apr 17 20:53:43 2018 +0000
+++ b/engine/engine.cpp Tue Apr 17 23:03:03 2018 +0000
@@ -19,7 +19,8 @@
void engine::draw(N5110 &lcd)
{
- _rect.draw(lcd);
+ //draw and re-draw rectangle, boom and money on the screen
+ _rect.draw(lcd);
_boom.draw(lcd);
_money.draw(lcd);
@@ -36,8 +37,10 @@
void engine::update(Gamepad &pad)
{
- _rect.update(_d,_mag);
- _boom.update();
+ _rect.update(_d,_mag); //get the position of rect when jopystick moves
+
+ //boom and money will keep moving with initial settings
+ _boom.update();
_money.update();
check_boom_pos(pad);
@@ -53,9 +56,10 @@
if (money_pos.y > 48) {
money_pos.y = 0;
- money_pos.x = rand()%84;
+ money_pos.x = rand()%84; //the money will back to top with random x position
}
+ //avoid money out of the screen
if (money_pos.x == 84) {
money_pos.x = 81;
}
@@ -73,9 +77,10 @@
Vector2D boom_pos = _boom.get_pos();
if (boom_pos.y > 48) {
boom_pos.y = 0;
- boom_pos.x = rand()%84;
+ boom_pos.x = rand()%84; //boom will back to top with random x position
}
-
+
+ //avoid boom go outside of the screen
if (boom_pos.x == 84) {
boom_pos.x = 81;
}
@@ -89,7 +94,8 @@
void engine::check_rect_pos(Gamepad &pad)
{
Vector2D rect_pos = _rect.get_pos();
-
+
+ //keep the rect moving inside the screen
if (rect_pos.x < 1) {
rect_pos.x = 1;
}
@@ -104,17 +110,18 @@
{
Vector2D boom_pos = _boom.get_pos();
Vector2D rect_pos = _rect.get_pos();
+ Vector2D money_pos = _money.get_pos();
- if (boom_pos.y == rect_pos.y){
- if (
- (boom_pos.x+2 == rect_pos.x) or
- (boom_pos.x+1 == rect_pos.x)
- ){
- boom_pos.y = 0;
+ if ((money_pos.y == rect_pos.y)&&(money_pos.x == rect_pos.x ))
+
+ {
+ money_pos.y = 0;
pad.tone(750.0,0.1);
}
- }
+
+
+ _money.set_pos(money_pos);
_boom.set_pos(boom_pos);
_rect.set_pos(rect_pos);
}