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
PushingEngine/PushingEngine.cpp
- Committer:
- franklzw
- Date:
- 2019-03-24
- Revision:
- 3:9fa31396d89d
- Parent:
- 2:9f0d9516a6cd
- Child:
- 4:750d3f9b54de
File content as of revision 3:9fa31396d89d:
#include "PushingEngine.h"
PushingEngine::PushingEngine()
{
}
PushingEngine::~PushingEngine()
{
}
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)
{
// boxes position on screen
_b1x = box1_x;
_b2x = box2_x;
_b1y = box1_y;
_b2y = box2_y;
// ppl position on screen
_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();
}
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)
{
Vector2D b1_pos = _b1.get_pos();
Vector2D ppl_pos = _ppl.get_pos();
if (b1_pos.y == ppl_pos.y)
{
if((ppl_pos.x-b1_pos.x) =8)
{
_s = 1; // can push to left
} else if((b1_pos.x-ppl_pos.x)=8)
{
_s = 2; // can push to right
}
}
if (b1_pos.x == ppl_pos.x)
{
if((ppl_pos.y-b1_pos.y) =8)
{
_s = 4; // can push up
} else if((b1_pos.y-ppl_pos.y)=8)
{
_s = 3; // can push down
}
}
}
int PushingEngine::check_ppl_box2_touching(Gamepad &pad) //
{
Vector2D b2_pos = _b2.get_pos();
Vector2D ppl_pos = _ppl.get_pos();
if (b2_pos.y == ppl_pos.y)
{
if((ppl_pos.x-b2_pos.x) =8)
{
_r = 1; // can push to left
} else if((b2_pos.x-ppl_pos.x)=8)
{
_r = 2; // can push to right
}
}
if (b2_pos.x == ppl_pos.x)
{
if((ppl_pos.y-b2_pos.y) =8)
{
_r = 4; // can push up
} else if((b2_pos.y-ppl_pos.y)=8)
{
_r = 3; // can push down
}
}
}
void PushingEngine::box1_moving(Gamepad &pad)
{
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);
}
void PushingEngine::box2_moving(Gamepad &pad)
{
Vector2D b2_pos = _b2.get_pos();
Vector2D ppl_pos = _ppl.get_pos();
read_input(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;
}
if(_bb == 1 && _s == 2 )
{
b2_pos.x=b2_pos.x+8;
ppl_pos.x=ppl_pos.x+8;
}
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);
}
