ELEC2645 (2017/18) / Mbed 2 deprecated el17yw

Dependencies:   mbed

Committer:
RickYu
Date:
Tue Apr 24 19:24:03 2018 +0000
Revision:
17:7acfc8a0c277
Parent:
15:0a55e0ac8421
Child:
19:362ad1cd6d4a
fix the problem when the edge of boom collide the rect, will not game over

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