Early commits of my project
Dependencies: mbed Gamepad N5110
Revision 6:6294bf4eafc8, committed 2019-03-13
- Comitter:
- el17arm
- Date:
- Wed Mar 13 16:38:21 2019 +0000
- Parent:
- 5:f09602591ad3
- Commit message:
- implementing class but needs debugging
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sprites.cpp Wed Mar 13 16:38:21 2019 +0000 @@ -0,0 +1,89 @@ +#include "Sprites.h" +#include "main.h" +#include "Gamepad.h" + +Gamepad pad; + +Sprites::Sprites() +{ +} + +Sprites::~Sprites() +{ +} + +void Sprites::miner_move(int x_direction, int y_direction) +{ + + + + const int miner_right[13][5] = { + 0,0,0,1,1, + 0,1,1,1,1, + 0,1,0,1,0, + 0,1,1,1,1, + 0,1,1,1,0, + 0,0,1,0,0, + 1,1,1,1,1, + 1,1,1,1,1, + 1,1,1,1,1, + 0,1,1,1,0, + 0,1,0,1,0, + 0,1,1,1,1, + }; + + const int miner_left[13][5] = { + 1,1,0,0,0, + 1,1,1,1,0, + 0,1,0,1,0, + 1,1,1,1,0, + 0,1,1,1,0, + 0,0,1,0,0, + 1,1,1,1,1, + 1,1,1,1,1, + 1,1,1,1,1, + 0,1,1,1,0, + 0,1,0,1,0, + 1,1,1,1,0, + }; + + lcd.clear(); + + + Direction d = pad.get_direction(); + printf("Direction = %i\n",d); + + lcd.drawSprite(WIDTH/2 + x_direction,HEIGHT/2 + y_direction,13,5,(int *)miner_right); + + + if (d==3) { + + x_direction = x_direction + 1; + lcd.drawSprite(WIDTH/2 + x_direction,HEIGHT/2 + y_direction,13,5,(int *)miner_right); + lcd.refresh(); + wait(0.05); + + } + + if (d == 7) { + + x_direction = x_direction - 1; + lcd.drawSprite(WIDTH/2 + x_direction,HEIGHT/2 + y_direction,13,5,(int *)miner_left); + lcd.refresh(); + wait(0.05); + } + //lcd.drawSprite(WIDTH/2 + x,HEIGHT/2 + y,13,5,(int *)miner); + //lcd.refresh(); + + if(pad.check_event(Gamepad::A_PRESSED)) { + + + printf("A pressed"); + y_direction = y_direction - 6; + lcd.clear(); + lcd.drawSprite(WIDTH/2 + x_direction,HEIGHT/2 + y_direction,13,5,(int *)miner_right); + lcd.refresh(); + wait(0.2); + y_direction = y_direction + 6; + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sprites.h Wed Mar 13 16:38:21 2019 +0000 @@ -0,0 +1,23 @@ +#ifndef SPRITES_H +#define SPRITES_H + +#include "mbed.h" +#include "N5110.h" +#include "Gamepad.h" +#include "main.h" + +class Sprites +{ + +public: + + Sprites(); + ~Sprites(); + void miner_move(int x_direction, int y_direction); + +private: + + int x_direction; + int y_direction; +}; +#endif \ No newline at end of file
--- a/main.cpp Wed Mar 13 15:23:03 2019 +0000 +++ b/main.cpp Wed Mar 13 16:38:21 2019 +0000 @@ -1,23 +1,21 @@ #include "main.h" #include "N5110.h" #include "Gamepad.h" +//#include "Sprites.h" Gamepad pad; +//Sprites sprites; N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); AnalogIn pot0(PTB2); -int x = 0; -int y = 0; - - int main() { init(); + start_screen(); while (1) { contrast(); - minerbitmap(); } } @@ -41,61 +39,16 @@ } -void minerbitmap() +void start_screen() { - const int miner[13][5] = { - 0,0,0,1,1, - 0,1,1,1,1, - 0,1,0,1,0, - 0,1,1,1,1, - 0,1,1,1,0, - 0,0,1,0,0, - 1,1,1,1,1, - 1,1,1,1,1, - 1,1,1,1,1, - 0,1,1,1,0, - 0,1,0,1,0, - 0,1,1,1,1, - }; - - lcd.clear(); - - - Direction d = pad.get_direction(); - printf("Direction = %i\n",d); - - lcd.drawSprite(WIDTH/2 + x,HEIGHT/2 + y,13,5,(int *)miner); - + lcd.printString("******MANIC MILNER!******",0,1); + lcd.printString(" Press start to play! ",0,4); + lcd.refresh(); - if (d==3) { - - x = x+1; - lcd.refresh(); - wait(0.05); - - } - - if (d == 7) { - - x = x-1; - lcd.refresh(); - wait(0.05); + while ( pad.check_event(Gamepad::START_PRESSED) == false) { + pad.leds_on(); + wait(0.1); + pad.leds_off(); + wait(0.1); } - //lcd.drawSprite(WIDTH/2 + x,HEIGHT/2 + y,13,5,(int *)miner); - //lcd.refresh(); - - if(pad.check_event(Gamepad::A_PRESSED)) { - - - printf("A pressed"); - y = y - 6; - lcd.clear(); - lcd.drawSprite(WIDTH/2 + x,HEIGHT/2 + y,13,5,(int *)miner); - lcd.refresh(); - wait(0.2); - y= y + 6; - } - - - -} +} \ No newline at end of file
--- a/main.h Wed Mar 13 15:23:03 2019 +0000 +++ b/main.h Wed Mar 13 16:38:21 2019 +0000 @@ -16,5 +16,6 @@ void init(); void contrast(); void minerbitmap(); +void start_screen(); #endif \ No newline at end of file
--- a/sprites.cpp Wed Mar 13 15:23:03 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,58 +0,0 @@ -void minerbitmap() -{ - const int miner[13][5] = { - 0,0,0,1,1, - 0,1,1,1,1, - 0,1,0,1,0, - 0,1,1,1,1, - 0,1,1,1,0, - 0,0,1,0,0, - 1,1,1,1,1, - 1,1,1,1,1, - 1,1,1,1,1, - 0,1,1,1,0, - 0,1,0,1,0, - 0,1,1,1,1, - }; - - lcd.clear(); - - - Direction d = pad.get_direction(); - printf("Direction = %i\n",d); - - lcd.drawSprite(WIDTH/2 + x,HEIGHT/2 + y,13,5,(int *)miner); - - - if (d==3) { - - x = x+1; - lcd.refresh(); - wait(0.05); - - } - - if (d == 7) { - - x = x-1; - lcd.refresh(); - wait(0.05); - } - //lcd.drawSprite(WIDTH/2 + x,HEIGHT/2 + y,13,5,(int *)miner); - //lcd.refresh(); - - if(pad.check_event(Gamepad::A_PRESSED)) { - - - printf("A pressed"); - y = y - 6; - lcd.clear(); - lcd.drawSprite(WIDTH/2 + x,HEIGHT/2 + y,13,5,(int *)miner); - lcd.refresh(); - wait(0.2); - y= y + 6; - } - - - -}
--- a/sprites.h Wed Mar 13 15:23:03 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,8 +0,0 @@ -#ifndef SPRITES_H -#define SPRITES_H - -#include "mbed.h" -#include "N5110.h" -#include "Gamepad.h" - -#endif \ No newline at end of file