Yudong Xiao / Mbed OS pokemon

Dependencies:   Tone

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Rocket.cpp Source File

Rocket.cpp

00001 #include "Rocket.h"
00002 
00003 void Rocket::init(int x, int y, int size, int speed){
00004     _x = x;
00005     _y = y;
00006     _size = size;
00007     
00008     _velocity.x = speed;
00009     _velocity.y = speed;
00010 }
00011 
00012 void Rocket::draw(N5110 &lcd){
00013     lcd.drawRect(_x,_y,_size,_size,FILL_BLACK);
00014 }
00015 
00016 void Rocket::update(Position2D pokeball_pos){
00017     if (
00018         (_x <= pokeball_pos.x) && (_y <= pokeball_pos.y) )
00019         {
00020             _x += _velocity.x;
00021             _y += _velocity.y;}
00022     if (
00023         (_x > pokeball_pos.x) && (_y < pokeball_pos.y) )
00024         {
00025         _x -= _velocity.x;
00026         _y += _velocity.y;}
00027     if (
00028         (_x > pokeball_pos.x) && (_y > pokeball_pos.y) )
00029         {
00030         _x -= _velocity.x;
00031         _y -= _velocity.y;}
00032     if (
00033         (_x < pokeball_pos.x) && (_y > pokeball_pos.y) )
00034         {
00035         _x += _velocity.x;
00036         _y -= _velocity.y;}      
00037             
00038     if (_y < 1) _y = 1;
00039     if (_x < 1) _x = 1;
00040     if (_x > WIDTH - 1) _x = WIDTH - 1;
00041     if (_y > HEIGHT - 1) _y = HEIGHT - 1;      
00042 }
00043 
00044 void Rocket::set_velocity(Position2D v){
00045     _velocity.x = v.x;
00046     _velocity.y = v.y;
00047 }
00048 
00049 void Rocket::set_pos(Position2D p){
00050     _x = p.x;
00051     _y = p.y;
00052 }
00053 
00054 void Rocket::rocket_crash(){
00055     _x = rand() % 84 ;
00056     _y = rand() % 48 ;
00057 }
00058 
00059 Position2D Rocket::get_velocity(){ return {_velocity.x,_velocity.y}; }
00060 
00061 
00062 int Rocket::get_size() { return _size; }
00063     
00064 
00065 Position2D Rocket::get_pos() { return {_x,_y}; }