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
Fork of el17zl by
Diff: PushingEngine/PushingEngine.cpp
- Revision:
- 8:83891ea9a5d9
- Parent:
- 7:6f8aeadc4370
- Child:
- 9:1fa7f087051e
diff -r 6f8aeadc4370 -r 83891ea9a5d9 PushingEngine/PushingEngine.cpp
--- a/PushingEngine/PushingEngine.cpp Thu Apr 11 14:14:28 2019 +0000
+++ b/PushingEngine/PushingEngine.cpp Mon Apr 15 06:55:01 2019 +0000
@@ -25,7 +25,8 @@
}
void PushingEngine::init(int box1_x,int box1_y,int box2_x,int box2_y,
- int ppl_x,int ppl_y )
+ int ppl_x,int ppl_y,
+ int cross1_x,int cross1_y,int cross2_x,int cross2_y)
{
// boxes position on screen
_b1x = box1_x;
@@ -37,12 +38,19 @@
_pplx = ppl_x;
_pply = ppl_y;
+ // crosses position on screen
+ _c1x = cross1_x;
+ _c1y = cross1_y;
+ _c2x = cross2_x;
+ _c2y = cross2_y;
+
+
// inital boxes, crosses and ppl
_b1.init(_b1x,_b1y);
_b2.init(_b2x,_b2y);
_ppl.init(_pplx,_pply);
-
-
+ _c1.init(_c1x,_c1y);
+ _c2.init(_c2x,_c2y);
}
@@ -56,21 +64,25 @@
//else {_bback = 0;}
if (pad.check_event(Gamepad::A_PRESSED)) {
_ba = 1;
+ //pad.tone(1500.0,0.1);
} else {
_ba = 0;
}
if (pad.check_event(Gamepad::B_PRESSED)) {
_bb = 1;
+ //pad.tone(1500.0,0.1);
} else {
_bb = 0;
}
if (pad.check_event(Gamepad::X_PRESSED)) {
_bx = 1;
+ //pad.tone(1500.0,0.1);
} else {
_bx = 0;
}
if (pad.check_event(Gamepad::Y_PRESSED)) {
_by = 1;
+ //pad.tone(1500.0,0.1);
} else {
_by = 0;
}
@@ -132,16 +144,20 @@
lcd.drawLine(0,3,0,45,1);
lcd.drawLine(1,45,83,45,1);
lcd.drawLine(83,3,83,44,1);
-
- //draw the barrier
+
+ //draw the barrier
lcd.drawSprite(barrier_x,barrier_y,8,8,(int *)barrier);
+ //crosses
+ _c1.draw(lcd);
+ _c2.draw(lcd);
// ppl
_ppl.draw(lcd);
// boxes
_b1.draw(lcd);
_b2.draw(lcd);
-
-
+
+
+
}
void PushingEngine::update(Gamepad &pad,int barrier_x,int barrier_y) //
@@ -151,7 +167,7 @@
hold_ppl_box1_wall(pad);
hold_ppl_box2_wall(pad);
-
+
Vector2D temp_ppl_pos = _ppl.get_pos();
_b1.update(_s,_bb,_ba,_bx,_by,barrier_x,barrier_y);
_b2.update(_r,_bb,_ba,_bx,_by,barrier_x,barrier_y);
@@ -159,10 +175,17 @@
_temp = 0;
_s = 0;
_r = 0;
+ _score = 0;
- if (ppl_cover_box(pad)){
+ if (ppl_cover_box(pad)) {
_ppl.set_pos(temp_ppl_pos);
- }
+ }
+
+ box_cover_cross1_score(pad);
+ box_cover_cross2_score(pad);
+ set_score();
+
+
}
void PushingEngine::hold_ppl_box1_wall(Gamepad &pad) //
@@ -224,8 +247,43 @@
Vector2D b1_pos = _b1.get_pos();
Vector2D b2_pos = _b2.get_pos();
Vector2D ppl_pos = _ppl.get_pos();
-
- if ((b1_pos.x == ppl_pos.x &&b1_pos.y == ppl_pos.y)||(b2_pos.x == ppl_pos.x &&b2_pos.y == ppl_pos.y)){
+
+ if ((b1_pos.x == ppl_pos.x &&b1_pos.y == ppl_pos.y)||(b2_pos.x == ppl_pos.x &&b2_pos.y == ppl_pos.y)) {
return true;
- } else {return false;}
+ } else {
+ return false;
+ }
+}
+void PushingEngine::box_cover_cross1_score(Gamepad &pad)
+{
+ Vector2D c1_pos = _c1.get_pos();
+ Vector2D b1_pos = _b1.get_pos();
+ Vector2D b2_pos = _b2.get_pos();
+
+ if(c1_pos.x==b1_pos.x && c1_pos.y==b1_pos.y){
+ _score ++;
+ }
+ if(c1_pos.x==b2_pos.x && c1_pos.y==b2_pos.y){
+ _score ++;
+ }
}
+
+void PushingEngine::box_cover_cross2_score(Gamepad &pad)
+{
+ Vector2D c2_pos = _c2.get_pos();
+ Vector2D b1_pos = _b1.get_pos();
+ Vector2D b2_pos = _b2.get_pos();
+
+ if(c2_pos.x==b1_pos.x && c2_pos.y==b1_pos.y){
+ _score ++;
+ }
+ if(c2_pos.x==b2_pos.x && c2_pos.y==b2_pos.y){
+ _score ++;
+ }
+}
+
+int PushingEngine::set_score()
+{
+ printf("score = %d\n",_score);
+ return _score;
+}
\ No newline at end of file
