Yang Zhenye 201199680
Dependencies: mbed
Rooney/Rooney.cpp@6:4abef55fee88, 2020-05-14 (annotated)
- Committer:
- yangzhenye
- Date:
- Thu May 14 15:55:41 2020 +0000
- Revision:
- 6:4abef55fee88
- Parent:
- 5:fcad75e9b9e1
- Child:
- 7:a69ae964412c
el17zy
Who changed what in which revision?
User | Revision | Line number | New 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 | 5:fcad75e9b9e1 | 13 | #include "Rooney.h" |
yangzhenye | 5:fcad75e9b9e1 | 14 | |
yangzhenye | 5:fcad75e9b9e1 | 15 | player::player(){} |
yangzhenye | 5:fcad75e9b9e1 | 16 | player::~player(){} |
yangzhenye | 5:fcad75e9b9e1 | 17 | |
yangzhenye | 5:fcad75e9b9e1 | 18 | int _stand[10][5] = { |
yangzhenye | 1:74f525027af6 | 19 | {0,0,1,0,0}, |
yangzhenye | 1:74f525027af6 | 20 | {0,1,0,1,0}, |
yangzhenye | 1:74f525027af6 | 21 | {0,0,1,0,0}, |
yangzhenye | 1:74f525027af6 | 22 | {1,0,1,0,1}, |
yangzhenye | 1:74f525027af6 | 23 | {1,1,1,1,1}, |
yangzhenye | 1:74f525027af6 | 24 | {0,0,1,0,0}, |
yangzhenye | 1:74f525027af6 | 25 | {0,0,1,0,0}, |
yangzhenye | 1:74f525027af6 | 26 | {0,0,1,0,0}, |
yangzhenye | 1:74f525027af6 | 27 | {0,1,0,1,0}, |
yangzhenye | 1:74f525027af6 | 28 | {1,0,0,0,1}, |
yangzhenye | 1:74f525027af6 | 29 | }; |
yangzhenye | 5:fcad75e9b9e1 | 30 | int _left[5][10] = { |
yangzhenye | 1:74f525027af6 | 31 | {0,0,0,1,1,0,0,0,0,1}, |
yangzhenye | 1:74f525027af6 | 32 | {0,1,0,0,1,0,0,0,1,0}, |
yangzhenye | 1:74f525027af6 | 33 | {1,0,1,1,1,1,1,1,0,0}, |
yangzhenye | 1:74f525027af6 | 34 | {0,1,0,0,1,0,0,0,1,0}, |
yangzhenye | 1:74f525027af6 | 35 | {0,0,0,1,1,0,0,0,0,1}, |
yangzhenye | 1:74f525027af6 | 36 | }; |
yangzhenye | 5:fcad75e9b9e1 | 37 | int _right[5][10] = { |
yangzhenye | 1:74f525027af6 | 38 | {1,0,0,0,0,1,1,0,0,0}, |
yangzhenye | 1:74f525027af6 | 39 | {0,1,0,0,0,1,0,0,1,0}, |
yangzhenye | 1:74f525027af6 | 40 | {0,0,1,1,1,1,1,1,0,1}, |
yangzhenye | 1:74f525027af6 | 41 | {0,1,0,0,0,1,0,0,1,0}, |
yangzhenye | 1:74f525027af6 | 42 | {1,0,0,0,0,1,1,0,0,0}, |
yangzhenye | 1:74f525027af6 | 43 | }; |
yangzhenye | 1:74f525027af6 | 44 | |
yangzhenye | 1:74f525027af6 | 45 | void player::init(){ |
yangzhenye | 3:30c81344beff | 46 | _player_x=38; |
yangzhenye | 3:30c81344beff | 47 | _player_y=5; |
yangzhenye | 1:74f525027af6 | 48 | } |
yangzhenye | 5:fcad75e9b9e1 | 49 | void player::set_palyer_x(float joy_x, int speed) { |
yangzhenye | 1:74f525027af6 | 50 | _speed=speed; |
yangzhenye | 5:fcad75e9b9e1 | 51 | if (joy_x < float(-0.5)){ |
yangzhenye | 1:74f525027af6 | 52 | _speed=-0.5; |
yangzhenye | 5:fcad75e9b9e1 | 53 | _player_x=38+_speed;} |
yangzhenye | 5:fcad75e9b9e1 | 54 | else if (_player_x<=0){ |
yangzhenye | 5:fcad75e9b9e1 | 55 | _speed = 0; |
yangzhenye | 1:74f525027af6 | 56 | } |
yangzhenye | 5:fcad75e9b9e1 | 57 | if (joy_x > float(0.5)){ |
yangzhenye | 1:74f525027af6 | 58 | _speed=0.5; |
yangzhenye | 5:fcad75e9b9e1 | 59 | _player_x=38+_speed;} |
yangzhenye | 5:fcad75e9b9e1 | 60 | else if (_player_x>=80){ |
yangzhenye | 5:fcad75e9b9e1 | 61 | _speed = 0;} |
yangzhenye | 1:74f525027af6 | 62 | } |
yangzhenye | 5:fcad75e9b9e1 | 63 | |
yangzhenye | 6:4abef55fee88 | 64 | //void player::draw_gate(N5110 &lcd) { |
yangzhenye | 6:4abef55fee88 | 65 | // lcd.drawLine(unsigned int const x0, |
yangzhenye | 6:4abef55fee88 | 66 | // unsigned int const y0, |
yangzhenye | 6:4abef55fee88 | 67 | // unsigned int const x1, |
yangzhenye | 6:4abef55fee88 | 68 | // unsigned int const y1, |
yangzhenye | 6:4abef55fee88 | 69 | // FullBlack) |
yangzhenye | 6:4abef55fee88 | 70 | //} |
yangzhenye | 6:4abef55fee88 | 71 | void player::add_score() |
yangzhenye | 6:4abef55fee88 | 72 | { |
yangzhenye | 6:4abef55fee88 | 73 | _score++; |
yangzhenye | 5:fcad75e9b9e1 | 74 | } |
yangzhenye | 6:4abef55fee88 | 75 | int player::get_score() |
yangzhenye | 6:4abef55fee88 | 76 | { |
yangzhenye | 6:4abef55fee88 | 77 | return _score; |
yangzhenye | 6:4abef55fee88 | 78 | } |
yangzhenye | 6:4abef55fee88 | 79 | bool player::collision_flag() { |
yangzhenye | 6:4abef55fee88 | 80 | if ((_player_x == _x - 2) && (_player_y == _y - 5)) { |
yangzhenye | 3:30c81344beff | 81 | _collision_flag = true; |
yangzhenye | 6:4abef55fee88 | 82 | _score++; |
yangzhenye | 3:30c81344beff | 83 | } |
yangzhenye | 6:4abef55fee88 | 84 | } |
yangzhenye | 5:fcad75e9b9e1 | 85 | int * player::get_form(rooneybody body){ |
yangzhenye | 5:fcad75e9b9e1 | 86 | if (body == left){ |
yangzhenye | 1:74f525027af6 | 87 | return *left} |
yangzhenye | 5:fcad75e9b9e1 | 88 | else if (body == right){ |
yangzhenye | 1:74f525027af6 | 89 | return *right} |
yangzhenye | 5:fcad75e9b9e1 | 90 | else if (body == stand){ |
yangzhenye | 6:4abef55fee88 | 91 | return *stand}} |
yangzhenye | 5:fcad75e9b9e1 | 92 | lcd.drawSprite(_player_x, _player_y, 5, 10, (int *)get_form(body)); |
yangzhenye | 1:74f525027af6 | 93 | int player::get_x(){ |
yangzhenye | 3:30c81344beff | 94 | return _player_x; |
yangzhenye | 1:74f525027af6 | 95 | } |
yangzhenye | 1:74f525027af6 | 96 | int player::get_y(){ |
yangzhenye | 3:30c81344beff | 97 | return _player_y; |
yangzhenye | 1:74f525027af6 | 98 | } |
yangzhenye | 1:74f525027af6 | 99 | int player::get_speed(){ |
yangzhenye | 1:74f525027af6 | 100 | return _speed; |
yangzhenye | 6:4abef55fee88 | 101 | } |
yangzhenye | 6:4abef55fee88 | 102 |