Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Diff: Rocket/Rocket.cpp
- Revision:
- 0:8fb740fa6356
- Child:
- 1:679d7ada8de7
diff -r 000000000000 -r 8fb740fa6356 Rocket/Rocket.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Rocket/Rocket.cpp Sat May 11 14:58:43 2019 +0000 @@ -0,0 +1,77 @@ +#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; +}