Li Ruofan 201199450
Dependencies: mbed Gamepad Joystick
Diff: UFO/UFO.cpp
- Revision:
- 6:cbd9e1f26a10
- Parent:
- 5:e3a9f0548922
- Child:
- 8:b4a2954dd74f
--- a/UFO/UFO.cpp Fri May 15 19:57:40 2020 +0000 +++ b/UFO/UFO.cpp Fri May 15 21:16:14 2020 +0000 @@ -9,16 +9,13 @@ } -void UFO::init(int sizeX,int sizeY, int speed){ +void UFO::init(int width,int height, int speed){ - _sizeX = sizeX; - _sizeY = sizeY; // define the size of UFO - _x = rand() % (WIDTH - _sizeX); - _y = HEIGHT - 1; //UFO drops from top to bottom - _velocity.x = 0; - _velocity.y = speed; // define the initial value of velocity - srand(time(NULL)); // randomly define the the initial position on the top - + _width = width; + _height = height; // define the size of UFO + _x = rand() % (84- _width); + _y = 0; + _speed=2; } Vector2D UFO::getPos() @@ -31,7 +28,7 @@ _y+=_speed; } void UFO::setBlood(int get_shot){ - _blood -= get_shot; //One drop of blood per shot + _blood -= get_shot; } void UFO::draw(N5110 &lcd) { @@ -43,10 +40,8 @@ 1,1,1,0,0,0,0,0,0,1,1,1 , 1,1,1,1,1,1,1,1,1,1,1,1 }; - lcd.drawSprite(lcd, _x,_y,_height,_width,(int)Spaceship);// Specify rows and columns in sprite - // We can render the bitmap wherever we want on the screen - sprite.render(lcd, _x, _y); // x and y locations for rendering - + Bitmap sprite(enemy, _width, _height); + sprite.render(lcd, _x, _y); } int UFO::getBlood(){ return _blood;