ELEC2645 (2018/19) / Mbed 2 deprecated el17ph

Dependencies:   mbed

Committer:
el17ph
Date:
Sun May 12 13:43:27 2019 +0000
Revision:
1:679d7ada8de7
Parent:
0:8fb740fa6356
el17ph

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::Rocket()
el17ph 0:8fb740fa6356 5 {
el17ph 0:8fb740fa6356 6
el17ph 0:8fb740fa6356 7 }
el17ph 1:679d7ada8de7 8
el17ph 0:8fb740fa6356 9 Rocket::~Rocket()
el17ph 0:8fb740fa6356 10 {
el17ph 0:8fb740fa6356 11
el17ph 0:8fb740fa6356 12 }
el17ph 0:8fb740fa6356 13
el17ph 1:679d7ada8de7 14
el17ph 0:8fb740fa6356 15 //init the postion of the rocket
el17ph 0:8fb740fa6356 16 void Rocket::init()
el17ph 0:8fb740fa6356 17 {
el17ph 0:8fb740fa6356 18 m_x1 = 3 + rand() % 27;//rocket1 appear randmoly in left paly window
el17ph 0:8fb740fa6356 19 m_x2 = 30 + rand() % 27;//rocket2 appear randmoly in right paly window
el17ph 0:8fb740fa6356 20 m_y = 3;//both rocket have same starting height
el17ph 0:8fb740fa6356 21
el17ph 0:8fb740fa6356 22 m_speed = 4;//fixed flying speed for reocket
el17ph 0:8fb740fa6356 23 srand(time(NULL));
el17ph 0:8fb740fa6356 24 }
el17ph 0:8fb740fa6356 25
el17ph 0:8fb740fa6356 26 //draw the rocket base on their position
el17ph 0:8fb740fa6356 27 void Rocket::draw(N5110 &lcd)
el17ph 0:8fb740fa6356 28 {
el17ph 0:8fb740fa6356 29 lcd.drawRect(m_x1 - 1, m_y - 2,3,4, FILL_BLACK);//draw rocket 1
el17ph 0:8fb740fa6356 30 lcd.setPixel(m_x1 - 2,m_y - 2,true);
el17ph 0:8fb740fa6356 31 lcd.setPixel(m_x1 + 2,m_y - 2,true);
el17ph 0:8fb740fa6356 32 lcd.setPixel(m_x1 ,m_y + 2,true);
el17ph 0:8fb740fa6356 33
el17ph 0:8fb740fa6356 34 lcd.drawRect(m_x2 - 1, m_y - 2,3,4, FILL_BLACK);//draw rocket 2
el17ph 0:8fb740fa6356 35 lcd.setPixel(m_x2 - 2,m_y - 2,true);
el17ph 0:8fb740fa6356 36 lcd.setPixel(m_x2 + 2,m_y - 2,true);
el17ph 0:8fb740fa6356 37 lcd.setPixel(m_x2 ,m_y + 2,true);
el17ph 0:8fb740fa6356 38 }
el17ph 0:8fb740fa6356 39
el17ph 0:8fb740fa6356 40
el17ph 1:679d7ada8de7 41
el17ph 0:8fb740fa6356 42 //update its y position base on speed
el17ph 0:8fb740fa6356 43 void Rocket::update()
el17ph 0:8fb740fa6356 44 {
el17ph 0:8fb740fa6356 45 m_y += m_speed;
el17ph 0:8fb740fa6356 46 }
el17ph 0:8fb740fa6356 47
el17ph 1:679d7ada8de7 48
el17ph 0:8fb740fa6356 49 //get the x and y value for rocket 1
el17ph 0:8fb740fa6356 50 Vector2D Rocket::get_pos1()
el17ph 0:8fb740fa6356 51 {
el17ph 0:8fb740fa6356 52 Vector2D p1 = {m_x1,m_y};
el17ph 0:8fb740fa6356 53 return p1;
el17ph 0:8fb740fa6356 54 }
el17ph 0:8fb740fa6356 55
el17ph 1:679d7ada8de7 56
el17ph 0:8fb740fa6356 57 //get the x and y value for rocket 2
el17ph 0:8fb740fa6356 58 Vector2D Rocket::get_pos2()
el17ph 0:8fb740fa6356 59 {
el17ph 0:8fb740fa6356 60 Vector2D p2 = {m_x2,m_y};
el17ph 0:8fb740fa6356 61 return p2;
el17ph 0:8fb740fa6356 62 }