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:
- 9:ac396c818874
- Parent:
- 8:e3a76a808a4c
- Child:
- 10:4fda7b01484a
--- a/CaMove/CaMove.cpp Tue Apr 23 21:46:55 2019 +0000 +++ b/CaMove/CaMove.cpp Thu Apr 25 01:31:32 2019 +0000 @@ -31,21 +31,23 @@ void CaMove::move(N5110 &lcd) { //If statements to check joystick movement and has in bluilt collsion detection //collsion detection check 4 sides for black pixels - bool pi = (lcd.getPixel((_h-1),(_v+7)) == 0) && (lcd.getPixel((_h+10),(_v+7)) == 0) && - (lcd.getPixel((_h+5),(_v-1)) == 0) && (lcd.getPixel((_h+5),(_v+14)) == 0); - if (_hoz->read() > 0.6f && pi) { + bool c1 = (lcd.getPixel((_h-1),(_v+12)) == 0 && lcd.getPixel((_h-1),(_v+1)) == 0) ; + 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); + if (_hoz->read() > 0.6f && c1) { _h = _h - 2; _fc = Lt; } - if (_hoz->read() < 0.4f && pi) { + if (_hoz->read() < 0.4f && c2) { _h = _h + 2; _fc = Rt; } - if (_ver->read() > 0.6f && pi) { + if (_ver->read() > 0.6f && c3) { _v = _v - 2; _fc = Fd; } - if (_ver->read() < 0.4f && pi) { + if (_ver->read() < 0.4f && c4) { _v = _v + 2; _fc = Bd; } @@ -53,6 +55,11 @@ _itr = -1; } _itr++; + this->rend(lcd); +} + + +void CaMove::rend(N5110 &lcd) { //Switch case allows charater to move diagonally and retains its facing direction when stationary switch (_fc) { case Lt: @@ -75,7 +82,7 @@ bool CaMove::in_screen() { - if (_h >= 84 || (_h + 9) <= 0 || _v <= 0 || (_v + 13) >= 48) { + if (_h + 5 >= 84 || (_h + 5) <= 0 || _v + 7 >= 48 || (_v + 8) <= 0) { return false; } else { return true; @@ -153,3 +160,37 @@ return temp; } +//AI Components +void CaMove::AIinit() { + enabled = false; +}; + +void CaMove::spawn(int x, int y) { + enabled = true; + _ch = x; + _cv = y; +} + +void CaMove::chase(N5110 &lcd) { + if (enabled) { + if (_cv < _v) { + _cv = _cv + 2; + } else if (_cv > _v) { + _cv = _cv - 2; + } else if (_ch < _h) { + _ch = _ch + 2; + } else if (_ch > _v) { + _ch = _ch - 2; + } + Bitmap::renderBMP(AIC[_itr],lcd,_ch,_cv); + } +} + +bool CaMove::is_caught() { + if ((abs(_ch - _h) < 10) && (abs(_cv - _v) < 14)) { + return true; + } else { + return false; + } +} +