Yang Zhenye 201199680

Dependencies:   mbed

Committer:
yangzhenye
Date:
Thu May 14 18:30:55 2020 +0000
Revision:
8:c02c278320c0
Parent:
7:a69ae964412c
Child:
9:a5a82b3d1102
el17zy

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yangzhenye 5:fcad75e9b9e1 1 /*
yangzhenye 5:fcad75e9b9e1 2 ELEC2645 Embedded Systems Project
yangzhenye 5:fcad75e9b9e1 3 School of Electronic & Electrical Engineering
yangzhenye 5:fcad75e9b9e1 4 University of Leeds
yangzhenye 5:fcad75e9b9e1 5 2019/20
yangzhenye 5:fcad75e9b9e1 6
yangzhenye 5:fcad75e9b9e1 7 Name:Yang Zhenye
yangzhenye 5:fcad75e9b9e1 8 Username:el17zy
yangzhenye 5:fcad75e9b9e1 9 Student ID Number:201199680
yangzhenye 5:fcad75e9b9e1 10 Date:2020/5/12
yangzhenye 5:fcad75e9b9e1 11 */
yangzhenye 5:fcad75e9b9e1 12
yangzhenye 7:a69ae964412c 13 #include "RooneyEngine.h"
yangzhenye 3:30c81344beff 14
yangzhenye 7:a69ae964412c 15 char buffer[15];
yangzhenye 5:fcad75e9b9e1 16 RooneyEngine::RooneyEngine(){}
yangzhenye 5:fcad75e9b9e1 17 RooneyEngine::~RooneyEngine(){}
yangzhenye 4:eb8dca1dc341 18 void RooneyEngine::init() {
yangzhenye 3:30c81344beff 19 reset();
yangzhenye 3:30c81344beff 20 _start_flag = true;
yangzhenye 3:30c81344beff 21 }
yangzhenye 3:30c81344beff 22
yangzhenye 4:eb8dca1dc341 23 void RooneyEngine::reset() {
yangzhenye 3:30c81344beff 24 _player_x=38;
yangzhenye 3:30c81344beff 25 _player_y=5;
yangzhenye 7:a69ae964412c 26 _collision_flag = false;
yangzhenye 3:30c81344beff 27 _player_score = 0;
yangzhenye 7:a69ae964412c 28 _x = WIDTH/2 - 2/2;
yangzhenye 7:a69ae964412c 29 _y = HEIGHT/2 - 2/2;
yangzhenye 3:30c81344beff 30 }
yangzhenye 3:30c81344beff 31
yangzhenye 7:a69ae964412c 32 void RooneyEngine::check_reset(N5110 &lcd, Gamepad &gamepad) {
yangzhenye 3:30c81344beff 33 if(get_reset_flag()){
yangzhenye 3:30c81344beff 34 gamepad.leds_on();
yangzhenye 3:30c81344beff 35 lcd.clear();
yangzhenye 3:30c81344beff 36 for (int i = 0; i<60; i++) {
yangzhenye 3:30c81344beff 37 lcd.printString("lose the game", 0, 2);
yangzhenye 3:30c81344beff 38 lcd.printString("sccore:", 0, 4);
yangzhenye 3:30c81344beff 39 wait(0.00001);
yangzhenye 3:30c81344beff 40 sprintf(buffer,"%2d",_player_score);
yangzhenye 3:30c81344beff 41 lcd.printString(buffer,16,4);
yangzhenye 3:30c81344beff 42 reset();
yangzhenye 3:30c81344beff 43 }
yangzhenye 3:30c81344beff 44 }
yangzhenye 7:a69ae964412c 45 }
yangzhenye 3:30c81344beff 46
yangzhenye 4:eb8dca1dc341 47 void RooneyEngine::check_start(N5110 &lcd, Gamepad &gamepad) {
yangzhenye 3:30c81344beff 48 if(_start_flag == true) {
yangzhenye 3:30c81344beff 49 check_reset(lcd, gamepad);}
yangzhenye 3:30c81344beff 50 _start_flag = get_start_flag();
yangzhenye 3:30c81344beff 51 }
yangzhenye 3:30c81344beff 52
yangzhenye 4:eb8dca1dc341 53 void RooneyEngine::check_collision(Gamepad &gamepad) {
yangzhenye 7:a69ae964412c 54 if ((_player_x == _x - 2) && (_player_y == _y - 5)) {
yangzhenye 3:30c81344beff 55 _collision_flag = true;
yangzhenye 3:30c81344beff 56 _player_score++;
yangzhenye 3:30c81344beff 57 }
yangzhenye 7:a69ae964412c 58 }
yangzhenye 3:30c81344beff 59
yangzhenye 7:a69ae964412c 60 //int RooneyEngine::get_score() {
yangzhenye 7:a69ae964412c 61 // return _player_score;
yangzhenye 7:a69ae964412c 62 // }
yangzhenye 3:30c81344beff 63
yangzhenye 7:a69ae964412c 64 //void RooneyEngine::get_sprite() {
yangzhenye 7:a69ae964412c 65 // lcd.drawLine(unsigned int const x0,
yangzhenye 7:a69ae964412c 66 // unsigned int const y0,
yangzhenye 7:a69ae964412c 67 // unsigned int const x1,
yangzhenye 7:a69ae964412c 68 // unsigned int const y1,
yangzhenye 7:a69ae964412c 69 // FullBlack);
yangzhenye 7:a69ae964412c 70 // lcd.drawSprite(_player_x, _player_y, 5, 10, (int *)get_form(ronnybody));
yangzhenye 7:a69ae964412c 71 // lcd.drawRect(_x,_y,_size,_size,FILL_BLACK);
yangzhenye 7:a69ae964412c 72 // }
yangzhenye 3:30c81344beff 73
yangzhenye 8:c02c278320c0 74 //void RooneyEngine::update_lcd(N5110 &lcd) {
yangzhenye 8:c02c278320c0 75 // get_sprite();
yangzhenye 8:c02c278320c0 76 // sprintf(buffer,"%2d",_player_score);
yangzhenye 8:c02c278320c0 77 // lcd.printString("score",0,0);
yangzhenye 8:c02c278320c0 78 // lcd.printString(buffer,30,0);
yangzhenye 8:c02c278320c0 79 // }
yangzhenye 3:30c81344beff 80
yangzhenye 8:c02c278320c0 81 //void RooneyEngine::get_rooney_x(Gamepad &gamepad) {
yangzhenye 8:c02c278320c0 82 // _speed=speed;
yangzhenye 8:c02c278320c0 83 // if (joy_x < float(-0.5){
yangzhenye 8:c02c278320c0 84 // _speed=-0.5;
yangzhenye 8:c02c278320c0 85 // _player_x=38+_speed;
yangzhenye 8:c02c278320c0 86 // else if (x<=0){
yangzhenye 8:c02c278320c0 87 // _speed = 0
yangzhenye 8:c02c278320c0 88 // }
yangzhenye 8:c02c278320c0 89 // }
yangzhenye 8:c02c278320c0 90 // if (joy_x > float(0.5){
yangzhenye 8:c02c278320c0 91 // _speed=0.5;
yangzhenye 8:c02c278320c0 92 // _player_x=38+_speed;
yangzhenye 8:c02c278320c0 93 // else if (x>=80){
yangzhenye 8:c02c278320c0 94 // _speed = 0
yangzhenye 8:c02c278320c0 95 // }
yangzhenye 8:c02c278320c0 96 // }
yangzhenye 3:30c81344beff 97
yangzhenye 4:eb8dca1dc341 98 bool RooneyEngine::get_reset_flag() {
yangzhenye 3:30c81344beff 99 return _reset_flag;
yangzhenye 3:30c81344beff 100 }
yangzhenye 3:30c81344beff 101
yangzhenye 4:eb8dca1dc341 102 bool RooneyEngine::get_start_flag() {
yangzhenye 3:30c81344beff 103 return _start_flag;
yangzhenye 3:30c81344beff 104 }
yangzhenye 3:30c81344beff 105
yangzhenye 4:eb8dca1dc341 106 void RooneyEngine::run_engine(N5110 &lcd, Gamepad &gamepad) {
yangzhenye 3:30c81344beff 107 init();
yangzhenye 3:30c81344beff 108 reset();
yangzhenye 8:c02c278320c0 109 check_reset(lcd, gamepad);
yangzhenye 8:c02c278320c0 110 check_start(lcd, gamepad);
yangzhenye 8:c02c278320c0 111 check_collision(gamepad);
yangzhenye 8:c02c278320c0 112 // _player_score=get_score();
yangzhenye 8:c02c278320c0 113 // get_sprite();
yangzhenye 8:c02c278320c0 114 // update_lcd(lcd);
yangzhenye 3:30c81344beff 115 get_reset_flag();
yangzhenye 3:30c81344beff 116 get_start_flag();
yangzhenye 8:c02c278320c0 117 // get_rooney_x(gamepad);
yangzhenye 3:30c81344beff 118 }
yangzhenye 3:30c81344beff 119
yangzhenye 3:30c81344beff 120
yangzhenye 3:30c81344beff 121
yangzhenye 3:30c81344beff 122
yangzhenye 3:30c81344beff 123
yangzhenye 3:30c81344beff 124
yangzhenye 3:30c81344beff 125
yangzhenye 3:30c81344beff 126
yangzhenye 3:30c81344beff 127
yangzhenye 3:30c81344beff 128