Snake vs Block Game to be run upon K64F.

Dependencies:   mbed

GameObjects/Snake/Snake.h

Committer:
AhmedPlaymaker
Date:
2019-05-08
Revision:
87:871d9fecb593
Parent:
83:329da564799a
Child:
96:1ab67b3e6898

File content as of revision 87:871d9fecb593:

#ifndef SNAKE_H
#define SNAKE_H

#include "mbed.h"
#include "N5110.h"
#include "Gamepad.h"


class Snake
{
public:


    Snake();
    ~Snake();

    /** Initialise Snake
    *
    *   This function initalises the Snake library.
    */
    void init(N5110 *lcd);
    
    void _setLength(int length);
    void _setSpeed(int speed);

    /** Draw
    *
    *   This function draws the Snake sprite onto the screen at the specified coordinates.
    */
    void draw();

    /** Set Position
    *
    *   This function sets a position for where the snake should spawn.
    */
    void set_pos(Vector2D p);

    /** Update
    *
    *   This function updates the Snake sprite position on screen.
    */
    void update(Direction d, int* immobile_bead_n);
    
    /** Chain Snake Together
    *
    *   This function makes all of the snake beeds chained together by making the lower ones drag towards where the top one was in the previous loop
    */
    void chainSnakeTogether(int* immobile_bead_n);

    /** move Snake
    *
    *   This function makes the controls of W/E directions only exclusive to the top beed in the snake
    */
    void moveSnake(int* immobile_bead_n);

    /** Set Snake Limits
    *
    *   This function makes sure that the snake stays where it is when it ate food and does not travel off the screen.
    */
    void _setSnakeLimits();

    /** Get Position
    *
    *   This function obtains the coordinate of the top-left pixel in the Snake sprite.
    */
    Vector2D get_pos(int snakeIndex);

    int reset;
    int immobile_bead_n[10];  //each element in this array represents the beed number in the snake.

private:
    int _speed;  //this is the speed of the snake flowing in the x axis.
    int _x[10];  //each element in this array represents the x position of each beed in the snake.
    int _y[10];  //each element in this array represents the y position of each beed in the snake.
    int _length; //stores thee length of snake to be drawn or managed in terms of structure.
    Direction _d; //Stores the direction the snake moves in.
    
    //Pointer to the game pad object pad.
    Gamepad *_pad;
    //Pointer to the N5110 object lcd.
    N5110 *_lcd;

};
#endif