Li Ruofan 201199450
Dependencies: mbed Gamepad Joystick
UFO/UFO.cpp@6:cbd9e1f26a10, 2020-05-15 (annotated)
- Committer:
- DannyLee
- Date:
- Fri May 15 21:16:14 2020 +0000
- Revision:
- 6:cbd9e1f26a10
- Parent:
- 5:e3a9f0548922
- Child:
- 8:b4a2954dd74f
still debuging
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
DannyLee | 3:cf9fead9c3f4 | 1 | #include "UFO.h" |
DannyLee | 3:cf9fead9c3f4 | 2 | |
DannyLee | 5:e3a9f0548922 | 3 | UFO::UFO() |
DannyLee | 3:cf9fead9c3f4 | 4 | { |
DannyLee | 5:e3a9f0548922 | 5 | |
DannyLee | 3:cf9fead9c3f4 | 6 | } |
DannyLee | 3:cf9fead9c3f4 | 7 | UFO::~UFO() |
DannyLee | 3:cf9fead9c3f4 | 8 | { |
DannyLee | 3:cf9fead9c3f4 | 9 | |
DannyLee | 3:cf9fead9c3f4 | 10 | } |
DannyLee | 3:cf9fead9c3f4 | 11 | |
DannyLee | 6:cbd9e1f26a10 | 12 | void UFO::init(int width,int height, int speed){ |
DannyLee | 3:cf9fead9c3f4 | 13 | |
DannyLee | 6:cbd9e1f26a10 | 14 | _width = width; |
DannyLee | 6:cbd9e1f26a10 | 15 | _height = height; // define the size of UFO |
DannyLee | 6:cbd9e1f26a10 | 16 | _x = rand() % (84- _width); |
DannyLee | 6:cbd9e1f26a10 | 17 | _y = 0; |
DannyLee | 6:cbd9e1f26a10 | 18 | _speed=2; |
DannyLee | 3:cf9fead9c3f4 | 19 | } |
DannyLee | 3:cf9fead9c3f4 | 20 | |
DannyLee | 3:cf9fead9c3f4 | 21 | Vector2D UFO::getPos() |
DannyLee | 3:cf9fead9c3f4 | 22 | { |
DannyLee | 3:cf9fead9c3f4 | 23 | Vector2D p = {_x,_y}; |
DannyLee | 3:cf9fead9c3f4 | 24 | return p; |
DannyLee | 3:cf9fead9c3f4 | 25 | } |
DannyLee | 3:cf9fead9c3f4 | 26 | void UFO::update() |
DannyLee | 3:cf9fead9c3f4 | 27 | { |
DannyLee | 3:cf9fead9c3f4 | 28 | _y+=_speed; |
DannyLee | 3:cf9fead9c3f4 | 29 | } |
DannyLee | 3:cf9fead9c3f4 | 30 | void UFO::setBlood(int get_shot){ |
DannyLee | 6:cbd9e1f26a10 | 31 | _blood -= get_shot; |
DannyLee | 3:cf9fead9c3f4 | 32 | } |
DannyLee | 5:e3a9f0548922 | 33 | void UFO::draw(N5110 &lcd) |
DannyLee | 3:cf9fead9c3f4 | 34 | { |
DannyLee | 3:cf9fead9c3f4 | 35 | //different ufo shapes for each level |
DannyLee | 5:e3a9f0548922 | 36 | int UFO[5][12] = { |
DannyLee | 3:cf9fead9c3f4 | 37 | 1,1,1,1,1,1,1,1,1,1,1,1 , |
DannyLee | 3:cf9fead9c3f4 | 38 | 1,1,1,0,0,0,0,0,0,1,1,1 , |
DannyLee | 3:cf9fead9c3f4 | 39 | 1,1,1,0,0,0,0,0,0,1,1,1 , |
DannyLee | 3:cf9fead9c3f4 | 40 | 1,1,1,0,0,0,0,0,0,1,1,1 , |
DannyLee | 3:cf9fead9c3f4 | 41 | 1,1,1,1,1,1,1,1,1,1,1,1 }; |
DannyLee | 5:e3a9f0548922 | 42 | |
DannyLee | 6:cbd9e1f26a10 | 43 | Bitmap sprite(enemy, _width, _height); |
DannyLee | 6:cbd9e1f26a10 | 44 | sprite.render(lcd, _x, _y); |
DannyLee | 3:cf9fead9c3f4 | 45 | } |
DannyLee | 3:cf9fead9c3f4 | 46 | int UFO::getBlood(){ |
DannyLee | 3:cf9fead9c3f4 | 47 | return _blood; |
DannyLee | 3:cf9fead9c3f4 | 48 | } |
DannyLee | 3:cf9fead9c3f4 | 49 | void UFO::setSpeed(int speed){ |
DannyLee | 3:cf9fead9c3f4 | 50 | _speed = speed; |
DannyLee | 3:cf9fead9c3f4 | 51 | } |
DannyLee | 3:cf9fead9c3f4 | 52 | int UFO::getSpeed(){ |
DannyLee | 3:cf9fead9c3f4 | 53 | return _speed; |
DannyLee | 3:cf9fead9c3f4 | 54 | } |