Snake vs Block Game to be run upon K64F.

Dependencies:   mbed

SnakevsBlock/SnakevsBlock.cpp

Committer:
AhmedPlaymaker
Date:
2019-03-26
Revision:
7:48ba87cd79b5
Child:
8:890b986b16a4

File content as of revision 7:48ba87cd79b5:

#include "SnakevsBlock.h"

SnakevsBlock::SnakevsBlock()
{

}

SnakevsBlock::~SnakevsBlock()
{

}

void SnakevsBlock::init()
{
    //The snake length configuration and all the other initial information passing will be done here
    length=1;
    
}



void SnakevsBlock::read_input(Gamepad &pad)
{
    _d = pad.get_direction(); //Obtains Direction pushed towards on Joystick.
    _mag = pad.get_mag(); //Obtains Magnitude of Joystick.
}

void SnakevsBlock::draw(N5110 &lcd, Gamepad &pad)
{
    _s.draw(lcd); //Draws the Snake.
    
    //Code to print length on game screen.
    char bufferscore[14];
    sprintf(bufferscore,"%d",length);
    lcd.printString(bufferscore,1,0);
    
            if(pad.check_event(Gamepad::BACK_PRESSED)){ //Waits for Back button to be pressed.
            
                NVIC_SystemReset(); //Software Reset.
                
            }
        
    
}


void SnakevsBlock::update(Gamepad &pad) //Updates objects on screen.
{
    _s.update(_d,_mag); 
}

void SnakevsBlock::get_pos()
{
    Vector2D snake_pos = _s.get_pos();
    //printf("player pos = %f %f \n", player_pos.x, player_pos.y); //top left of player sprite
    // 81.000000 0.000000 top right
    // 0.000000 0.000000 is top left
    // 81.000000 45.000000 bottom right
    snakex = snake_pos.x;
    snakey = snake_pos.y;
    //printf("snakexy in GAME = %d %d \n", snakex, snakey);
}