zhenye yang
/
el17zy
Yang Zhenye 201199680
Diff: RooneyEngine/RooneyEngine.cpp
- Revision:
- 9:a5a82b3d1102
- Parent:
- 8:c02c278320c0
--- 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); + }