ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_el18jgb

Dependencies:   mbed

Spikes/Spikes.cpp

Committer:
el18jgb
Date:
2020-05-19
Revision:
17:18ae81180853
Parent:
13:cfdfe60a2327
Child:
18:c600a6545e81

File content as of revision 17:18ae81180853:

#include "Spikes.h"

const int spike [5][5] = 
{
    {0,0,1,0,0},
    {0,0,1,0,0},
    {1,1,1,1,1},
    {0,1,1,1,0},
    {0,0,1,0,0},
};

Spikes::Spikes()
{

}

Spikes::~Spikes()
{

}

void Spikes::init(){
    _x = 0;
    _y = 0;
    _height = 5;
    _width = 5;
    
    _speed = 3;
}


void Spikes::draw(N5110 &lcd)
{
    // draw spike 
    lcd.drawSprite(_x,_y,5,5,(int*)spike);

}

void Spikes::position(int x)
{
    if (x == 1){
        _x = rand() % 37 + 1;
        _y = 1;
    }
    if (x == 2){
        _x = rand() % 37 + 42;
        _y = 1;
    }
    if (x == 3){
        _y = rand() % 19 + 1;
        _x = 1;
    }
    if (x == 4){
        _y = rand() % 19 + 24;
        _x = 1;
    }
}

void Spikes::updatey()
{
    _y = _y + 3;
}

void Spikes::updatex()
{
    _x = _x + 3;
}


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

void Spikes::hit(Gamepad &pad)
{
    pad.led(1,1);
    pad.led(4,1);
    wait(0.2);
    pad.leds_off();
}