Li Ruofan 201199450

Dependencies:   mbed Gamepad Joystick

Revision:
3:cf9fead9c3f4
Child:
5:e3a9f0548922
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/UFO/UFO.cpp	Thu May 14 13:12:28 2020 +0000
@@ -0,0 +1,76 @@
+#include "UFO.h"
+
+UFO::UFO(int level)
+{
+    //The blood of UFO changes with the difficulty of value
+    //when level=0, blood=1; when level=1, blood=2
+    if(level == 0)
+        _blood = 1;
+    else if(level == 1)
+        _blood = 2;
+}
+UFO::~UFO()
+{
+    
+}
+
+void UFO::init(int sizeX,int sizeY, 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
+
+}
+
+Vector2D UFO::getPos()
+{
+    Vector2D p = {_x,_y};
+    return p;
+}
+void UFO::update()
+{
+    _y+=_speed;
+}
+void UFO::setBlood(int get_shot){ 
+    _blood -= get_shot; //One drop of blood per shot
+}
+void UFO::draw(N5110 &lcd,int level)
+{
+    //different ufo shapes for each level
+    int UFOEasy[5][12] =   {
+     1,1,1,1,1,1,1,1,1,1,1,1 ,
+     1,1,1,0,0,0,0,0,0,1,1,1 ,
+     1,1,1,0,0,0,0,0,0,1,1,1 ,
+     1,1,1,0,0,0,0,0,0,1,1,1 ,
+     1,1,1,1,1,1,1,1,1,1,1,1 };
+     int UFOHard[5][10] =   {
+     0,1,1,1,1,1,1,1,1,0 ,
+     1,1,0,0,1,1,0,0,1,1 ,
+     0,1,1,1,1,1,1,1,1,0 ,
+     1,1,0,0,1,1,0,0,1,1 ,
+     0,1,1,1,1,1,1,1,1,0 };
+     
+     if(level == 0){
+        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
+     }else if(level == 1){
+        Bitmap sprite(UFONormal, _sizeY, _sizeX); // 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
+     }
+    
+}
+int UFO::getBlood(){
+    return _blood;
+}
+void UFO::setSpeed(int speed){
+    _speed = speed;
+}
+int UFO::getSpeed(){
+    return _speed;
+}
\ No newline at end of file