Yang Zhenye 201199680

Dependencies:   mbed

RooneyEngine/RooneyEngine.cpp

Committer:
yangzhenye
Date:
2020-05-14
Revision:
7:a69ae964412c
Parent:
5:fcad75e9b9e1
Child:
8:c02c278320c0

File content as of revision 7:a69ae964412c:

/* 
ELEC2645 Embedded Systems Project
School of Electronic & Electrical Engineering
University of Leeds
2019/20

Name:Yang Zhenye
Username:el17zy
Student ID Number:201199680
Date:2020/5/12
*/

#include "RooneyEngine.h"

char buffer[15];
RooneyEngine::RooneyEngine(){}
RooneyEngine::~RooneyEngine(){}
void RooneyEngine::init() {
     reset();
     _start_flag = true;
     }
     
void RooneyEngine::reset() {
     _player_x=38;
     _player_y=5;
     _collision_flag = false;
     _player_score = 0;
     _x = WIDTH/2 -  2/2;
     _y = HEIGHT/2 - 2/2;
     }

void RooneyEngine::check_reset(N5110 &lcd, Gamepad &gamepad) {
 if(get_reset_flag()){
     gamepad.leds_on();
     lcd.clear();
     for (int i = 0; i<60; i++) {
         lcd.printString("lose the game", 0, 2);
         lcd.printString("sccore:", 0, 4);
         wait(0.00001);
         sprintf(buffer,"%2d",_player_score); 
         lcd.printString(buffer,16,4);
         reset();
         }
         }
         }

void RooneyEngine::check_start(N5110 &lcd, Gamepad &gamepad) {
     if(_start_flag == true) { 
     check_reset(lcd, gamepad);} 
    _start_flag = get_start_flag(); 
    }
    
void RooneyEngine::check_collision(Gamepad &gamepad) { 
    if ((_player_x == _x - 2) && (_player_y == _y - 5)) {  
    _collision_flag = true;
    _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::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
         }
        }
        
bool RooneyEngine::get_reset_flag() {
        return _reset_flag;
        }

bool RooneyEngine::get_start_flag() {
        return _start_flag;
        }        
        
void RooneyEngine::run_engine(N5110 &lcd, Gamepad &gamepad) {
    init();
    reset();
    check_reset(N5110 &lcd, Gamepad &gamepad);
    check_start(N5110 &lcd, Gamepad &gamepad);
    check_collision(Gamepad &gamepad);
    _player_score=get_score();
    get_sprite();
    update_lcd(N5110 &lcd);
    get_reset_flag();
    get_start_flag();
    get_rooney_x(Gamepad &gamepad);
    }