201199550 Li Boyuan PlaneWar Game on K64f
Dependencies: mbed Gamepad N5110
plane.cpp@0:36c99c50e688, 2020-05-14 (annotated)
- Committer:
- LBY
- Date:
- Thu May 14 10:14:48 2020 +0000
- Revision:
- 0:36c99c50e688
From:201199550 Li Boyuan; Game name: PlaneWar
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
LBY | 0:36c99c50e688 | 1 | #include "plane.h" |
LBY | 0:36c99c50e688 | 2 | |
LBY | 0:36c99c50e688 | 3 | void plane::init(){ |
LBY | 0:36c99c50e688 | 4 | _width = 7; |
LBY | 0:36c99c50e688 | 5 | _height = 8; |
LBY | 0:36c99c50e688 | 6 | int d[56] = { |
LBY | 0:36c99c50e688 | 7 | 0,0,0,0,1,0,0, |
LBY | 0:36c99c50e688 | 8 | 0,0,0,0,1,1,0, |
LBY | 0:36c99c50e688 | 9 | 1,0,0,0,1,1,0, |
LBY | 0:36c99c50e688 | 10 | 1,1,1,1,1,1,1, |
LBY | 0:36c99c50e688 | 11 | 1,1,1,1,1,1,1, |
LBY | 0:36c99c50e688 | 12 | 1,0,0,0,1,1,0, |
LBY | 0:36c99c50e688 | 13 | 0,0,0,0,1,1,0, |
LBY | 0:36c99c50e688 | 14 | 0,0,0,0,1,0,0 |
LBY | 0:36c99c50e688 | 15 | }; |
LBY | 0:36c99c50e688 | 16 | for(int i = 0; i<56;i++){ |
LBY | 0:36c99c50e688 | 17 | data[i] = d[i]; |
LBY | 0:36c99c50e688 | 18 | } |
LBY | 0:36c99c50e688 | 19 | _xy.x = 0; |
LBY | 0:36c99c50e688 | 20 | _xy.y = 25; |
LBY | 0:36c99c50e688 | 21 | } |
LBY | 0:36c99c50e688 | 22 | |
LBY | 0:36c99c50e688 | 23 | void plane::update(Gamepad &pad){ |
LBY | 0:36c99c50e688 | 24 | if(pad.get_direction() == N){ |
LBY | 0:36c99c50e688 | 25 | _xy.y = _xy.y - 1; |
LBY | 0:36c99c50e688 | 26 | }else if(pad.get_direction() == S){ |
LBY | 0:36c99c50e688 | 27 | _xy.y = _xy.y + 1; |
LBY | 0:36c99c50e688 | 28 | }else if(pad.get_direction() == W){ |
LBY | 0:36c99c50e688 | 29 | _xy.x = _xy.x - 1; |
LBY | 0:36c99c50e688 | 30 | }else if(pad.get_direction() == E){ |
LBY | 0:36c99c50e688 | 31 | _xy.x = _xy.x + 1; |
LBY | 0:36c99c50e688 | 32 | } |
LBY | 0:36c99c50e688 | 33 | } |
LBY | 0:36c99c50e688 | 34 | |
LBY | 0:36c99c50e688 | 35 | void plane::display(N5110 &lcd){ |
LBY | 0:36c99c50e688 | 36 | unsigned int width = _width; |
LBY | 0:36c99c50e688 | 37 | unsigned int height = _height; |
LBY | 0:36c99c50e688 | 38 | Bitmap p(data, height, width); |
LBY | 0:36c99c50e688 | 39 | p.render(lcd, _xy.x, _xy.y); |
LBY | 0:36c99c50e688 | 40 | } |
LBY | 0:36c99c50e688 | 41 | |
LBY | 0:36c99c50e688 | 42 | xy plane::getxy(){return _xy;} |
LBY | 0:36c99c50e688 | 43 | |
LBY | 0:36c99c50e688 | 44 | int plane::getwidth(){return _width;} |
LBY | 0:36c99c50e688 | 45 | int plane::getheight(){return _height;} |