#ifndef Snek_h
#define Snek_h

#include "Arduino.h"
#include "Vector2.h"

class Snek{


    
    public :

        Vector2 headPos; //posistion of snake head
        Vector2 lightPos[256]; //list of all snake pos 512 is max length
        byte direction; //direction that snake will move in next
        byte length; // length of snake
        bool ded; // check after game loop is snake is dead 

        // initial values
        Snek(){
            direction = 0;
            length = 1;
            ded = false;


        }

        //move the snake
        void MoveSnake(){
            
            switch (direction)
            {
                case 1:
                    headPos.y ++;
                    break;
                case 2:
                    headPos.x ++;
                    break;
                case 3:
                    headPos.y --;
                    break;
                case 4:
                    headPos.x --;
                    break;    
       
            }
            //shift all data down one 
            for (int i = length; i > 0; i--)
            {
                lightPos[i] = lightPos[i-1];

            }
           
            //put current head pos into list
            lightPos[0] = headPos;
            //removing last snake segment
            lightPos[length] =  Vector2((byte)255,(byte)255);

            //move head in direction
            
            //make sure snake has not hit its self
            for (int i = 1; i < length; i++)
            {
                if(lightPos[i] == headPos){
                    ded = true;
                }
            }
            //make sure snake is not out of bounds
            if(headPos.x >= 32 || headPos.x < 0 || headPos.y >= 16 || headPos.y < 0){
                ded = true;
            }
        }
        
        //change direction
        void ChangeDirection(int newDirection){
            
            //make sure that snake cant go in oppisite direction of current direction
            switch (direction)
            {
                case 1:
                    if(newDirection == 3){
                        return;
                    }else{
                        direction = newDirection;
                    }
                    break;
                case 2:
                     if(newDirection == 4){
                        return;
                    }else{
                        direction = newDirection;
                    }
                    break;
                case 3:
                     if(newDirection == 1){
                        return;
                    }else{
                        direction = newDirection;
                    }
                    break;
                case 4:
                     if(newDirection == 2){
                        return;
                    }else{
                        direction = newDirection;
                    }
                    break;    
       
            }
        }
        
    private :


   
};

#endif

