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 FATFileSystem
Diff: CaMove/CaMove.cpp
- Revision:
- 18:14e5391beccf
- Parent:
- 17:7d4d8905b608
- Child:
- 19:065207c07c3c
--- a/CaMove/CaMove.cpp Wed May 08 00:30:09 2019 +0000 +++ b/CaMove/CaMove.cpp Wed May 08 01:49:54 2019 +0000 @@ -1,5 +1,6 @@ #include "CaMove.h" #include "AniPaths.h" + //Constructor CaMove::CaMove(PinName Button, PinName Pot_h, @@ -12,6 +13,7 @@ _check->mode(PullDown); _check->rise(callback(this,&CaMove::intercheck)); }; + //Destructor CaMove::~CaMove() { delete _check; @@ -35,6 +37,15 @@ bool c2 = (lcd.getPixel((_h+10),(_v+12)) == 0 && lcd.getPixel((_h+10),(_v+1)) == 0); bool c3 = (lcd.getPixel((_h+1),(_v-1)) == 0 && lcd.getPixel((_h+8),(_v-1)) == 0); bool c4 = (lcd.getPixel((_h+1),(_v+14)) == 0 && lcd.getPixel((_h+8),(_v+14)) == 0); + this->check_collision(c1,c2,c3,c4); + if (_itr == 3) { + _itr = -1; + } + _itr++; + this->rend(lcd); +} + +void CaMove::check_collision(bool c1,bool c2,bool c3,bool c4) { if (_hoz->read() > 0.6f && c1) { _h = _h - 2; _fc = Lt; @@ -50,14 +61,8 @@ if (_ver->read() < 0.4f && c4) { _v = _v + 2; _fc = Bd; - } - if (_itr == 3) { - _itr = -1; - } - _itr++; - this->rend(lcd); + } } - void CaMove::rend(Bitmap &lcd) { //Switch case allows charater to move diagonally and retains its facing direction when stationary @@ -88,6 +93,7 @@ return true; } }; + //Sets values into vector void CaMove::set_region(int xmin, int ymin, int xl, int yl) { _vreg.push_back((xmin + xl)); @@ -102,50 +108,62 @@ void CaMove::intercheck() { _trg = false; + LowerH = false; + UpperH = false; + MidH = false; + LowerV = false; + UpperV = false; + MidV = false; if (_vreg.size() > 0) { for(int Vvalue = 0; Vvalue < _vreg.size(); Vvalue = Vvalue +4) { - //Function only will check the facing side for interative regions - //If Statements check that sides position with all x- y region ranges to see if charater has hit that region. - bool LowerH = (_h - 1) <= _vreg[Vvalue] && (_h-1) >= _vreg[Vvalue + 1]; - bool UpperH = (_h + 10) <= _vreg[Vvalue] && (_h + 10) >= _vreg[Vvalue + 1]; - bool MidH = (_h + 5) <= _vreg[Vvalue] && (_h + 5) >= _vreg[Vvalue + 1]; - bool LowerV = (_v - 1) >= _vreg[Vvalue + 3] && (_v - 1) <= _vreg[Vvalue + 2]; - bool UpperV = (_v+14) >= _vreg[Vvalue + 3] && (_v + 14) <= _vreg[Vvalue + 2]; - bool MidV = (_v+7) >= _vreg[Vvalue + 3] && (_v + 7) <= _vreg[Vvalue + 2]; - //The region number is found depending on its position in the vector - //e.g elements 0 to 3 are in region 0 and elements 4 to 7 are in region 1 - switch (_fc) { - case Lt: //L - if (LowerH && MidV) { - _trg = true; - _treg = Vvalue / 4; - }; - break; - - case Rt: //R - if (UpperH && MidV) { - _trg = true; - _treg = Vvalue / 4; - } - break; - - case Fd: //F - if (MidH && LowerV) { - _trg = true; - _treg = Vvalue / 4; - } - break; - - case Bd: //B - if (MidH && UpperV) { - _trg = true; - _treg = Vvalue / 4; - } - break; - } + this->set_statements(Vvalue); + this->check_sides(Vvalue); } } }; + +void CaMove::check_sides(int Vvalue) { + switch (_fc) { //Function only will check the facing side for interative regions + case Lt: //L + if (LowerH && MidV) { + this->set_treg(Vvalue); + }; + break; + case Rt: //R + if (UpperH && MidV) { + this->set_treg(Vvalue); + } + break; + case Fd: //F + if (MidH && LowerV) { + this->set_treg(Vvalue); + } + break; + case Bd: //B + if (MidH && UpperV) { + this->set_treg(Vvalue); + } + break; + } +} + +void CaMove::set_treg(int Vvalue) { + //The region number is found depending on its position in the vector + //e.g elements 0 to 3 are in region 0 and elements 4 to 7 are in region 1 + _trg = true; + _treg = Vvalue / 4; +} + +void CaMove::set_statements(int Vvalue) { + //If Statements check that sides position with all x- y region ranges to see if charater has hit that region. + LowerH = (_h - 1) <= _vreg[Vvalue] && (_h-1) >= _vreg[Vvalue + 1]; + UpperH = (_h + 10) <= _vreg[Vvalue] && (_h + 10) >= _vreg[Vvalue + 1]; + MidH = (_h + 5) <= _vreg[Vvalue] && (_h + 5) >= _vreg[Vvalue + 1]; + LowerV = (_v - 1) >= _vreg[Vvalue + 3] && (_v - 1) <= _vreg[Vvalue + 2]; + UpperV = (_v+14) >= _vreg[Vvalue + 3] && (_v + 14) <= _vreg[Vvalue + 2]; + MidV = (_v+7) >= _vreg[Vvalue + 3] && (_v + 7) <= _vreg[Vvalue + 2]; +} + //Functions revert to default values evrytime they are called. bool CaMove::is_trg() { bool temp = _trg; @@ -161,21 +179,11 @@ } //AI Components -void CaMove::AIinit() { +void CaMove::AIinit(int chaser) { enabled = false; _ch = 0; _cv = 0; -}; - -void CaMove::spawn(int x, int y) { - enabled = true; - _ch = x; - _cv = y; -} - -void CaMove::chase(Bitmap &lcd, int girl) { - int increment; - switch (girl) { + switch (chaser) { case 2: increment = 2; break; @@ -189,6 +197,15 @@ increment = 3; break; } +}; + +void CaMove::spawn(int x, int y) { + enabled = true; + _ch = x; + _cv = y; +} + +void CaMove::chase(Bitmap &lcd, int girl) { if (enabled) { if (_cv < _v) { _cv = _cv + increment; @@ -200,17 +217,21 @@ } else if (_ch > _h) { _ch = _ch - increment; } - switch (girl) { - case 2: - lcd.renderBMP(AIC[_itr],_ch,_cv); - break; - case 4: - lcd.renderBMP(AIC[_itr],_ch,_cv); // change later - break; - default: - lcd.renderBMP(AIM[_itr],_ch,_cv); - break; - } + this->render_chaser(lcd,girl); + } +} + +void CaMove::render_chaser(Bitmap &lcd,int chaser) { + switch (chaser) { + case 2: + lcd.renderBMP(AIC[_itr],_ch,_cv); + break; + case 4: + lcd.renderBMP(AIC[_itr],_ch,_cv); // change later + break; + default: + lcd.renderBMP(AIM[_itr],_ch,_cv); + break; } }