ELEC2645 (2017/18) / Mbed 2 deprecated el17yw

Dependencies:   mbed

rec/rect.cpp

Committer:
RickYu
Date:
2018-04-23
Revision:
13:7ad2072d63ac
Parent:
10:ef01b3076040
Child:
14:a4176da69b49

File content as of revision 13:7ad2072d63ac:

#include "rect.h"

rect::rect()
{

}

rect::~rect()
{

}
void rect::init(int x,int y)
{
    //set the rect move speed
    rect_speed = 1;  // default speed
}

void rect::draw(N5110 &lcd)
{
    //draw rect om the screen
    lcd.drawRect(rect_x,40,10,1,FILL_BLACK);
    lcd.drawRect(rect_x+3,39,4,1,FILL_BLACK);
  
}

void rect::update(Direction d,float mag)
{
    
    rect_speed = int(mag*10.0f);  // scale is arbitrary
    
    //control the movement of rect when joystick moves
    //movement of north and south are not allowed
      if (d == W) {
        rect_x-=rect_speed;
    } else if (d == E) {
        rect_x+=rect_speed;

    }
}

void rect::add_score()
{
    rect_score++;
}
int rect::get_score()
{
    return rect_score;
}

Vector2D rect::get_pos() {
    Vector2D p = {rect_x};
    return p;    
}

void rect::set_pos(Vector2D p)
{
    rect_x = p.x;
   //rect_y = p.y;
}