Yang Zhenye 201199680
Dependencies: mbed
Revision 9:a5a82b3d1102, committed 2020-05-15
- Comitter:
- yangzhenye
- Date:
- Fri May 15 07:27:23 2020 +0000
- Parent:
- 8:c02c278320c0
- Commit message:
- el17zy Yang Zhenye
Changed in this revision
diff -r c02c278320c0 -r a5a82b3d1102 Menu/Menu.cpp --- a/Menu/Menu.cpp Thu May 14 18:30:55 2020 +0000 +++ b/Menu/Menu.cpp Fri May 15 07:27:23 2020 +0000 @@ -77,12 +77,13 @@ _input = 3;} } void Menu::get_output(N5110 &lcd, Gamepad &gamepad) { - if (_output == 0) { - display_page1(lcd, gamepad); + if (_output == 0) { run_engine(lcd, gamepad); } else if(_output == 1) { - display_page2(lcd, gamepad); - run_engine(lcd, gamepad); } + display_page1(lcd, gamepad); + // display_page2(lcd, gamepad); + // run_engine(lcd, gamepad); + } else if(_output == 2) { display_page3(lcd, gamepad); } } //display the three pages @@ -93,9 +94,9 @@ lcd.printString("X - instruction",0,5); lcd.drawSprite(1,60,30,80,(int*)_sprite); } -void Menu::display_page2(N5110 &lcd, Gamepad &gamepad) { - lcd.printString("It is Rooney turn!",0,0); -} +//void Menu::display_page2(N5110 &lcd, Gamepad &gamepad) { +// lcd.printString("It is Rooney turn!",0,0); +//} void Menu::display_page3(N5110 &lcd, Gamepad &gamepad) { lcd.printString("joystick - ",0,1);
diff -r c02c278320c0 -r a5a82b3d1102 Menu/Menu.h --- a/Menu/Menu.h Thu May 14 18:30:55 2020 +0000 +++ b/Menu/Menu.h Fri May 15 07:27:23 2020 +0000 @@ -21,13 +21,27 @@ * @brief Destructor @details Non user specified. */ ~Menu(); + // Mutators + /** + * @brief Initialises the Menu. + */ void init(); + /** + * @brief Runs the menu and a state machine. + * @param &lcd @details The lcd object from the N5110 class + * @param &gamepad @details The gamepad object from Gamepad class + */ void run_engine(N5110 &lcd, Gamepad &gamepad); + /** + * @brief Runs the game. + * @param &lcd @details The lcd object from the N5110 class + * @param &gamepad @details The gamepad object from Gamepad class + */ void run_game(N5110 &lcd, Gamepad &gamepad); private: void display_page1(N5110 &lcd, Gamepad &gamepad); - void display_page2(N5110 &lcd, Gamepad &gamepad); + // void display_page2(N5110 &lcd, Gamepad &gamepad); void display_page3(N5110 &lcd, Gamepad &gamepad); void get_output(N5110 &lcd, Gamepad &gamepad); void get_input(bool start, bool back, bool x);
diff -r c02c278320c0 -r a5a82b3d1102 Rooney/Rooney.h --- a/Rooney/Rooney.h Thu May 14 18:30:55 2020 +0000 +++ b/Rooney/Rooney.h Fri May 15 07:27:23 2020 +0000 @@ -17,18 +17,46 @@ * @brief Destructor @details Non user specified. */ ~player(); - + /** + * @brief Initialises the Rooney. + */ void init(); + /** + * @brief set the rooney position. + */ void set_palyer_x(float joy_x, int speed); -//void draw_gate(N5110 &lcd);] + /** + * @brief get the collision flag. + * @param &gamepad @details The gamepad object from Gamepad class. + */ bool collision_flag(); - + /** + * @brief set the rooney body form. + */ int * get_form(rooneybody body); + /** + * @brief set the rooney body y. + */ int get_y(); + /** + * @brief set the rooney body x. + */ int get_x(); + /** + * @brief set the rooney speed + */ int get_speed(); + /** + * @brief add the score. + */ void add_score(); + /** + * @brief get the score. + */ int get_score(); + /** + * @draw form. + */ int drawrooney(N5110 &lcd); private:
diff -r c02c278320c0 -r a5a82b3d1102 RooneyEngine/RooneyEngine.cpp --- a/RooneyEngine/RooneyEngine.cpp Thu May 14 18:30:55 2020 +0000 +++ b/RooneyEngine/RooneyEngine.cpp Fri May 15 07:27:23 2020 +0000 @@ -12,7 +12,7 @@ #include "RooneyEngine.h" -char buffer[15]; +char buffer[14]; RooneyEngine::RooneyEngine(){} RooneyEngine::~RooneyEngine(){} void RooneyEngine::init() { @@ -21,6 +21,7 @@ } void RooneyEngine::reset() { + _control.c.x=0; _player_x=38; _player_y=5; _collision_flag = false; @@ -29,6 +30,11 @@ _y = HEIGHT/2 - 2/2; } +void RooneyEngine::read_input(Gamepad &gamepad) { + _control.c = gamepad.get_mapped_coord(); +// X_flag = gamepad.check_event(Gamepad::X_PRESSED); +} + void RooneyEngine::check_reset(N5110 &lcd, Gamepad &gamepad) { if(get_reset_flag()){ gamepad.leds_on(); @@ -36,7 +42,7 @@ for (int i = 0; i<60; i++) { lcd.printString("lose the game", 0, 2); lcd.printString("sccore:", 0, 4); - wait(0.00001); + wait(0.001); sprintf(buffer,"%2d",_player_score); lcd.printString(buffer,16,4); reset(); @@ -57,44 +63,36 @@ } } -//int RooneyEngine::get_score() { - // return _player_score; - // } +int RooneyEngine::get_score() { + return _player_score;} -//void RooneyEngine::get_sprite() { -// lcd.drawLine(unsigned int const x0, - // unsigned int const y0, - // unsigned int const x1, - // unsigned int const y1, - // FullBlack); - // lcd.drawSprite(_player_x, _player_y, 5, 10, (int *)get_form(ronnybody)); - // lcd.drawRect(_x,_y,_size,_size,FILL_BLACK); - // } +void RooneyEngine::get_sprite(N5110 &lcd) { + lcd.drawRect(_x,_y,10,20,FILL_BLACK);} -//void RooneyEngine::update_lcd(N5110 &lcd) { - // get_sprite(); -// sprintf(buffer,"%2d",_player_score); - // lcd.printString("score",0,0); - // lcd.printString(buffer,30,0); - // } - -//void RooneyEngine::get_rooney_x(Gamepad &gamepad) { - // _speed=speed; -// if (joy_x < float(-0.5){ - // _speed=-0.5; -// _player_x=38+_speed; -// else if (x<=0){ -// _speed = 0 - // } -// } - // if (joy_x > float(0.5){ - // _speed=0.5; - // _player_x=38+_speed; - // else if (x>=80){ - // _speed = 0 -// } -// } - +void RooneyEngine::update_lcd(N5110 &lcd) { + get_sprite(lcd); + sprintf(buffer,"%2d",_player_score); + lcd.printString("score",0,0); + lcd.printString(buffer,30,0); + } + +int RooneyEngine::get_speed() {return _speed;} + +void RooneyEngine::get_rooney_x(Gamepad &gamepad,int speed,float joy_x) { + _speed=speed; + if (joy_x < float(-0.5)){ + _speed=-0.5; + _player_x=38+_speed;} + else if (_x<=0){ + _speed = 0; + } + if (joy_x > float(0.5)){ + _speed=0.5; + _player_x=38+_speed;} + else if (_x>=80){ + _speed = 0; + } + } bool RooneyEngine::get_reset_flag() { return _reset_flag; } @@ -109,16 +107,15 @@ check_reset(lcd, gamepad); check_start(lcd, gamepad); check_collision(gamepad); -// _player_score=get_score(); - // get_sprite(); - // update_lcd(lcd); + _speed=get_speed(); + _player_score=get_score(); + get_sprite(lcd); + _player.drawrooney(lcd); + update_lcd(lcd); get_reset_flag(); get_start_flag(); - // get_rooney_x(gamepad); - } - - - + get_rooney_x(gamepad,_speed,_control.c.x); + }
diff -r c02c278320c0 -r a5a82b3d1102 RooneyEngine/RooneyEngine.h --- a/RooneyEngine/RooneyEngine.h Thu May 14 18:30:55 2020 +0000 +++ b/RooneyEngine/RooneyEngine.h Fri May 15 07:27:23 2020 +0000 @@ -1,3 +1,4 @@ + #ifndef ROONEYENGINE_H #define ROONEYENGIN_H @@ -6,6 +7,28 @@ #include "Gamepad.h" #include "Rooney.h" #include "Ball.h" +/** control struct */ +struct control { + Vector2D c; /**< Vector 2D for joystick x */ + }; + /** RooneyEngine class + * @1 make the whole game run and set the score the reset process + * @2 cheak the collision and the reset or fall flag + * @3 draw on the lcd screen and load the gamepad controll + * @date May 14th 2020 + * @author Yang Zhenye + +@ code + +#include "mbed.h" +#include "N5110.h" +#include "Gamepad.h" +#include "RooneyEngine.h" +@endcode +*/ + + + class RooneyEngine{ public: @@ -18,19 +41,74 @@ * @brief Destructor @details Non user specified. */ ~RooneyEngine(); + // Mutators. + /** + * @brief Initalises the RooneyEngine + */ void init(); + /** + * @brief reset the RooneyEngine. + */ void reset(); + /** + * @brief get the coordinate and the button_flag. + * @param &gamepad @details The gamepad object from Gamepad class. + */ + void read_input(Gamepad &pad); + /** + * @brief check and flesh the reset flag. + * @param &gamepad @details The gamepad object from Gamepad class. + * @param &lcd @details The lcd object from the N5110 class + */ void check_reset(N5110 &lcd, Gamepad &gamepad); + /** + * @brief check and flesh the start flag. + * @param &gamepad @details The gamepad object from Gamepad class. + * @param &lcd @details The lcd object from the N5110 class + */ void check_start(N5110 &lcd, Gamepad &gamepad); + /** + * @brief check and flesh the collision flag. + * @param &gamepad @details The gamepad object from Gamepad class. + */ void check_collision(Gamepad &gamepad); - void get_score(); - // void get_sprite(); + /** + * @brief get the player score. + */ + int get_score(); + /** + * @brief get the player speed. + */ + int get_speed(); + /** + * @brief get the sprite. + */ + void get_sprite(N5110 &lcd); + /** + * @brief Updates the LCD display. + * @param &lcd @details The lcd object from the N5110 class. + */ void update_lcd(N5110 &lcd); + /** + * @brief run the game. + */ void run_engine(N5110 &lcd, Gamepad &gamepad); + /** + * @brief get the reset flag. + */ bool get_reset_flag(); + /** + * @brief get the start flag. + */ bool get_start_flag(); - void get_rooney_x(Gamepad &gamepad); + /** + * @brief get player's x + */ + void get_rooney_x(Gamepad &gamepad,int speed,float joy_x); private: + control _control; + player _player; + rooneybody body; int _player_x; int _player_y; int _x;