#ifndef BALL_H
#define BALL_H

#include "mbed.h"
#include "N5110.h"
#include "Gamepad.h"

/** Enum for wall types */
enum WallType { 
  
    LEFT,  /**< left wall */
    RIGHT,       /**< right wall */
    TOP,      /**< top wall */
    BOTTOM,       /**< bottom wall */
    BOTTOMLEFT,  /**< bottom left 45 deg wall */
    BOTTOMRIGHT,  /**< bottom right 45 deg wall */
    TOPLEFT,  /**< top left 45 deg wall */
    TOPRIGHT,  /**< top right 45 deg wall */
    
};

/** Pixel Coordinate Struct*/
struct Coord {
    
    int x; /**< coordinate of x pixel */
    int y; /**< coordinate of y pixel */
    
};

/** Wall Information struct */
struct WallMap {
    
    WallType wall;  /**< wall type */
    Coord start; /**< coordinate of line start */
    Coord end; /**< coordinate of line end */
    
};

/** Levels Information struct */
struct Levels {
    
    Coord ball; /**< start position of ball */
    Coord hole; /**< position of hole */
    WallMap walls[16]; /**< array of walls */
    int wall_count; /**< number of walls in level */
    

};

/** Ball Class
* @brief Class for controlling the golf ball
* @author Ellis Blackford Stroud
* @date May, 2018
*/

class Ball 
{

public:

    /** Constructor */
    Ball();

    /** Destructor */
    ~Ball();
    
    void init(Coord start_pos);
    
    void drawBall(N5110 &lcd);
    
    void printShotCount(N5110 &lcd);
    
    void drawPower(N5110 &lcd, float mag);
    
    void drawAim(N5110 &lcd, Vector2D joy_coord ,float angle);
           
    void move_ball();
        
    void shoot_ball(Gamepad &pad, Vector2D joy_coord);
            
    void set_total_shot_count(int total_shot_count);
    
    int get_total_shot_count();
        
    bool check_hole(Coord hole);
    
    void check_wall_bounce(WallMap map[], int size);
    
    void set_frame_rate(int frame_rate);

private:
    
    void left_bounce(Coord start, Coord end);
    
    void right_bounce(Coord start, Coord end);
    
    void top_bounce(Coord start, Coord end);
    
    void bottom_bounce(Coord start, Coord end);
    
    void bottom_left_bounce(Coord start, Coord end);
    
    void bottom_right_bounce(Coord start, Coord end);
       
    void top_left_bounce(Coord start, Coord end);
    
    void top_right_bounce(Coord start, Coord end);
    
    float _x_pos; 
    
    float _y_pos;
    
    float _x_vel;
    
    float _y_vel;
    
    int _shot_count;
    
    int _total_shot_count;
    
    int _frame_rate;
    
    Direction _direction;
    
};  

#endif