ELEC2645 (2018/19) / Mbed 2 deprecated ml16c5l

Dependencies:   mbed

Wall/Wall.cpp

Committer:
ml16c5l
Date:
2019-04-22
Revision:
8:ccf827ce0072
Parent:
7:0a122d5295d2
Child:
9:192ad897ec95

File content as of revision 8:ccf827ce0072:

 /*
ELEC2645 Embedded Systems Project
School of Electronic & Electrical Engineering
University of Leeds
Name: Caiwenjing Liu
Username:ml16c5l
Student ID Number: 201165261
Date: 11/04/2019
*/
 
#include "Walls.h"

Wall::Wall(){
}

Wall::~Wall(){
}

void Wall::init(int size,int speed)
{
    _size = size;
    _x = WIDTH;  
    _y =0 ;
    srand(time(NULL));
   int di = 0; // randomise the direction. 
   if (di == 0) {
        _velocity.x = speed;
        _velocity.y = 1;
    } 
}

void Wall::draw(N5110 &lcd)
{
   /* lcd.drawRect(_x+1,_y+1,_x+40,_y+1,FILL_BLACK);
    lcd.drawRect(_x+5,_y+2,_x+36,_y+2,FILL_BLACK);
    lcd.drawRect(_x+10,_y+3,_x+31,_y+3,FILL_BLACK);   
    lcd.drawRect(_x+15,_y+4,_x+26,_y+4,FILL_BLACK);
    lcd.drawRect(_x+17,_y+5,_x+23,_y+5,FILL_BLACK);
    lcd.drawRect(_x+19,_y+6,_x+21,_y+6,FILL_BLACK);*/
    
    lcd.drawRect(_x,_y,_x+10,_y+10,FILL_BLACK);
   // lcd.drawRect(_x+20,_y,_x+30,_y+10,FILL_BLACK);
    lcd.drawRect(_x+10,_y+33,_x+20,_y+40,FILL_BLACK);
    
 
  
}

void Wall::update()
{
  
    _x -= _velocity.x;
    if (_x <= 1){
        _x = WIDTH;
        _y = 0;
        }
}

void Wall::set_velocity(Vector2D v)
{
    _velocity.x = v.x;
    _velocity.y = v.y;
}

Vector2D Wall::get_velocity()
{
    Vector2D v = {_velocity.x,_velocity.y};
    return v;
}

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

    return p;
}


void Wall::set_pos(Vector2D p)
{
    _x = p.x;
    _y = p.y;
}