Yang Zhenye 201199680
Dependencies: mbed
Roony/Roony.cpp@3:30c81344beff, 2020-05-08 (annotated)
- Committer:
- yangzhenye
- Date:
- Fri May 08 09:09:49 2020 +0000
- Revision:
- 3:30c81344beff
- Parent:
- 2:baca89f466bc
improve project
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yangzhenye | 1:74f525027af6 | 1 | #include "Ronny.h" |
yangzhenye | 1:74f525027af6 | 2 | int stand[5][10] = { |
yangzhenye | 1:74f525027af6 | 3 | {0,0,1,0,0}, |
yangzhenye | 1:74f525027af6 | 4 | {0,1,0,1,0}, |
yangzhenye | 1:74f525027af6 | 5 | {0,0,1,0,0}, |
yangzhenye | 1:74f525027af6 | 6 | {1,0,1,0,1}, |
yangzhenye | 1:74f525027af6 | 7 | {1,1,1,1,1}, |
yangzhenye | 1:74f525027af6 | 8 | {0,0,1,0,0}, |
yangzhenye | 1:74f525027af6 | 9 | {0,0,1,0,0}, |
yangzhenye | 1:74f525027af6 | 10 | {0,0,1,0,0}, |
yangzhenye | 1:74f525027af6 | 11 | {0,1,0,1,0}, |
yangzhenye | 1:74f525027af6 | 12 | {1,0,0,0,1}, |
yangzhenye | 1:74f525027af6 | 13 | }; |
yangzhenye | 1:74f525027af6 | 14 | int left[10][5] = { |
yangzhenye | 1:74f525027af6 | 15 | {0,0,0,1,1,0,0,0,0,1}, |
yangzhenye | 1:74f525027af6 | 16 | {0,1,0,0,1,0,0,0,1,0}, |
yangzhenye | 1:74f525027af6 | 17 | {1,0,1,1,1,1,1,1,0,0}, |
yangzhenye | 1:74f525027af6 | 18 | {0,1,0,0,1,0,0,0,1,0}, |
yangzhenye | 1:74f525027af6 | 19 | {0,0,0,1,1,0,0,0,0,1}, |
yangzhenye | 1:74f525027af6 | 20 | }; |
yangzhenye | 1:74f525027af6 | 21 | int right[10][5] = { |
yangzhenye | 1:74f525027af6 | 22 | {1,0,0,0,0,1,1,0,0,0}, |
yangzhenye | 1:74f525027af6 | 23 | {0,1,0,0,0,1,0,0,1,0}, |
yangzhenye | 1:74f525027af6 | 24 | {0,0,1,1,1,1,1,1,0,1}, |
yangzhenye | 1:74f525027af6 | 25 | {0,1,0,0,0,1,0,0,1,0}, |
yangzhenye | 1:74f525027af6 | 26 | {1,0,0,0,0,1,1,0,0,0}, |
yangzhenye | 1:74f525027af6 | 27 | }; |
yangzhenye | 1:74f525027af6 | 28 | |
yangzhenye | 1:74f525027af6 | 29 | void player::init(){ |
yangzhenye | 3:30c81344beff | 30 | _player_x=38; |
yangzhenye | 3:30c81344beff | 31 | _player_y=5; |
yangzhenye | 1:74f525027af6 | 32 | } |
yangzhenye | 1:74f525027af6 | 33 | void player::set_palyer_x(float joy_x int speed) { |
yangzhenye | 1:74f525027af6 | 34 | _speed=speed; |
yangzhenye | 1:74f525027af6 | 35 | if (joy_x < float(-0.5){ |
yangzhenye | 1:74f525027af6 | 36 | _speed=-0.5; |
yangzhenye | 3:30c81344beff | 37 | _player_x=38+_speed; |
yangzhenye | 1:74f525027af6 | 38 | else if (x<=0){ |
yangzhenye | 1:74f525027af6 | 39 | _speed = 0 |
yangzhenye | 1:74f525027af6 | 40 | } |
yangzhenye | 1:74f525027af6 | 41 | } |
yangzhenye | 1:74f525027af6 | 42 | if (joy_x > float(0.5){ |
yangzhenye | 1:74f525027af6 | 43 | _speed=0.5; |
yangzhenye | 3:30c81344beff | 44 | _player_x=38+_speed; |
yangzhenye | 1:74f525027af6 | 45 | else if (x>=80){ |
yangzhenye | 1:74f525027af6 | 46 | _speed = 0 |
yangzhenye | 1:74f525027af6 | 47 | } |
yangzhenye | 1:74f525027af6 | 48 | } |
yangzhenye | 2:baca89f466bc | 49 | void player::draw_gate(N5110 &lcd) { |
yangzhenye | 2:baca89f466bc | 50 | lcd.drawLine(unsigned int const x0, |
yangzhenye | 2:baca89f466bc | 51 | unsigned int const y0, |
yangzhenye | 2:baca89f466bc | 52 | unsigned int const x1, |
yangzhenye | 2:baca89f466bc | 53 | unsigned int const y1, |
yangzhenye | 2:baca89f466bc | 54 | FullBlack) |
yangzhenye | 2:baca89f466bc | 55 | { |
yangzhenye | 3:30c81344beff | 56 | bool player::collisicon_flag() { |
yangzhenye | 3:30c81344beff | 57 | if ((_player_x == _x() - 2) && (_player_y == _y() - 5)) { |
yangzhenye | 3:30c81344beff | 58 | _collision_flag = true; |
yangzhenye | 3:30c81344beff | 59 | _player_score++; |
yangzhenye | 3:30c81344beff | 60 | } |
yangzhenye | 1:74f525027af6 | 61 | int * player::get_form(roonybody){ |
yangzhenye | 1:74f525027af6 | 62 | if (roonybody == left){ |
yangzhenye | 1:74f525027af6 | 63 | return *left} |
yangzhenye | 1:74f525027af6 | 64 | else if (ronnybody == right){ |
yangzhenye | 1:74f525027af6 | 65 | return *right} |
yangzhenye | 1:74f525027af6 | 66 | else if (ronnybody == stand){ |
yangzhenye | 1:74f525027af6 | 67 | return *stand} |
yangzhenye | 3:30c81344beff | 68 | lcd.drawSprite(_player_x, _player_y, 5, 10, (int *)get_form(ronnybody)); |
yangzhenye | 1:74f525027af6 | 69 | int player::get_x(){ |
yangzhenye | 3:30c81344beff | 70 | return _player_x; |
yangzhenye | 1:74f525027af6 | 71 | } |
yangzhenye | 1:74f525027af6 | 72 | int player::get_y(){ |
yangzhenye | 3:30c81344beff | 73 | return _player_y; |
yangzhenye | 1:74f525027af6 | 74 | } |
yangzhenye | 1:74f525027af6 | 75 | int player::get_speed(){ |
yangzhenye | 1:74f525027af6 | 76 | return _speed; |
yangzhenye | 1:74f525027af6 | 77 | } |