Li Ruofan 201199450
Dependencies: mbed Gamepad Joystick
UFO/UFO.cpp
- Committer:
- DannyLee
- Date:
- 2020-05-15
- Revision:
- 5:e3a9f0548922
- Parent:
- 3:cf9fead9c3f4
- Child:
- 6:cbd9e1f26a10
File content as of revision 5:e3a9f0548922:
#include "UFO.h" UFO::UFO() { } 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) { //different ufo shapes for each level int UFO[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 }; 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 } int UFO::getBlood(){ return _blood; } void UFO::setSpeed(int speed){ _speed = speed; } int UFO::getSpeed(){ return _speed; }