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@4:34bf3587cf42, 2019-04-18 (annotated)
- Committer:
- rottenegg
- Date:
- Thu Apr 18 21:44:05 2019 +0000
- Revision:
- 4:34bf3587cf42
- Child:
- 5:860087ff295e
Added CaMove as a Character Movement and Interaction System that manages the moving animation and the Item Interaction Regions. WDplayer has been Documented and Flepaths File was added. CaMove Require Documenting
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rottenegg | 4:34bf3587cf42 | 1 | #include "CaMove.h" |
rottenegg | 4:34bf3587cf42 | 2 | #include "FilePaths.h" |
rottenegg | 4:34bf3587cf42 | 3 | |
rottenegg | 4:34bf3587cf42 | 4 | CaMove::CaMove(PinName pin) : _check(pin) { |
rottenegg | 4:34bf3587cf42 | 5 | _check.mode(PullDown); |
rottenegg | 4:34bf3587cf42 | 6 | _check.rise(callback(this,&CaMove::intercheck)); |
rottenegg | 4:34bf3587cf42 | 7 | _h = 40; |
rottenegg | 4:34bf3587cf42 | 8 | _v = 20; |
rottenegg | 4:34bf3587cf42 | 9 | _itr = 0; |
rottenegg | 4:34bf3587cf42 | 10 | Faceing = Lt; |
rottenegg | 4:34bf3587cf42 | 11 | Trig = false; |
rottenegg | 4:34bf3587cf42 | 12 | }; |
rottenegg | 4:34bf3587cf42 | 13 | |
rottenegg | 4:34bf3587cf42 | 14 | CaMove::~CaMove() { |
rottenegg | 4:34bf3587cf42 | 15 | }; |
rottenegg | 4:34bf3587cf42 | 16 | |
rottenegg | 4:34bf3587cf42 | 17 | void CaMove::CMmove(N5110 &lcd, AnalogIn &hoz, AnalogIn &ver) { |
rottenegg | 4:34bf3587cf42 | 18 | if (hoz > 0.6f && lcd.getPixel((_h-1),(_v+7)) == 0) { |
rottenegg | 4:34bf3587cf42 | 19 | _h = _h - 2; |
rottenegg | 4:34bf3587cf42 | 20 | Faceing = Lt; |
rottenegg | 4:34bf3587cf42 | 21 | } |
rottenegg | 4:34bf3587cf42 | 22 | if (hoz < 0.4f && lcd.getPixel((_h+10),(_v+7)) == 0) { |
rottenegg | 4:34bf3587cf42 | 23 | _h = _h + 2; |
rottenegg | 4:34bf3587cf42 | 24 | Faceing = Rt; |
rottenegg | 4:34bf3587cf42 | 25 | } |
rottenegg | 4:34bf3587cf42 | 26 | if (ver > 0.6f && lcd.getPixel((_h+5),(_v-1)) == 0) { |
rottenegg | 4:34bf3587cf42 | 27 | _v = _v - 2; |
rottenegg | 4:34bf3587cf42 | 28 | Faceing = Fd; |
rottenegg | 4:34bf3587cf42 | 29 | } |
rottenegg | 4:34bf3587cf42 | 30 | if (ver < 0.4f && lcd.getPixel((_h+5),(_v+14)) == 0) { |
rottenegg | 4:34bf3587cf42 | 31 | _v = _v + 2; |
rottenegg | 4:34bf3587cf42 | 32 | Faceing = Bd; |
rottenegg | 4:34bf3587cf42 | 33 | } |
rottenegg | 4:34bf3587cf42 | 34 | if (_itr == 3) { |
rottenegg | 4:34bf3587cf42 | 35 | _itr = -1; |
rottenegg | 4:34bf3587cf42 | 36 | } |
rottenegg | 4:34bf3587cf42 | 37 | _itr++; |
rottenegg | 4:34bf3587cf42 | 38 | switch (Faceing) { |
rottenegg | 4:34bf3587cf42 | 39 | case Lt: |
rottenegg | 4:34bf3587cf42 | 40 | Bitmap::renderBMP(L[_itr],lcd,_h,_v); |
rottenegg | 4:34bf3587cf42 | 41 | break; |
rottenegg | 4:34bf3587cf42 | 42 | |
rottenegg | 4:34bf3587cf42 | 43 | case Rt: |
rottenegg | 4:34bf3587cf42 | 44 | Bitmap::renderBMP(R[_itr],lcd,_h,_v); |
rottenegg | 4:34bf3587cf42 | 45 | break; |
rottenegg | 4:34bf3587cf42 | 46 | |
rottenegg | 4:34bf3587cf42 | 47 | case Fd: |
rottenegg | 4:34bf3587cf42 | 48 | Bitmap::renderBMP(F[_itr],lcd,_h,_v); |
rottenegg | 4:34bf3587cf42 | 49 | break; |
rottenegg | 4:34bf3587cf42 | 50 | |
rottenegg | 4:34bf3587cf42 | 51 | case Bd: |
rottenegg | 4:34bf3587cf42 | 52 | Bitmap::renderBMP(B[_itr],lcd,_h,_v); |
rottenegg | 4:34bf3587cf42 | 53 | break; |
rottenegg | 4:34bf3587cf42 | 54 | } |
rottenegg | 4:34bf3587cf42 | 55 | }; |
rottenegg | 4:34bf3587cf42 | 56 | |
rottenegg | 4:34bf3587cf42 | 57 | |
rottenegg | 4:34bf3587cf42 | 58 | bool CaMove::inscreen() { |
rottenegg | 4:34bf3587cf42 | 59 | if (_h >= 84 || (_h + 9) <= 0 || _v <= 0 || (_v + 13) >= 48) { |
rottenegg | 4:34bf3587cf42 | 60 | return true; |
rottenegg | 4:34bf3587cf42 | 61 | } else { |
rottenegg | 4:34bf3587cf42 | 62 | return false; |
rottenegg | 4:34bf3587cf42 | 63 | } |
rottenegg | 4:34bf3587cf42 | 64 | }; |
rottenegg | 4:34bf3587cf42 | 65 | |
rottenegg | 4:34bf3587cf42 | 66 | void CaMove::set_region(int xmin, int ymax, int xl, int yl) { |
rottenegg | 4:34bf3587cf42 | 67 | intereact.push_back((xmin + xl)); |
rottenegg | 4:34bf3587cf42 | 68 | intereact.push_back(xmin); |
rottenegg | 4:34bf3587cf42 | 69 | intereact.push_back(ymax); |
rottenegg | 4:34bf3587cf42 | 70 | intereact.push_back((ymax - yl)); |
rottenegg | 4:34bf3587cf42 | 71 | }; |
rottenegg | 4:34bf3587cf42 | 72 | |
rottenegg | 4:34bf3587cf42 | 73 | void CaMove::delete_regions() { |
rottenegg | 4:34bf3587cf42 | 74 | intereact.clear(); |
rottenegg | 4:34bf3587cf42 | 75 | }; |
rottenegg | 4:34bf3587cf42 | 76 | |
rottenegg | 4:34bf3587cf42 | 77 | void CaMove::intercheck() { |
rottenegg | 4:34bf3587cf42 | 78 | Trig = false; |
rottenegg | 4:34bf3587cf42 | 79 | if (intereact.size() > 0) { |
rottenegg | 4:34bf3587cf42 | 80 | for(int Vvalue = 0; Vvalue < intereact.size(); Vvalue = Vvalue +4) { |
rottenegg | 4:34bf3587cf42 | 81 | //if Statements |
rottenegg | 4:34bf3587cf42 | 82 | bool LowerH = (_h - 1) <= intereact[Vvalue] && (_h-1) >= intereact[Vvalue + 1]; |
rottenegg | 4:34bf3587cf42 | 83 | bool UpperH = (_h + 10) <= intereact[Vvalue] && (_h + 10) >= intereact[Vvalue + 1]; |
rottenegg | 4:34bf3587cf42 | 84 | bool MidH = (_h + 5) <= intereact[Vvalue] && (_h + 5) >= intereact[Vvalue + 1]; |
rottenegg | 4:34bf3587cf42 | 85 | bool LowerV = (_v - 1) >= intereact[Vvalue + 3] && (_v - 1) <= intereact[Vvalue + 2]; |
rottenegg | 4:34bf3587cf42 | 86 | bool UpperV = (_v+14) >= intereact[Vvalue + 3] && (_v + 14) <= intereact[Vvalue + 2]; |
rottenegg | 4:34bf3587cf42 | 87 | bool MidV = (_v+7) >= intereact[Vvalue + 3] && (_v + 7) <= intereact[Vvalue + 2]; |
rottenegg | 4:34bf3587cf42 | 88 | |
rottenegg | 4:34bf3587cf42 | 89 | switch (Faceing) { |
rottenegg | 4:34bf3587cf42 | 90 | case Lt: //L |
rottenegg | 4:34bf3587cf42 | 91 | if (LowerH && MidV) { |
rottenegg | 4:34bf3587cf42 | 92 | Trig = true; |
rottenegg | 4:34bf3587cf42 | 93 | tregion = Vvalue / 4; |
rottenegg | 4:34bf3587cf42 | 94 | }; |
rottenegg | 4:34bf3587cf42 | 95 | break; |
rottenegg | 4:34bf3587cf42 | 96 | |
rottenegg | 4:34bf3587cf42 | 97 | case Rt: //R |
rottenegg | 4:34bf3587cf42 | 98 | if (UpperH && MidV) { |
rottenegg | 4:34bf3587cf42 | 99 | Trig = true; |
rottenegg | 4:34bf3587cf42 | 100 | tregion = Vvalue / 4; |
rottenegg | 4:34bf3587cf42 | 101 | } |
rottenegg | 4:34bf3587cf42 | 102 | break; |
rottenegg | 4:34bf3587cf42 | 103 | |
rottenegg | 4:34bf3587cf42 | 104 | case Fd: //F |
rottenegg | 4:34bf3587cf42 | 105 | if (MidH && LowerV) { |
rottenegg | 4:34bf3587cf42 | 106 | Trig = true; |
rottenegg | 4:34bf3587cf42 | 107 | tregion = Vvalue / 4; |
rottenegg | 4:34bf3587cf42 | 108 | } |
rottenegg | 4:34bf3587cf42 | 109 | break; |
rottenegg | 4:34bf3587cf42 | 110 | |
rottenegg | 4:34bf3587cf42 | 111 | case Bd: //B |
rottenegg | 4:34bf3587cf42 | 112 | if (MidH && UpperV) { |
rottenegg | 4:34bf3587cf42 | 113 | Trig = true; |
rottenegg | 4:34bf3587cf42 | 114 | tregion = Vvalue / 4; |
rottenegg | 4:34bf3587cf42 | 115 | } |
rottenegg | 4:34bf3587cf42 | 116 | break; |
rottenegg | 4:34bf3587cf42 | 117 | } |
rottenegg | 4:34bf3587cf42 | 118 | } |
rottenegg | 4:34bf3587cf42 | 119 | } |
rottenegg | 4:34bf3587cf42 | 120 | } |
rottenegg | 4:34bf3587cf42 | 121 | |
rottenegg | 4:34bf3587cf42 | 122 | bool CaMove::get_Trig() { |
rottenegg | 4:34bf3587cf42 | 123 | bool temp = Trig; |
rottenegg | 4:34bf3587cf42 | 124 | Trig = false; |
rottenegg | 4:34bf3587cf42 | 125 | return temp; |
rottenegg | 4:34bf3587cf42 | 126 | |
rottenegg | 4:34bf3587cf42 | 127 | }; |