ELEC2645 (2018/19) / Mbed 2 deprecated ml16c5l

Dependencies:   mbed

Committer:
ml16c5l
Date:
Thu Apr 11 12:51:57 2019 +0000
Revision:
6:0bc6813fe434
Parent:
3:5d860d0d589e
Child:
9:192ad897ec95
the copter of the CopterGame

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