ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_ll16j23s

Dependencies:   mbed ll16j23s_test_docs

SnakeBody/SnakeBody.cpp

Committer:
JoeShotton
Date:
2020-05-20
Revision:
3:fcd6d70e9694
Child:
4:ea3fa51c4386

File content as of revision 3:fcd6d70e9694:

#include "SnakeBody.h"

// nothing doing in the constructor and destructor
SnakeBody::SnakeBody()
{
//constructor
    Direction _fsm[5] = {
        {0, 0,  0, {0,1,2,3,4}},  // Centred
        {1, 0, -1, {1,1,2,1,4}},  // North, will not go to centre or south
        {2, 1,  0, {2,1,2,3,2}},  // East, will not go to centre or west
        {3, 0,  1, {3,3,2,3,4}},  // South, will not go to centre or north
        {4, -1, 0, {4,1,4,3,4}}   // West, will not go to centre or east
    };
}

SnakeBody::~SnakeBody()
{
//deconstructor
}

void update_movement(int x_max, int y_max, int cell_size, int d, int _state) {   
    /*
    if ((_x_head % cell_size) + (_y_head % cell_size) == 0) {   // only allows changing movement when the snake is cell-aligned
        d = pad.get_cardinal();          // gets joystick cardinal direction: 0 for centre, 1 - 4 for NESW respectively
        state = _fsm[_state].nextState[d]; // adjusts direction fsm state based on direction
    }
    
    _x_head += _fsm[_state].delta_x; // increments x value based on fsm state value
    _y_head += _fsm[_state].delta_y; // increments y value based on fsm state value
            
    _x_head = ((x_head % X_MAX) + X_MAX)% X_MAX; // wraps x back to within range 0-83
    _y_head = ((y_head % Y_MAX) + Y_MAX)% Y_MAX; // wraps y back to within range 0-83
    */    
};