![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Early commits of my project
Dependencies: mbed Gamepad N5110
main.cpp@5:f09602591ad3, 2019-03-13 (annotated)
- Committer:
- el17arm
- Date:
- Wed Mar 13 15:23:03 2019 +0000
- Revision:
- 5:f09602591ad3
- Parent:
- 4:e7215819c9bc
- Child:
- 6:6294bf4eafc8
Fixed jump issue, next step is create a class where I will store the main character sprite and its mechanics
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el17arm | 0:9e5f9e1c8ef9 | 1 | #include "main.h" |
el17arm | 0:9e5f9e1c8ef9 | 2 | #include "N5110.h" |
el17arm | 3:140cad440684 | 3 | #include "Gamepad.h" |
el17arm | 0:9e5f9e1c8ef9 | 4 | |
el17arm | 3:140cad440684 | 5 | Gamepad pad; |
el17arm | 5:f09602591ad3 | 6 | N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); |
el17arm | 1:c80162894831 | 7 | AnalogIn pot0(PTB2); |
el17arm | 2:ba653520a140 | 8 | |
el17arm | 2:ba653520a140 | 9 | int x = 0; |
el17arm | 2:ba653520a140 | 10 | int y = 0; |
el17arm | 2:ba653520a140 | 11 | |
el17arm | 0:9e5f9e1c8ef9 | 12 | |
el17arm | 0:9e5f9e1c8ef9 | 13 | int main() |
el17arm | 0:9e5f9e1c8ef9 | 14 | { |
el17arm | 0:9e5f9e1c8ef9 | 15 | init(); |
el17arm | 3:140cad440684 | 16 | |
el17arm | 0:9e5f9e1c8ef9 | 17 | while (1) { |
el17arm | 5:f09602591ad3 | 18 | |
el17arm | 2:ba653520a140 | 19 | contrast(); |
el17arm | 2:ba653520a140 | 20 | minerbitmap(); |
el17arm | 0:9e5f9e1c8ef9 | 21 | } |
el17arm | 5:f09602591ad3 | 22 | |
el17arm | 0:9e5f9e1c8ef9 | 23 | } |
el17arm | 0:9e5f9e1c8ef9 | 24 | |
el17arm | 0:9e5f9e1c8ef9 | 25 | void init() |
el17arm | 0:9e5f9e1c8ef9 | 26 | { |
el17arm | 0:9e5f9e1c8ef9 | 27 | lcd.init(); |
el17arm | 1:c80162894831 | 28 | lcd.normalMode(); // normal colour mode |
el17arm | 1:c80162894831 | 29 | lcd.setBrightness(0.5); // put LED backlight on 50% |
el17arm | 1:c80162894831 | 30 | lcd.refresh(); |
el17arm | 5:f09602591ad3 | 31 | pad.init(); |
el17arm | 5:f09602591ad3 | 32 | pad.leds_off(); |
el17arm | 1:c80162894831 | 33 | } |
el17arm | 1:c80162894831 | 34 | |
el17arm | 1:c80162894831 | 35 | void contrast() |
el17arm | 5:f09602591ad3 | 36 | { |
el17arm | 1:c80162894831 | 37 | lcd.refresh(); |
el17arm | 1:c80162894831 | 38 | float con = pot0.read(); |
el17arm | 1:c80162894831 | 39 | lcd.setContrast(con); |
el17arm | 5:f09602591ad3 | 40 | |
el17arm | 5:f09602591ad3 | 41 | |
el17arm | 2:ba653520a140 | 42 | } |
el17arm | 2:ba653520a140 | 43 | |
el17arm | 2:ba653520a140 | 44 | void minerbitmap() |
el17arm | 2:ba653520a140 | 45 | { |
el17arm | 2:ba653520a140 | 46 | const int miner[13][5] = { |
el17arm | 2:ba653520a140 | 47 | 0,0,0,1,1, |
el17arm | 2:ba653520a140 | 48 | 0,1,1,1,1, |
el17arm | 2:ba653520a140 | 49 | 0,1,0,1,0, |
el17arm | 2:ba653520a140 | 50 | 0,1,1,1,1, |
el17arm | 2:ba653520a140 | 51 | 0,1,1,1,0, |
el17arm | 2:ba653520a140 | 52 | 0,0,1,0,0, |
el17arm | 2:ba653520a140 | 53 | 1,1,1,1,1, |
el17arm | 2:ba653520a140 | 54 | 1,1,1,1,1, |
el17arm | 2:ba653520a140 | 55 | 1,1,1,1,1, |
el17arm | 2:ba653520a140 | 56 | 0,1,1,1,0, |
el17arm | 2:ba653520a140 | 57 | 0,1,0,1,0, |
el17arm | 2:ba653520a140 | 58 | 0,1,1,1,1, |
el17arm | 2:ba653520a140 | 59 | }; |
el17arm | 5:f09602591ad3 | 60 | |
el17arm | 2:ba653520a140 | 61 | lcd.clear(); |
el17arm | 5:f09602591ad3 | 62 | |
el17arm | 5:f09602591ad3 | 63 | |
el17arm | 5:f09602591ad3 | 64 | Direction d = pad.get_direction(); |
el17arm | 5:f09602591ad3 | 65 | printf("Direction = %i\n",d); |
el17arm | 5:f09602591ad3 | 66 | |
el17arm | 5:f09602591ad3 | 67 | lcd.drawSprite(WIDTH/2 + x,HEIGHT/2 + y,13,5,(int *)miner); |
el17arm | 5:f09602591ad3 | 68 | |
el17arm | 5:f09602591ad3 | 69 | |
el17arm | 5:f09602591ad3 | 70 | if (d==3) { |
el17arm | 3:140cad440684 | 71 | |
el17arm | 5:f09602591ad3 | 72 | x = x+1; |
el17arm | 5:f09602591ad3 | 73 | lcd.refresh(); |
el17arm | 5:f09602591ad3 | 74 | wait(0.05); |
el17arm | 5:f09602591ad3 | 75 | |
el17arm | 5:f09602591ad3 | 76 | } |
el17arm | 5:f09602591ad3 | 77 | |
el17arm | 5:f09602591ad3 | 78 | if (d == 7) { |
el17arm | 5:f09602591ad3 | 79 | |
el17arm | 5:f09602591ad3 | 80 | x = x-1; |
el17arm | 5:f09602591ad3 | 81 | lcd.refresh(); |
el17arm | 5:f09602591ad3 | 82 | wait(0.05); |
el17arm | 5:f09602591ad3 | 83 | } |
el17arm | 5:f09602591ad3 | 84 | //lcd.drawSprite(WIDTH/2 + x,HEIGHT/2 + y,13,5,(int *)miner); |
el17arm | 5:f09602591ad3 | 85 | //lcd.refresh(); |
el17arm | 5:f09602591ad3 | 86 | |
el17arm | 5:f09602591ad3 | 87 | if(pad.check_event(Gamepad::A_PRESSED)) { |
el17arm | 2:ba653520a140 | 88 | |
el17arm | 2:ba653520a140 | 89 | |
el17arm | 5:f09602591ad3 | 90 | printf("A pressed"); |
el17arm | 5:f09602591ad3 | 91 | y = y - 6; |
el17arm | 5:f09602591ad3 | 92 | lcd.clear(); |
el17arm | 5:f09602591ad3 | 93 | lcd.drawSprite(WIDTH/2 + x,HEIGHT/2 + y,13,5,(int *)miner); |
el17arm | 5:f09602591ad3 | 94 | lcd.refresh(); |
el17arm | 5:f09602591ad3 | 95 | wait(0.2); |
el17arm | 5:f09602591ad3 | 96 | y= y + 6; |
el17arm | 5:f09602591ad3 | 97 | } |
el17arm | 5:f09602591ad3 | 98 | |
el17arm | 5:f09602591ad3 | 99 | |
el17arm | 5:f09602591ad3 | 100 | |
el17arm | 5:f09602591ad3 | 101 | } |