ELEC2645 (2018/19) / Mbed 2 deprecated el17ph

Dependencies:   mbed

Rocket/Rocket.cpp

Committer:
el17ph
Date:
2019-05-11
Revision:
0:8fb740fa6356
Child:
1:679d7ada8de7

File content as of revision 0:8fb740fa6356:

#include "Rocket.h"


/** Rocket Class
* @brief Set and update the value of rocket in the game
* @author Pengxi Huang
* @date may,2019
*/

/** Constructor */
Rocket::Rocket()
{
    
}
/** Destructor */
Rocket::~Rocket()
{
    
}

/** Inital the postion
 * @param the X and y of the class(int)
 */
//init the postion of the rocket
void Rocket::init()
{
    m_x1 = 3 + rand() % 27;//rocket1 appear randmoly in left paly window
    m_x2 = 30 + rand() % 27;//rocket2 appear randmoly in right paly window
    m_y = 3;//both rocket have same starting height 

    m_speed = 4;//fixed flying speed for reocket
    srand(time(NULL));
}

//draw the rocket base on their position
void Rocket::draw(N5110 &lcd)
{
    lcd.drawRect(m_x1 - 1, m_y - 2,3,4, FILL_BLACK);//draw rocket 1
    lcd.setPixel(m_x1 - 2,m_y - 2,true);
    lcd.setPixel(m_x1 + 2,m_y - 2,true);
    lcd.setPixel(m_x1 ,m_y + 2,true);
    
    lcd.drawRect(m_x2 - 1, m_y - 2,3,4, FILL_BLACK);//draw rocket 2
    lcd.setPixel(m_x2 - 2,m_y - 2,true);
    lcd.setPixel(m_x2 + 2,m_y - 2,true);
    lcd.setPixel(m_x2 ,m_y + 2,true);
}


/** Set the new position
 * @param the value of the new position(Vector2D)
 */
//update its y position base on speed
void Rocket::update()
{
    m_y += m_speed;
}

/** Get the position of rocket 1
 * @return the current poition in 2d
 */
//get the x and y value for rocket 1
Vector2D Rocket::get_pos1()
{
    Vector2D p1 = {m_x1,m_y};
    return p1;
}

/** Get the position of rocket 2
 * @return the current poition in 2d
 */
//get the x and y value for rocket 2
Vector2D Rocket::get_pos2()
{
    Vector2D p2 = {m_x2,m_y};
    return p2;
}