ELEC2645 (2017/18) / Mbed 2 deprecated el17yw

Dependencies:   mbed

rec/rect.cpp

Committer:
RickYu
Date:
2018-04-16
Revision:
5:0a116644cce2
Parent:
3:1a134243e2f0
Child:
6:46d0caedf217

File content as of revision 5:0a116644cce2:

#include "rect.h"

rect::rect()
{

}

rect::~rect()
{

}
void rect::init(int x,int y)
{
    //rect_x = x;  // x value on screen is fixed
    //rect_y = y;
    rect_speed = 0.7;  // default speed
}

void rect::draw(N5110 &lcd)
{
    lcd.drawRect(rect_x,rect_y,10,1,FILL_BLACK);
  
}

void rect::update(Direction d,float mag)
{
    
    rect_speed = int(mag*10.0f);  // scale is arbitrary, could be changed in future
    if (d == N) {
    
        rect_y-=rect_speed;
   
    } else if (d == S) {
        
        rect_y+=rect_speed;

    }
      if (d == W) {
        rect_x-=rect_speed;
    } else if (d == E) {
        rect_x+=rect_speed;
    }

    // check the y origin to ensure that the paddle doesn't go off screen
    if (rect_y < 1) {
        rect_y = 1;
    }
    if (rect_y > 44) {
        rect_y = 44;
    }

    if (rect_x < 1) {
        rect_x = 1;
    }
    if (rect_x > 80) {
        rect_x = 80;
    }
}


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

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