ELEC2645 (2018/19) / Mbed 2 deprecated ml16c5l

Dependencies:   mbed

Committer:
ml16c5l
Date:
Sun Apr 28 21:32:06 2019 +0000
Revision:
9:192ad897ec95
Parent:
6:0bc6813fe434
change wall

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ml16c5l 6:0bc6813fe434 1 /*
ml16c5l 6:0bc6813fe434 2 ELEC2645 Embedded Systems Project
ml16c5l 6:0bc6813fe434 3 School of Electronic & Electrical Engineering
ml16c5l 6:0bc6813fe434 4 University of Leeds
ml16c5l 6:0bc6813fe434 5 Name: Caiwenjing Liu
ml16c5l 6:0bc6813fe434 6 Username:ml16c5l
ml16c5l 6:0bc6813fe434 7 Student ID Number: 201165261
ml16c5l 6:0bc6813fe434 8 Date: 11/04/2019
ml16c5l 6:0bc6813fe434 9 */
ml16c5l 6:0bc6813fe434 10
ml16c5l 6:0bc6813fe434 11 #include "Copter.h"
ml16c5l 6:0bc6813fe434 12
ml16c5l 6:0bc6813fe434 13
ml16c5l 9:192ad897ec95 14
ml16c5l 6:0bc6813fe434 15 Copter::Copter()
ml16c5l 6:0bc6813fe434 16 {
ml16c5l 6:0bc6813fe434 17
ml16c5l 6:0bc6813fe434 18 }
ml16c5l 6:0bc6813fe434 19
ml16c5l 6:0bc6813fe434 20 Copter::~Copter()
ml16c5l 6:0bc6813fe434 21 {
ml16c5l 6:0bc6813fe434 22
ml16c5l 6:0bc6813fe434 23 }
ml16c5l 6:0bc6813fe434 24 void Copter::init(int x,int height,int width )
ml16c5l 6:0bc6813fe434 25 {
ml16c5l 9:192ad897ec95 26
ml16c5l 9:192ad897ec95 27 _x = 15 ;
ml16c5l 9:192ad897ec95 28 _y = 10;
ml16c5l 6:0bc6813fe434 29 _height = height;
ml16c5l 6:0bc6813fe434 30 _width = width;
ml16c5l 9:192ad897ec95 31 _speed = 1;
ml16c5l 9:192ad897ec95 32 _score = 0;
ml16c5l 6:0bc6813fe434 33
ml16c5l 9:192ad897ec95 34 srand(time(NULL));
ml16c5l 6:0bc6813fe434 35 }
ml16c5l 6:0bc6813fe434 36
ml16c5l 6:0bc6813fe434 37 void Copter::draw(N5110 &lcd)
ml16c5l 6:0bc6813fe434 38 {
ml16c5l 9:192ad897ec95 39
ml16c5l 9:192ad897ec95 40 lcd.drawLine(_x,_y,_x+1,_y,1);
ml16c5l 9:192ad897ec95 41 lcd.drawLine(_x+2,_y+1,_x+3,_y+1,1);
ml16c5l 9:192ad897ec95 42 lcd.drawLine(_x+4,_y+2,_x+6,_y+2,1);
ml16c5l 9:192ad897ec95 43 lcd.drawLine(_x+6,_y+3,_x+8,_y+3,1);
ml16c5l 9:192ad897ec95 44 lcd.drawLine(_x+9,_y+4,_x+10,_y+4,1);
ml16c5l 9:192ad897ec95 45 lcd.drawLine(_x+11,_y+5,_x+12,_y+5,1);
ml16c5l 9:192ad897ec95 46 lcd.drawLine(_x+6,_y+4,_x+6,_y+4,1);//fan
ml16c5l 9:192ad897ec95 47
ml16c5l 9:192ad897ec95 48 lcd.drawLine(_x+5,_y+5,_x+7,_y+5,1);
ml16c5l 9:192ad897ec95 49 lcd.drawLine(_x+4,_y+6,_x+8,_y+6,1);
ml16c5l 9:192ad897ec95 50 lcd.drawLine(_x,_y+6,_x,_y+6,1);
ml16c5l 9:192ad897ec95 51 lcd.drawLine(_x,_y+7,_x+6,_y+7,1);
ml16c5l 9:192ad897ec95 52 lcd.drawLine(_x+8,_y+7,_x+9,_y+7,1);
ml16c5l 9:192ad897ec95 53 lcd.drawLine(_x+2,_y+8,_x+6,_y+8,1);
ml16c5l 9:192ad897ec95 54 lcd.drawLine(_x+8,_y+8,_x+9,_y+8,1);
ml16c5l 9:192ad897ec95 55 lcd.drawLine(_x+4,_y+9,_x+8,_y+9,1);
ml16c5l 9:192ad897ec95 56 lcd.drawLine(_x+5,_y+10,_x+7,_y+10,1);
ml16c5l 9:192ad897ec95 57 lcd.drawLine(_x+6,_y+11,_x+6,_y+11,1);
ml16c5l 9:192ad897ec95 58 lcd.drawLine(_x+5,_y+12,_x+7,_y+12,1);
ml16c5l 9:192ad897ec95 59
ml16c5l 9:192ad897ec95 60
ml16c5l 9:192ad897ec95 61
ml16c5l 6:0bc6813fe434 62 }
ml16c5l 6:0bc6813fe434 63
ml16c5l 6:0bc6813fe434 64 void Copter::update( Direction d,float mag)
ml16c5l 6:0bc6813fe434 65 {
ml16c5l 6:0bc6813fe434 66 _speed = int(mag*6.0f);
ml16c5l 9:192ad897ec95 67
ml16c5l 6:0bc6813fe434 68 if (d == N) {
ml16c5l 6:0bc6813fe434 69 _y-=_speed;
ml16c5l 6:0bc6813fe434 70 } else if (d == S) {
ml16c5l 6:0bc6813fe434 71 _y+=_speed;
ml16c5l 6:0bc6813fe434 72 }
ml16c5l 6:0bc6813fe434 73
ml16c5l 9:192ad897ec95 74 if (_y < 1) {
ml16c5l 6:0bc6813fe434 75 _y = 1;
ml16c5l 6:0bc6813fe434 76 }
ml16c5l 6:0bc6813fe434 77 if (_y > HEIGHT - _height - 1) {
ml16c5l 6:0bc6813fe434 78 _y = HEIGHT - _height - 1;
ml16c5l 6:0bc6813fe434 79 }
ml16c5l 6:0bc6813fe434 80 }
ml16c5l 9:192ad897ec95 81
ml16c5l 6:0bc6813fe434 82
ml16c5l 6:0bc6813fe434 83 void Copter::add_score()
ml16c5l 6:0bc6813fe434 84 {
ml16c5l 6:0bc6813fe434 85 _score++;
ml16c5l 6:0bc6813fe434 86 }
ml16c5l 6:0bc6813fe434 87 int Copter::get_score()
ml16c5l 6:0bc6813fe434 88 {
ml16c5l 6:0bc6813fe434 89 return _score;
ml16c5l 6:0bc6813fe434 90 }
ml16c5l 6:0bc6813fe434 91
ml16c5l 9:192ad897ec95 92
ml16c5l 9:192ad897ec95 93
ml16c5l 9:192ad897ec95 94 Vector2D Copter::get_pos() {
ml16c5l 6:0bc6813fe434 95 Vector2D p = {_x,_y};
ml16c5l 9:192ad897ec95 96 return p;
ml16c5l 9:192ad897ec95 97 }
ml16c5l 9:192ad897ec95 98