publish my project

Dependencies:   mbed

Me/Me.cpp

Committer:
dongyuhu
Date:
2020-04-27
Revision:
0:9e95a5ef2659

File content as of revision 0:9e95a5ef2659:

#include "Me.h"

Me::Me()
{

}

Me::~Me()
{

}

void Me::init(int x,int y,int height,int width)
{
    _x = 41;               //Initially set in the center of the screen
    _y = 23;
    _height = height;  //3   The colltroller is 3 by 3
    _width = width;    //3
    _speed = 2;  

}

void Me::draw(N5110 &lcd)
{
    
    lcd.drawRect(_x,_y,_width,_height,FILL_BLACK);
}

void Me::update(Direction d)
{
    _speed =2;  // scale is arbitrary, could be changed in future


    if (d == N) {
        _y-=_speed;   //_y=_y-speed;
    }  if (d == S) {
        _y+=_speed;
    }  if (d == E) {
        _x+=_speed;     //_x=_x+speed;
    }  if (d == W) {
        _x-=_speed;
    }

    if (_y < 11) {      
        _y = 11;        //coboundary
    }
    if (_y > 34) {      //lower boundary
        _y = 34;
    }
    if (_x < 11) {      //left border 
       _x = 11; 
    }
    if (_x > 70) {       //right border 
       _x = 70;
    }
           
}


Vector2D Me::get_pos() {
    Vector2D p = {_x,_y};
    return p;    
}