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:
- 4:750d3f9b54de
- Parent:
- 3:9fa31396d89d
- Child:
- 5:b50ce6160013
--- a/PushingEngine/PushingEngine.cpp Sun Mar 24 22:41:22 2019 +0000
+++ b/PushingEngine/PushingEngine.cpp Tue Apr 09 08:31:27 2019 +0000
@@ -11,8 +11,7 @@
}
void PushingEngine::init(int box1_x,int box1_y,int box2_x,int box2_y,
- int ppl_x,int ppl_y,
- int cross1_x,int corss2_x,int cross1_x,int cross2_y)
+ int ppl_x,int ppl_y)
{
// boxes position on screen
_b1x = box1_x;
@@ -24,73 +23,45 @@
_pplx = ppl_x;
_pply = ppl_y;
- //cross position on screen
- _c1x = cross1_x;
- _c2x = cross2_x;
- _c1y = cross1_y;
- _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);
+
}
void PushingEngine::read_input(Gamepad &pad)
{
- _bstart = pad.check_event(Gamepad::START_PRESSED);
- _bback = pad.check_event(Gamepad::BACK_PRESSED);
- _ba = pad.check_event(Gamepad::A_PRESSED);
- _bb = pad.check_event(Gamepad::B_PRESSED);
- _bx = pad.check_event(Gamepad::X_PRESSED);
- _by = pad.check_event(Gamepad::Y_PRESSED);
- _bjoy = pad.check_event(Gamepad::JOY_PRESSED);
- _djoy = pad.get_direction();
+ if (pad.check_event(Gamepad::START_PRESSED))
+ {_bstart = 1;}
+ else {_bstart = 0;}
+ if (pad.check_event(Gamepad::BACK_PRESSED))
+ {_bback = 1; }
+ else {_bback = 0;}
+ if (pad.check_event(Gamepad::A_PRESSED))
+ {_ba = 1; }
+ else {_ba = 0;}
+ if (pad.check_event(Gamepad::B_PRESSED))
+ {_bb = 1; }
+ else {_bb = 0;}
+ if (pad.check_event(Gamepad::X_PRESSED))
+ {_bx = 1; }
+ else {_bx = 0;}
+ if (pad.check_event(Gamepad::Y_PRESSED))
+ {_by = 1; }
+ else {_by = 0;}
+ if (pad.check_event(Gamepad::JOY_PRESSED))
+ {_bjoy = 1; }
+ else {_bjoy = 0;}
}
-void PushingEngine::draw(N5110 &lcd)
-{
- // draw the elements in the LCD buffer
- // pitch
- lcd.drawLine(0,4,83,4,1);
- lcd.drawLine(0,5,0,47,1);
- lcd.drawLine(1,47,83,47,1);
- lcd.drawLine(83,5,83,46,1);
- // boxes
- _b1.draw(lcd);
- _b2.draw(lcd);
- // ppl
- _ppl.draw(lcd);
- // cross
- _c1.draw(lcd);
- _c2.draw(lcd);
-}
-
-void PushingEngine::update(Gamepad &pad) //
-{
- check_goal(pad);
- // important to update paddles and ball before checking collisions so can
- // correct for it before updating the display
- _b1.update();
- _b2.update();
- _ppl.update();
-
- check_cross_box_matching(pad);
- check_cross_box_touching(pad);
-}
-
-void PushingEngine::check_cross_box_matching(Gamepad &pad)
-{
- vvvv
-}
-
-int PushingEngine::check_ppl_box1_touching(Gamepad &pad)
+void PushingEngine::check_ppl_box1_touching(Gamepad &pad)
{
Vector2D b1_pos = _b1.get_pos();
Vector2D ppl_pos = _ppl.get_pos();
+ int _s = 0;
+
if (b1_pos.y == ppl_pos.y)
{
if((ppl_pos.x-b1_pos.x) =8)
@@ -114,10 +85,11 @@
}
}
-int PushingEngine::check_ppl_box2_touching(Gamepad &pad) //
+void PushingEngine::check_ppl_box2_touching(Gamepad &pad) //
{
Vector2D b2_pos = _b2.get_pos();
Vector2D ppl_pos = _ppl.get_pos();
+ int _r = 0;
if (b2_pos.y == ppl_pos.y)
{
@@ -142,75 +114,31 @@
}
}
-void PushingEngine::box1_moving(Gamepad &pad)
+
+void PushingEngine::draw(N5110 &lcd)
{
- Vector2D b1_pos = _b1.get_pos();
- Vector2D ppl_pos = _ppl.get_pos();
-
- read_input(pad);
- check_ppl_box1_touching(pad);
-
- if(_bx == 1 && _s == 1 )
- {
- b1_pos.x=b1_pos.x-8;
- ppl_pos.x=ppl_pos.x-8;
- }
-
- if(_bb == 1 && _s == 2 )
- {
- b1_pos.x=b1_pos.x+8;
- ppl_pos.x=ppl_pos.x+8;
- }
-
- if(_ba == 1 && _s == 3 )
- {
- b1_pos.y=b1_pos.y+8;
- ppl_pos.y=ppl_pos.y+8;
- }
-
- if(_by == 1 && _s == 4 )
- {
- b1_pos.y=b1_pos.y-8;
- ppl_pos.y=ppl_pos.y-8;
- }
-
- _b1.set_pos(b1_pos);
- _ppl.set_pos(ppl_pos);
+ // draw the elements in the LCD buffer
+ // pitch
+ lcd.drawLine(0,2,83,2,1);
+ lcd.drawLine(0,3,0,45,1);
+ lcd.drawLine(1,45,83,45,1);
+ lcd.drawLine(83,3,83,44,1);
+ lcd.drawSprite(34,28,8,8,(int *)barrier);
+ // boxes
+ _b1.draw(lcd);
+ _b2.draw(lcd);
+ // ppl
+ _ppl.draw(lcd);
}
-void PushingEngine::box2_moving(Gamepad &pad)
+void PushingEngine::update(Gamepad &pad) //
{
- Vector2D b2_pos = _b2.get_pos();
- Vector2D ppl_pos = _ppl.get_pos();
-
- read_input(pad);
+ //check_cross_box_matching(pad);
check_ppl_box1_touching(pad);
-
- if(_bx == 1 && _s == 1 )
- {
- b2_pos.x=b2_pos.x-8;
- ppl_pos.x=ppl_pos.x-8;
- }
+ check_ppl_box2_touching(pad);
- if(_bb == 1 && _s == 2 )
- {
- b2_pos.x=b2_pos.x+8;
- ppl_pos.x=ppl_pos.x+8;
- }
+ _b1.update(_s,_ba,_bb,_bx,_by);
+ _b2.update(_r,_ba,_bb,_bx,_by);
+ _ppl.update(_ba,_bb,_bx,_by);
- if(_ba == 1 && _s == 3 )
- {
- b2_pos.y=b2_pos.y+8;
- ppl_pos.y=ppl_pos.y+8;
- }
-
- if(_by == 1 && _s == 4 )
- {
- b2_pos.y=b2_pos.y-8;
- ppl_pos.y=ppl_pos.y-8;
- }
-
- _b2.set_pos(b2_pos);
- _ppl.set_pos(ppl_pos);
}
-
