Snake vs Block Game to be run upon K64F.

Dependencies:   mbed

GameObjects/Barriers/Barriers.cpp

Committer:
AhmedPlaymaker
Date:
2019-05-06
Revision:
81:4c1641e10dcd
Child:
82:c51ae8a501d1

File content as of revision 81:4c1641e10dcd:

#include "Barriers.h"

Barriers::Barriers()
{

}

Barriers::~Barriers()
{

}

//Brrier Sprite.
int Barrier[22][1] = {
    {1},
    {1},
    {1},
    {1},
    {1},
    {1},
    {1},
    {1},
    {1},
    {1},
    {1},
    {1},
    {1},
    {1},
    {1},
    {1},
    {1},
    {1},
    {1},
    {1},
    {1},
    {1},
    };
void Barriers::init()
{
    reset = 0;
}


void Barriers::draw(N5110 &lcd, int b_y)
{
    velocity.x = 0;
    velocity.y = 1;
    
    if((reset == 0)&&((b_y < (_blockgap-11))||(b_y > -8))){
        _barx = rand()%82;  //this makes the barrier pop up at a random, unspecified location in the x axis.
        _bary = -22;
        reset = reset+1; //to stop this if function to keep executing.
    }
    lcd.drawSprite(_barx,_bary,22,1,(int *)Barrier); //Function to draw the frame at all i coordinates as x.
    
}

Vector2D Barriers::get_pos() //Obtains the X and Y coordinate of the target.
{
    Vector2D barrierpos = {_barx,_bary};
    //printf("barrierpos is = %f %f \n", barrierpos.x, barrierpos.y);
    return barrierpos;
}

void Barriers::update(int blockgap)
{
    _blockgap = blockgap;
    _barriergap = _blockgap/3;
    if (_blockgap <= 60) { _barriergap = 60; }
    // this if function makes sure the block appears at the rate of blockgap.
    if(_bary >= _barriergap){
        reset = 0;
    }
    _barx += velocity.x;
    _bary += velocity.y;

}


void Barriers::set_pos(Vector2D p)
{
    _barx = p.x;
    _bary = p.y;
}