ELEC2645 (2017/18) / Mbed 2 deprecated el17yw

Dependencies:   mbed

Committer:
RickYu
Date:
Mon Apr 23 22:36:11 2018 +0000
Revision:
15:0a55e0ac8421
Parent:
14:a4176da69b49
Child:
17:7acfc8a0c277
add score while not work.....

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RickYu 2:421fb0670c5c 1 #include "rect.h"
RickYu 2:421fb0670c5c 2
RickYu 2:421fb0670c5c 3 rect::rect()
RickYu 2:421fb0670c5c 4 {
RickYu 2:421fb0670c5c 5
RickYu 2:421fb0670c5c 6 }
RickYu 2:421fb0670c5c 7
RickYu 2:421fb0670c5c 8 rect::~rect()
RickYu 2:421fb0670c5c 9 {
RickYu 2:421fb0670c5c 10
RickYu 2:421fb0670c5c 11 }
RickYu 3:1a134243e2f0 12 void rect::init(int x,int y)
RickYu 2:421fb0670c5c 13 {
RickYu 7:1964f649676e 14 //set the rect move speed
RickYu 14:a4176da69b49 15 rect_speed = 0.5; // default speed
RickYu 15:0a55e0ac8421 16 rect_score = 10;
RickYu 2:421fb0670c5c 17 }
RickYu 2:421fb0670c5c 18
RickYu 2:421fb0670c5c 19 void rect::draw(N5110 &lcd)
RickYu 2:421fb0670c5c 20 {
RickYu 7:1964f649676e 21 //draw rect om the screen
RickYu 6:46d0caedf217 22 lcd.drawRect(rect_x,40,10,1,FILL_BLACK);
RickYu 13:7ad2072d63ac 23 lcd.drawRect(rect_x+3,39,4,1,FILL_BLACK);
RickYu 3:1a134243e2f0 24
RickYu 2:421fb0670c5c 25 }
RickYu 2:421fb0670c5c 26
RickYu 2:421fb0670c5c 27 void rect::update(Direction d,float mag)
RickYu 2:421fb0670c5c 28 {
RickYu 2:421fb0670c5c 29
RickYu 7:1964f649676e 30 rect_speed = int(mag*10.0f); // scale is arbitrary
RickYu 2:421fb0670c5c 31
RickYu 7:1964f649676e 32 //control the movement of rect when joystick moves
RickYu 7:1964f649676e 33 //movement of north and south are not allowed
RickYu 3:1a134243e2f0 34 if (d == W) {
RickYu 2:421fb0670c5c 35 rect_x-=rect_speed;
RickYu 2:421fb0670c5c 36 } else if (d == E) {
RickYu 2:421fb0670c5c 37 rect_x+=rect_speed;
RickYu 9:d217a636c18d 38
RickYu 2:421fb0670c5c 39 }
RickYu 2:421fb0670c5c 40 }
RickYu 2:421fb0670c5c 41
RickYu 10:ef01b3076040 42 void rect::add_score()
RickYu 10:ef01b3076040 43 {
RickYu 10:ef01b3076040 44 rect_score++;
RickYu 10:ef01b3076040 45 }
RickYu 10:ef01b3076040 46 int rect::get_score()
RickYu 10:ef01b3076040 47 {
RickYu 10:ef01b3076040 48 return rect_score;
RickYu 10:ef01b3076040 49 }
RickYu 2:421fb0670c5c 50
RickYu 2:421fb0670c5c 51 Vector2D rect::get_pos() {
RickYu 6:46d0caedf217 52 Vector2D p = {rect_x};
RickYu 2:421fb0670c5c 53 return p;
RickYu 3:1a134243e2f0 54 }
RickYu 5:0a116644cce2 55
RickYu 5:0a116644cce2 56 void rect::set_pos(Vector2D p)
RickYu 5:0a116644cce2 57 {
RickYu 5:0a116644cce2 58 rect_x = p.x;
RickYu 5:0a116644cce2 59 }
RickYu 5:0a116644cce2 60
RickYu 5:0a116644cce2 61
RickYu 5:0a116644cce2 62