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
Rocket/Rocket.cpp
- Committer:
- el17ph
- Date:
- 2019-05-12
- Revision:
- 1:679d7ada8de7
- Parent:
- 0:8fb740fa6356
File content as of revision 1:679d7ada8de7:
#include "Rocket.h" Rocket::Rocket() { } Rocket::~Rocket() { } //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); } //update its y position base on speed void Rocket::update() { m_y += m_speed; } //get the x and y value for rocket 1 Vector2D Rocket::get_pos1() { Vector2D p1 = {m_x1,m_y}; return p1; } //get the x and y value for rocket 2 Vector2D Rocket::get_pos2() { Vector2D p2 = {m_x2,m_y}; return p2; }