XJEL2645 (18/19) / Mbed 2 deprecated 2645_Mygame

Dependencies:   mbed Gamepad N5110

snake/snake.cpp

Committer:
694617778
Date:
2019-04-02
Revision:
0:b67614a0c4cf
Child:
1:b49c36604125

File content as of revision 0:b67614a0c4cf:

#include "snake.h"

// nothing doing in the constructor and destructor
snake::snake()
{

}

snake::~snake()
{

}

void snake::init(int x,int y,int size,int speed)
{
    _size = size;

    _x = WIDTH/2 -  _size/2;
    _y = HEIGHT/2 - _size/2;

    _velocity.x = speed;
    _velocity.y = 0;
     
    _score = 0;  // start score from zero

}

void snake::draw(N5110 &lcd)
{

    // draw snake in screen buffer. 
    lcd.drawRect(_x,_y,_size,_size,FILL_BLACK);
}

void snake::update()
{
    _x += _velocity.x;
    _y += _velocity.y;
}

void snake::add_score()
{
    _score++;
}

int snake::get_score()
{
    return _score;
}

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