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: Copter/Copter.cpp
- Revision:
- 6:0bc6813fe434
- Parent:
- 3:5d860d0d589e
- Child:
- 9:192ad897ec95
--- a/Copter/Copter.cpp Thu Apr 11 09:44:12 2019 +0000
+++ b/Copter/Copter.cpp Thu Apr 11 12:51:57 2019 +0000
@@ -0,0 +1,97 @@
+/*
+ELEC2645 Embedded Systems Project
+School of Electronic & Electrical Engineering
+University of Leeds
+Name: Caiwenjing Liu
+Username:ml16c5l
+Student ID Number: 201165261
+Date: 11/04/2019
+*/
+
+#include "Copter.h"
+
+
+Copter::Copter()
+{
+
+}
+
+Copter::~Copter()
+{
+
+}
+void Copter::init(int x,int height,int width )
+{
+
+ _x = 15 ;
+ _y = 10;
+ _height = height;
+ _width = width;
+ _speed = 1;
+ _score = 0;
+
+ srand(time(NULL));
+}
+
+void Copter::draw(N5110 &lcd)
+{
+
+ lcd.drawLine(_x,_y,_x+1,_y,1);
+ lcd.drawLine(_x+2,_y+1,_x+3,_y+1,1);
+ lcd.drawLine(_x+4,_y+2,_x+6,_y+2,1);
+ lcd.drawLine(_x+6,_y+3,_x+8,_y+3,1);
+ lcd.drawLine(_x+9,_y+4,_x+10,_y+4,1);
+ lcd.drawLine(_x+11,_y+5,_x+12,_y+5,1);
+ lcd.drawLine(_x+6,_y+4,_x+6,_y+4,1);//fan
+
+ lcd.drawLine(_x+5,_y+5,_x+7,_y+5,1);
+ lcd.drawLine(_x+4,_y+6,_x+8,_y+6,1);
+ lcd.drawLine(_x,_y+6,_x,_y+6,1);
+ lcd.drawLine(_x,_y+7,_x+6,_y+7,1);
+ lcd.drawLine(_x+8,_y+7,_x+9,_y+7,1);
+ lcd.drawLine(_x+2,_y+8,_x+6,_y+8,1);
+ lcd.drawLine(_x+8,_y+8,_x+9,_y+8,1);
+ lcd.drawLine(_x+4,_y+9,_x+8,_y+9,1);
+ lcd.drawLine(_x+5,_y+10,_x+7,_y+10,1);
+ lcd.drawLine(_x+6,_y+11,_x+6,_y+11,1);
+ lcd.drawLine(_x+5,_y+12,_x+7,_y+12,1);
+
+
+
+}
+
+void Copter::update( Direction d,float mag)
+{
+ _speed = int(mag*6.0f);
+
+ if (d == N) {
+ _y-=_speed;
+ } else if (d == S) {
+ _y+=_speed;
+ }
+
+ if (_y < 1) {
+ _y = 1;
+ }
+ if (_y > HEIGHT - _height - 1) {
+ _y = HEIGHT - _height - 1;
+ }
+}
+
+
+void Copter::add_score()
+{
+ _score++;
+}
+
+
+int Copter::get_score()
+{
+ return _score;
+}
+
+Vector2D Copter::get_pos()
+{
+ Vector2D p = {_x,_y};
+ return p;
+}
\ No newline at end of file