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: Ppl/Ppl.cpp
- Revision:
- 6:6b083e22cb53
- Parent:
- 5:b50ce6160013
- Child:
- 7:6f8aeadc4370
--- a/Ppl/Ppl.cpp Tue Apr 09 12:46:02 2019 +0000
+++ b/Ppl/Ppl.cpp Thu Apr 11 13:42:34 2019 +0000
@@ -34,29 +34,92 @@
lcd.drawSprite(_x,_y,8,8,(int *)ppl);
}
-void Ppl::update(int bb,int ba,int bx,int by)
-{
- if (bx ==0 && bb == 0 && by == 0 && ba == 0){
+void Ppl::update(int bb,int ba,int bx,int by,int temp,
+ int barrier_x,int barrier_y)
+{
+ int temp_x = _x;
+ int temp_y = _y;
+
+ move_ppl(bb,ba,bx,by);
+
+ if (hold_beside_barrier(barrier_x,barrier_y)) {
+ _x = temp_x;
+ _y = temp_y;
+ } else {
_x = _x;
_y = _y;
- }
- if (bx == 1){
+ }
+ hold_ppl_against_wall();
+ hold_ppl_box_touching(temp);
+
+}
+
+Vector2D Ppl::get_pos()
+{
+ Vector2D p = {_x,_y};
+ return p;
+}
+
+void Ppl::set_pos(Vector2D p)
+{
+ _x = p.x;
+ _y = p.y;
+}
+
+bool Ppl::hold_beside_barrier(int barrier_x,int barrier_y) // check after moving if ppl pos match the barrier
+{
+ // if matched return ture
+
+ if (_x == barrier_x &&_y == barrier_y) {
+ return true;
+ } else {
+ return false;
+ }
+}
+
+void Ppl::move_ppl(int bb,int ba,int bx,int by) //move the ppl with respect to the bottom read
+{
+
+ if (bx ==0 && bb == 0 && by == 0 && ba == 0) {
+ _x = _x;
+ _y = _y;
+ }
+ if (bx == 1) {
_x = _x-8;
_y = _y;
- }
- if (bb == 1){
+ }
+ if (bb == 1) {
_x = _x+8;
_y = _y;
- }
- if (by == 1){
+ }
+ if (by == 1) {
_y = _y-8;
_x = _x;
- }
- if (ba == 1){
+ }
+ if (ba == 1) {
_y = _y+8;
_x = _x;
- }
- // check the y origin to ensure that the paddle doesn't go off screen
+ }
+}
+
+void Ppl::hold_ppl_box_touching(int temp) //check for box facing wall and hold pos of ppl
+{
+ if (temp == 0 ) {
+ _y = _y;
+ _x = _x;
+ } else if (temp == 1) {
+ _x = 10;
+ } else if (temp == 2) {
+ _x = 66;
+ } else if (temp == 3) {
+ _y = 12;
+ } else if (temp == 4) {
+ _y = 28;
+ }
+}
+
+void Ppl::hold_ppl_against_wall() // check the y origin to ensure that the paddle doesn't go off screen
+{
if (_y < 4) {
_y = 4;
}
@@ -69,16 +132,4 @@
if (_x < 2) {
_x = 2;
}
-}
-
-Vector2D Ppl::get_pos()
-{
- Vector2D p = {_x,_y};
- return p;
-}
-
-void Ppl::set_pos(Vector2D p)
-{
- _x = p.x;
- _y = p.y;
}
\ No newline at end of file
