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
CaMove/CaMove.cpp@8:e3a76a808a4c, 2019-04-23 (annotated)
- Committer:
- rottenegg
- Date:
- Tue Apr 23 21:46:55 2019 +0000
- Revision:
- 8:e3a76a808a4c
- Parent:
- 5:860087ff295e
- Child:
- 9:ac396c818874
CaMove: Update to move(N5110 &lcd) function's collision detection due to issue where player could glitch out of terrain.; SceneCreator was made, it manages all scene allowing easy function changes and also contains all function to control events ;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rottenegg | 4:34bf3587cf42 | 1 | #include "CaMove.h" |
rottenegg | 8:e3a76a808a4c | 2 | #include "AniPaths.h" |
rottenegg | 5:860087ff295e | 3 | //Constructor |
rottenegg | 5:860087ff295e | 4 | CaMove::CaMove(PinName Button, |
rottenegg | 5:860087ff295e | 5 | PinName Pot_h, |
rottenegg | 5:860087ff295e | 6 | PinName Pot_v) |
rottenegg | 5:860087ff295e | 7 | : //Creating Class Objects |
rottenegg | 5:860087ff295e | 8 | _check(new InterruptIn(Button)), |
rottenegg | 5:860087ff295e | 9 | _hoz(new AnalogIn(Pot_h)), |
rottenegg | 5:860087ff295e | 10 | _ver(new AnalogIn(Pot_v)) |
rottenegg | 5:860087ff295e | 11 | { |
rottenegg | 5:860087ff295e | 12 | _check->mode(PullDown); |
rottenegg | 5:860087ff295e | 13 | _check->rise(callback(this,&CaMove::intercheck)); |
rottenegg | 4:34bf3587cf42 | 14 | }; |
rottenegg | 5:860087ff295e | 15 | //Destructor |
rottenegg | 4:34bf3587cf42 | 16 | CaMove::~CaMove() { |
rottenegg | 5:860087ff295e | 17 | delete _check; |
rottenegg | 5:860087ff295e | 18 | delete _hoz; |
rottenegg | 5:860087ff295e | 19 | delete _ver; |
rottenegg | 4:34bf3587cf42 | 20 | }; |
rottenegg | 4:34bf3587cf42 | 21 | |
rottenegg | 5:860087ff295e | 22 | void CaMove::init(int x,int y,Direction D) { |
rottenegg | 5:860087ff295e | 23 | _h = x; |
rottenegg | 5:860087ff295e | 24 | _v = y; |
rottenegg | 5:860087ff295e | 25 | _itr = 0; |
rottenegg | 5:860087ff295e | 26 | _fc = D; |
rottenegg | 5:860087ff295e | 27 | _trg = false; |
rottenegg | 5:860087ff295e | 28 | _treg = -1; |
rottenegg | 5:860087ff295e | 29 | }; |
rottenegg | 5:860087ff295e | 30 | |
rottenegg | 5:860087ff295e | 31 | void CaMove::move(N5110 &lcd) { |
rottenegg | 5:860087ff295e | 32 | //If statements to check joystick movement and has in bluilt collsion detection |
rottenegg | 5:860087ff295e | 33 | //collsion detection check 4 sides for black pixels |
rottenegg | 8:e3a76a808a4c | 34 | bool pi = (lcd.getPixel((_h-1),(_v+7)) == 0) && (lcd.getPixel((_h+10),(_v+7)) == 0) && |
rottenegg | 8:e3a76a808a4c | 35 | (lcd.getPixel((_h+5),(_v-1)) == 0) && (lcd.getPixel((_h+5),(_v+14)) == 0); |
rottenegg | 8:e3a76a808a4c | 36 | if (_hoz->read() > 0.6f && pi) { |
rottenegg | 4:34bf3587cf42 | 37 | _h = _h - 2; |
rottenegg | 5:860087ff295e | 38 | _fc = Lt; |
rottenegg | 4:34bf3587cf42 | 39 | } |
rottenegg | 8:e3a76a808a4c | 40 | if (_hoz->read() < 0.4f && pi) { |
rottenegg | 4:34bf3587cf42 | 41 | _h = _h + 2; |
rottenegg | 5:860087ff295e | 42 | _fc = Rt; |
rottenegg | 4:34bf3587cf42 | 43 | } |
rottenegg | 8:e3a76a808a4c | 44 | if (_ver->read() > 0.6f && pi) { |
rottenegg | 4:34bf3587cf42 | 45 | _v = _v - 2; |
rottenegg | 5:860087ff295e | 46 | _fc = Fd; |
rottenegg | 4:34bf3587cf42 | 47 | } |
rottenegg | 8:e3a76a808a4c | 48 | if (_ver->read() < 0.4f && pi) { |
rottenegg | 4:34bf3587cf42 | 49 | _v = _v + 2; |
rottenegg | 5:860087ff295e | 50 | _fc = Bd; |
rottenegg | 4:34bf3587cf42 | 51 | } |
rottenegg | 4:34bf3587cf42 | 52 | if (_itr == 3) { |
rottenegg | 4:34bf3587cf42 | 53 | _itr = -1; |
rottenegg | 4:34bf3587cf42 | 54 | } |
rottenegg | 4:34bf3587cf42 | 55 | _itr++; |
rottenegg | 5:860087ff295e | 56 | //Switch case allows charater to move diagonally and retains its facing direction when stationary |
rottenegg | 5:860087ff295e | 57 | switch (_fc) { |
rottenegg | 4:34bf3587cf42 | 58 | case Lt: |
rottenegg | 4:34bf3587cf42 | 59 | Bitmap::renderBMP(L[_itr],lcd,_h,_v); |
rottenegg | 4:34bf3587cf42 | 60 | break; |
rottenegg | 4:34bf3587cf42 | 61 | |
rottenegg | 4:34bf3587cf42 | 62 | case Rt: |
rottenegg | 4:34bf3587cf42 | 63 | Bitmap::renderBMP(R[_itr],lcd,_h,_v); |
rottenegg | 4:34bf3587cf42 | 64 | break; |
rottenegg | 4:34bf3587cf42 | 65 | |
rottenegg | 4:34bf3587cf42 | 66 | case Fd: |
rottenegg | 4:34bf3587cf42 | 67 | Bitmap::renderBMP(F[_itr],lcd,_h,_v); |
rottenegg | 4:34bf3587cf42 | 68 | break; |
rottenegg | 4:34bf3587cf42 | 69 | |
rottenegg | 4:34bf3587cf42 | 70 | case Bd: |
rottenegg | 4:34bf3587cf42 | 71 | Bitmap::renderBMP(B[_itr],lcd,_h,_v); |
rottenegg | 4:34bf3587cf42 | 72 | break; |
rottenegg | 4:34bf3587cf42 | 73 | } |
rottenegg | 4:34bf3587cf42 | 74 | }; |
rottenegg | 4:34bf3587cf42 | 75 | |
rottenegg | 4:34bf3587cf42 | 76 | |
rottenegg | 5:860087ff295e | 77 | bool CaMove::in_screen() { |
rottenegg | 4:34bf3587cf42 | 78 | if (_h >= 84 || (_h + 9) <= 0 || _v <= 0 || (_v + 13) >= 48) { |
rottenegg | 5:860087ff295e | 79 | return false; |
rottenegg | 5:860087ff295e | 80 | } else { |
rottenegg | 4:34bf3587cf42 | 81 | return true; |
rottenegg | 4:34bf3587cf42 | 82 | } |
rottenegg | 4:34bf3587cf42 | 83 | }; |
rottenegg | 5:860087ff295e | 84 | //Sets values into vector |
rottenegg | 5:860087ff295e | 85 | void CaMove::set_region(int xmin, int ymin, int xl, int yl) { |
rottenegg | 5:860087ff295e | 86 | _vreg.push_back((xmin + xl)); |
rottenegg | 5:860087ff295e | 87 | _vreg.push_back(xmin); |
rottenegg | 5:860087ff295e | 88 | _vreg.push_back((ymin + yl)); |
rottenegg | 5:860087ff295e | 89 | _vreg.push_back(ymin); |
rottenegg | 4:34bf3587cf42 | 90 | }; |
rottenegg | 4:34bf3587cf42 | 91 | |
rottenegg | 4:34bf3587cf42 | 92 | void CaMove::delete_regions() { |
rottenegg | 5:860087ff295e | 93 | _vreg.clear(); |
rottenegg | 4:34bf3587cf42 | 94 | }; |
rottenegg | 4:34bf3587cf42 | 95 | |
rottenegg | 4:34bf3587cf42 | 96 | void CaMove::intercheck() { |
rottenegg | 5:860087ff295e | 97 | _trg = false; |
rottenegg | 5:860087ff295e | 98 | if (_vreg.size() > 0) { |
rottenegg | 5:860087ff295e | 99 | for(int Vvalue = 0; Vvalue < _vreg.size(); Vvalue = Vvalue +4) { |
rottenegg | 5:860087ff295e | 100 | //Function only will check the facing side for interative regions |
rottenegg | 5:860087ff295e | 101 | //If Statements check that sides position with all x- y region ranges to see if charater has hit that region. |
rottenegg | 5:860087ff295e | 102 | bool LowerH = (_h - 1) <= _vreg[Vvalue] && (_h-1) >= _vreg[Vvalue + 1]; |
rottenegg | 5:860087ff295e | 103 | bool UpperH = (_h + 10) <= _vreg[Vvalue] && (_h + 10) >= _vreg[Vvalue + 1]; |
rottenegg | 5:860087ff295e | 104 | bool MidH = (_h + 5) <= _vreg[Vvalue] && (_h + 5) >= _vreg[Vvalue + 1]; |
rottenegg | 5:860087ff295e | 105 | bool LowerV = (_v - 1) >= _vreg[Vvalue + 3] && (_v - 1) <= _vreg[Vvalue + 2]; |
rottenegg | 5:860087ff295e | 106 | bool UpperV = (_v+14) >= _vreg[Vvalue + 3] && (_v + 14) <= _vreg[Vvalue + 2]; |
rottenegg | 5:860087ff295e | 107 | bool MidV = (_v+7) >= _vreg[Vvalue + 3] && (_v + 7) <= _vreg[Vvalue + 2]; |
rottenegg | 5:860087ff295e | 108 | //The region number is found depending on its position in the vector |
rottenegg | 5:860087ff295e | 109 | //e.g elements 0 to 3 are in region 0 and elements 4 to 7 are in region 1 |
rottenegg | 5:860087ff295e | 110 | switch (_fc) { |
rottenegg | 4:34bf3587cf42 | 111 | case Lt: //L |
rottenegg | 4:34bf3587cf42 | 112 | if (LowerH && MidV) { |
rottenegg | 5:860087ff295e | 113 | _trg = true; |
rottenegg | 5:860087ff295e | 114 | _treg = Vvalue / 4; |
rottenegg | 4:34bf3587cf42 | 115 | }; |
rottenegg | 4:34bf3587cf42 | 116 | break; |
rottenegg | 4:34bf3587cf42 | 117 | |
rottenegg | 4:34bf3587cf42 | 118 | case Rt: //R |
rottenegg | 4:34bf3587cf42 | 119 | if (UpperH && MidV) { |
rottenegg | 5:860087ff295e | 120 | _trg = true; |
rottenegg | 5:860087ff295e | 121 | _treg = Vvalue / 4; |
rottenegg | 4:34bf3587cf42 | 122 | } |
rottenegg | 4:34bf3587cf42 | 123 | break; |
rottenegg | 4:34bf3587cf42 | 124 | |
rottenegg | 4:34bf3587cf42 | 125 | case Fd: //F |
rottenegg | 4:34bf3587cf42 | 126 | if (MidH && LowerV) { |
rottenegg | 5:860087ff295e | 127 | _trg = true; |
rottenegg | 5:860087ff295e | 128 | _treg = Vvalue / 4; |
rottenegg | 4:34bf3587cf42 | 129 | } |
rottenegg | 4:34bf3587cf42 | 130 | break; |
rottenegg | 4:34bf3587cf42 | 131 | |
rottenegg | 4:34bf3587cf42 | 132 | case Bd: //B |
rottenegg | 4:34bf3587cf42 | 133 | if (MidH && UpperV) { |
rottenegg | 5:860087ff295e | 134 | _trg = true; |
rottenegg | 5:860087ff295e | 135 | _treg = Vvalue / 4; |
rottenegg | 4:34bf3587cf42 | 136 | } |
rottenegg | 4:34bf3587cf42 | 137 | break; |
rottenegg | 4:34bf3587cf42 | 138 | } |
rottenegg | 4:34bf3587cf42 | 139 | } |
rottenegg | 4:34bf3587cf42 | 140 | } |
rottenegg | 5:860087ff295e | 141 | }; |
rottenegg | 5:860087ff295e | 142 | //Functions revert to default values evrytime they are called. |
rottenegg | 5:860087ff295e | 143 | bool CaMove::is_trg() { |
rottenegg | 5:860087ff295e | 144 | bool temp = _trg; |
rottenegg | 5:860087ff295e | 145 | _trg = false; |
rottenegg | 4:34bf3587cf42 | 146 | return temp; |
rottenegg | 4:34bf3587cf42 | 147 | |
rottenegg | 4:34bf3587cf42 | 148 | }; |
rottenegg | 5:860087ff295e | 149 | |
rottenegg | 5:860087ff295e | 150 | int CaMove::get_treg() { |
rottenegg | 5:860087ff295e | 151 | int temp = _treg; |
rottenegg | 5:860087ff295e | 152 | _treg = -1; |
rottenegg | 5:860087ff295e | 153 | return temp; |
rottenegg | 5:860087ff295e | 154 | } |
rottenegg | 5:860087ff295e | 155 |