Li Ruofan 201199450

Dependencies:   mbed Gamepad Joystick

Committer:
DannyLee
Date:
Fri May 15 19:57:40 2020 +0000
Revision:
5:e3a9f0548922
Parent:
3:cf9fead9c3f4
Child:
6:cbd9e1f26a10
need to debug

Who changed what in which revision?

UserRevisionLine numberNew 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 3:cf9fead9c3f4 12 void UFO::init(int sizeX,int sizeY, int speed){
DannyLee 3:cf9fead9c3f4 13
DannyLee 3:cf9fead9c3f4 14 _sizeX = sizeX;
DannyLee 3:cf9fead9c3f4 15 _sizeY = sizeY; // define the size of UFO
DannyLee 3:cf9fead9c3f4 16 _x = rand() % (WIDTH - _sizeX);
DannyLee 3:cf9fead9c3f4 17 _y = HEIGHT - 1; //UFO drops from top to bottom
DannyLee 3:cf9fead9c3f4 18 _velocity.x = 0;
DannyLee 3:cf9fead9c3f4 19 _velocity.y = speed; // define the initial value of velocity
DannyLee 3:cf9fead9c3f4 20 srand(time(NULL)); // randomly define the the initial position on the top
DannyLee 3:cf9fead9c3f4 21
DannyLee 3:cf9fead9c3f4 22 }
DannyLee 3:cf9fead9c3f4 23
DannyLee 3:cf9fead9c3f4 24 Vector2D UFO::getPos()
DannyLee 3:cf9fead9c3f4 25 {
DannyLee 3:cf9fead9c3f4 26 Vector2D p = {_x,_y};
DannyLee 3:cf9fead9c3f4 27 return p;
DannyLee 3:cf9fead9c3f4 28 }
DannyLee 3:cf9fead9c3f4 29 void UFO::update()
DannyLee 3:cf9fead9c3f4 30 {
DannyLee 3:cf9fead9c3f4 31 _y+=_speed;
DannyLee 3:cf9fead9c3f4 32 }
DannyLee 3:cf9fead9c3f4 33 void UFO::setBlood(int get_shot){
DannyLee 3:cf9fead9c3f4 34 _blood -= get_shot; //One drop of blood per shot
DannyLee 3:cf9fead9c3f4 35 }
DannyLee 5:e3a9f0548922 36 void UFO::draw(N5110 &lcd)
DannyLee 3:cf9fead9c3f4 37 {
DannyLee 3:cf9fead9c3f4 38 //different ufo shapes for each level
DannyLee 5:e3a9f0548922 39 int UFO[5][12] = {
DannyLee 3:cf9fead9c3f4 40 1,1,1,1,1,1,1,1,1,1,1,1 ,
DannyLee 3:cf9fead9c3f4 41 1,1,1,0,0,0,0,0,0,1,1,1 ,
DannyLee 3:cf9fead9c3f4 42 1,1,1,0,0,0,0,0,0,1,1,1 ,
DannyLee 3:cf9fead9c3f4 43 1,1,1,0,0,0,0,0,0,1,1,1 ,
DannyLee 3:cf9fead9c3f4 44 1,1,1,1,1,1,1,1,1,1,1,1 };
DannyLee 5:e3a9f0548922 45
DannyLee 3:cf9fead9c3f4 46 lcd.drawSprite(lcd, _x,_y,_height,_width,(int)Spaceship);// Specify rows and columns in sprite
DannyLee 3:cf9fead9c3f4 47 // We can render the bitmap wherever we want on the screen
DannyLee 3:cf9fead9c3f4 48 sprite.render(lcd, _x, _y); // x and y locations for rendering
DannyLee 5:e3a9f0548922 49
DannyLee 3:cf9fead9c3f4 50 }
DannyLee 3:cf9fead9c3f4 51 int UFO::getBlood(){
DannyLee 3:cf9fead9c3f4 52 return _blood;
DannyLee 3:cf9fead9c3f4 53 }
DannyLee 3:cf9fead9c3f4 54 void UFO::setSpeed(int speed){
DannyLee 3:cf9fead9c3f4 55 _speed = speed;
DannyLee 3:cf9fead9c3f4 56 }
DannyLee 3:cf9fead9c3f4 57 int UFO::getSpeed(){
DannyLee 3:cf9fead9c3f4 58 return _speed;
DannyLee 3:cf9fead9c3f4 59 }