Li Ruofan 201199450

Dependencies:   mbed Gamepad Joystick

Committer:
DannyLee
Date:
Thu May 14 13:12:28 2020 +0000
Revision:
3:cf9fead9c3f4
Child:
5:e3a9f0548922
aaa

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DannyLee 3:cf9fead9c3f4 1 #include "UFO.h"
DannyLee 3:cf9fead9c3f4 2
DannyLee 3:cf9fead9c3f4 3 UFO::UFO(int level)
DannyLee 3:cf9fead9c3f4 4 {
DannyLee 3:cf9fead9c3f4 5 //The blood of UFO changes with the difficulty of value
DannyLee 3:cf9fead9c3f4 6 //when level=0, blood=1; when level=1, blood=2
DannyLee 3:cf9fead9c3f4 7 if(level == 0)
DannyLee 3:cf9fead9c3f4 8 _blood = 1;
DannyLee 3:cf9fead9c3f4 9 else if(level == 1)
DannyLee 3:cf9fead9c3f4 10 _blood = 2;
DannyLee 3:cf9fead9c3f4 11 }
DannyLee 3:cf9fead9c3f4 12 UFO::~UFO()
DannyLee 3:cf9fead9c3f4 13 {
DannyLee 3:cf9fead9c3f4 14
DannyLee 3:cf9fead9c3f4 15 }
DannyLee 3:cf9fead9c3f4 16
DannyLee 3:cf9fead9c3f4 17 void UFO::init(int sizeX,int sizeY, int speed){
DannyLee 3:cf9fead9c3f4 18
DannyLee 3:cf9fead9c3f4 19 _sizeX = sizeX;
DannyLee 3:cf9fead9c3f4 20 _sizeY = sizeY; // define the size of UFO
DannyLee 3:cf9fead9c3f4 21 _x = rand() % (WIDTH - _sizeX);
DannyLee 3:cf9fead9c3f4 22 _y = HEIGHT - 1; //UFO drops from top to bottom
DannyLee 3:cf9fead9c3f4 23 _velocity.x = 0;
DannyLee 3:cf9fead9c3f4 24 _velocity.y = speed; // define the initial value of velocity
DannyLee 3:cf9fead9c3f4 25 srand(time(NULL)); // randomly define the the initial position on the top
DannyLee 3:cf9fead9c3f4 26
DannyLee 3:cf9fead9c3f4 27 }
DannyLee 3:cf9fead9c3f4 28
DannyLee 3:cf9fead9c3f4 29 Vector2D UFO::getPos()
DannyLee 3:cf9fead9c3f4 30 {
DannyLee 3:cf9fead9c3f4 31 Vector2D p = {_x,_y};
DannyLee 3:cf9fead9c3f4 32 return p;
DannyLee 3:cf9fead9c3f4 33 }
DannyLee 3:cf9fead9c3f4 34 void UFO::update()
DannyLee 3:cf9fead9c3f4 35 {
DannyLee 3:cf9fead9c3f4 36 _y+=_speed;
DannyLee 3:cf9fead9c3f4 37 }
DannyLee 3:cf9fead9c3f4 38 void UFO::setBlood(int get_shot){
DannyLee 3:cf9fead9c3f4 39 _blood -= get_shot; //One drop of blood per shot
DannyLee 3:cf9fead9c3f4 40 }
DannyLee 3:cf9fead9c3f4 41 void UFO::draw(N5110 &lcd,int level)
DannyLee 3:cf9fead9c3f4 42 {
DannyLee 3:cf9fead9c3f4 43 //different ufo shapes for each level
DannyLee 3:cf9fead9c3f4 44 int UFOEasy[5][12] = {
DannyLee 3:cf9fead9c3f4 45 1,1,1,1,1,1,1,1,1,1,1,1 ,
DannyLee 3:cf9fead9c3f4 46 1,1,1,0,0,0,0,0,0,1,1,1 ,
DannyLee 3:cf9fead9c3f4 47 1,1,1,0,0,0,0,0,0,1,1,1 ,
DannyLee 3:cf9fead9c3f4 48 1,1,1,0,0,0,0,0,0,1,1,1 ,
DannyLee 3:cf9fead9c3f4 49 1,1,1,1,1,1,1,1,1,1,1,1 };
DannyLee 3:cf9fead9c3f4 50 int UFOHard[5][10] = {
DannyLee 3:cf9fead9c3f4 51 0,1,1,1,1,1,1,1,1,0 ,
DannyLee 3:cf9fead9c3f4 52 1,1,0,0,1,1,0,0,1,1 ,
DannyLee 3:cf9fead9c3f4 53 0,1,1,1,1,1,1,1,1,0 ,
DannyLee 3:cf9fead9c3f4 54 1,1,0,0,1,1,0,0,1,1 ,
DannyLee 3:cf9fead9c3f4 55 0,1,1,1,1,1,1,1,1,0 };
DannyLee 3:cf9fead9c3f4 56
DannyLee 3:cf9fead9c3f4 57 if(level == 0){
DannyLee 3:cf9fead9c3f4 58 lcd.drawSprite(lcd, _x,_y,_height,_width,(int)Spaceship);// Specify rows and columns in sprite
DannyLee 3:cf9fead9c3f4 59 // We can render the bitmap wherever we want on the screen
DannyLee 3:cf9fead9c3f4 60 sprite.render(lcd, _x, _y); // x and y locations for rendering
DannyLee 3:cf9fead9c3f4 61 }else if(level == 1){
DannyLee 3:cf9fead9c3f4 62 Bitmap sprite(UFONormal, _sizeY, _sizeX); // Specify rows and columns in sprite
DannyLee 3:cf9fead9c3f4 63 // We can render the bitmap wherever we want on the screen
DannyLee 3:cf9fead9c3f4 64 sprite.render(lcd, _x, _y); // x and y locations for rendering
DannyLee 3:cf9fead9c3f4 65 }
DannyLee 3:cf9fead9c3f4 66
DannyLee 3:cf9fead9c3f4 67 }
DannyLee 3:cf9fead9c3f4 68 int UFO::getBlood(){
DannyLee 3:cf9fead9c3f4 69 return _blood;
DannyLee 3:cf9fead9c3f4 70 }
DannyLee 3:cf9fead9c3f4 71 void UFO::setSpeed(int speed){
DannyLee 3:cf9fead9c3f4 72 _speed = speed;
DannyLee 3:cf9fead9c3f4 73 }
DannyLee 3:cf9fead9c3f4 74 int UFO::getSpeed(){
DannyLee 3:cf9fead9c3f4 75 return _speed;
DannyLee 3:cf9fead9c3f4 76 }