ELEC2645 (2018/19) / Mbed 2 deprecated el17ph

Dependencies:   mbed

Committer:
el17ph
Date:
Sat May 11 14:58:43 2019 +0000
Revision:
0:8fb740fa6356
Child:
1:679d7ada8de7
last

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el17ph 0:8fb740fa6356 1 #include "Rocket.h"
el17ph 0:8fb740fa6356 2
el17ph 0:8fb740fa6356 3
el17ph 0:8fb740fa6356 4 /** Rocket Class
el17ph 0:8fb740fa6356 5 * @brief Set and update the value of rocket in the game
el17ph 0:8fb740fa6356 6 * @author Pengxi Huang
el17ph 0:8fb740fa6356 7 * @date may,2019
el17ph 0:8fb740fa6356 8 */
el17ph 0:8fb740fa6356 9
el17ph 0:8fb740fa6356 10 /** Constructor */
el17ph 0:8fb740fa6356 11 Rocket::Rocket()
el17ph 0:8fb740fa6356 12 {
el17ph 0:8fb740fa6356 13
el17ph 0:8fb740fa6356 14 }
el17ph 0:8fb740fa6356 15 /** Destructor */
el17ph 0:8fb740fa6356 16 Rocket::~Rocket()
el17ph 0:8fb740fa6356 17 {
el17ph 0:8fb740fa6356 18
el17ph 0:8fb740fa6356 19 }
el17ph 0:8fb740fa6356 20
el17ph 0:8fb740fa6356 21 /** Inital the postion
el17ph 0:8fb740fa6356 22 * @param the X and y of the class(int)
el17ph 0:8fb740fa6356 23 */
el17ph 0:8fb740fa6356 24 //init the postion of the rocket
el17ph 0:8fb740fa6356 25 void Rocket::init()
el17ph 0:8fb740fa6356 26 {
el17ph 0:8fb740fa6356 27 m_x1 = 3 + rand() % 27;//rocket1 appear randmoly in left paly window
el17ph 0:8fb740fa6356 28 m_x2 = 30 + rand() % 27;//rocket2 appear randmoly in right paly window
el17ph 0:8fb740fa6356 29 m_y = 3;//both rocket have same starting height
el17ph 0:8fb740fa6356 30
el17ph 0:8fb740fa6356 31 m_speed = 4;//fixed flying speed for reocket
el17ph 0:8fb740fa6356 32 srand(time(NULL));
el17ph 0:8fb740fa6356 33 }
el17ph 0:8fb740fa6356 34
el17ph 0:8fb740fa6356 35 //draw the rocket base on their position
el17ph 0:8fb740fa6356 36 void Rocket::draw(N5110 &lcd)
el17ph 0:8fb740fa6356 37 {
el17ph 0:8fb740fa6356 38 lcd.drawRect(m_x1 - 1, m_y - 2,3,4, FILL_BLACK);//draw rocket 1
el17ph 0:8fb740fa6356 39 lcd.setPixel(m_x1 - 2,m_y - 2,true);
el17ph 0:8fb740fa6356 40 lcd.setPixel(m_x1 + 2,m_y - 2,true);
el17ph 0:8fb740fa6356 41 lcd.setPixel(m_x1 ,m_y + 2,true);
el17ph 0:8fb740fa6356 42
el17ph 0:8fb740fa6356 43 lcd.drawRect(m_x2 - 1, m_y - 2,3,4, FILL_BLACK);//draw rocket 2
el17ph 0:8fb740fa6356 44 lcd.setPixel(m_x2 - 2,m_y - 2,true);
el17ph 0:8fb740fa6356 45 lcd.setPixel(m_x2 + 2,m_y - 2,true);
el17ph 0:8fb740fa6356 46 lcd.setPixel(m_x2 ,m_y + 2,true);
el17ph 0:8fb740fa6356 47 }
el17ph 0:8fb740fa6356 48
el17ph 0:8fb740fa6356 49
el17ph 0:8fb740fa6356 50 /** Set the new position
el17ph 0:8fb740fa6356 51 * @param the value of the new position(Vector2D)
el17ph 0:8fb740fa6356 52 */
el17ph 0:8fb740fa6356 53 //update its y position base on speed
el17ph 0:8fb740fa6356 54 void Rocket::update()
el17ph 0:8fb740fa6356 55 {
el17ph 0:8fb740fa6356 56 m_y += m_speed;
el17ph 0:8fb740fa6356 57 }
el17ph 0:8fb740fa6356 58
el17ph 0:8fb740fa6356 59 /** Get the position of rocket 1
el17ph 0:8fb740fa6356 60 * @return the current poition in 2d
el17ph 0:8fb740fa6356 61 */
el17ph 0:8fb740fa6356 62 //get the x and y value for rocket 1
el17ph 0:8fb740fa6356 63 Vector2D Rocket::get_pos1()
el17ph 0:8fb740fa6356 64 {
el17ph 0:8fb740fa6356 65 Vector2D p1 = {m_x1,m_y};
el17ph 0:8fb740fa6356 66 return p1;
el17ph 0:8fb740fa6356 67 }
el17ph 0:8fb740fa6356 68
el17ph 0:8fb740fa6356 69 /** Get the position of rocket 2
el17ph 0:8fb740fa6356 70 * @return the current poition in 2d
el17ph 0:8fb740fa6356 71 */
el17ph 0:8fb740fa6356 72 //get the x and y value for rocket 2
el17ph 0:8fb740fa6356 73 Vector2D Rocket::get_pos2()
el17ph 0:8fb740fa6356 74 {
el17ph 0:8fb740fa6356 75 Vector2D p2 = {m_x2,m_y};
el17ph 0:8fb740fa6356 76 return p2;
el17ph 0:8fb740fa6356 77 }