#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <math.h>
#include <ctype.h>
#include <GL/glut.h>
#include <malloc.h>

#define SCORE_TEXT     "Mamba's score: "
#define SCORE_TEXT_A   "Green's score: "
#define SCORE_TEXT_B   "Red's score: "
#define START_TEXT     "Right clic to start."
#define PAUSE_TEXT     "Pause."
#define READY_TEXT     "Start when you want."
#define AUTHOR_TEXT    "The Ripper - 2004"
#define TIME_RACE_TEXT "Frames per second: "
#define GREEN_WIN_TEXT "Green mamba wins!"
#define RED_WIN_TEXT   "Red mamba wins!"
#define DRAW_TEXT      "Round draw!"
#define INSTRUCTION_TEXT_1  "Green Mamba controls:              Red Mamba controls:"
#define INSTRUCTION_TEXT_2  "                                                      "
#define INSTRUCTION_TEXT_3  "            UP_ARROW                        W         "
#define INSTRUCTION_TEXT_4  " LEFT_ARROW          RIGHT_ARROW     A            D   "
#define INSTRUCTION_TEXT_5  "           DOWN_ARROW                       S         "
#define INSTRUCTION_TEXT_6  "                                                      "
#define INSTRUCTION_TEXT_7  "F1: Start                                             "
#define INSTRUCTION_TEXT_8  "F5: Small screen                                      " 
#define INSTRUCTION_TEXT_9  "F6: Medium screen                                     "
#define INSTRUCTION_TEXT_10 "F7: Full screen                                       "
#define INSTRUCTION_TEXT_11 "P: Pause                                              "
#define INSTRUCTION_TEXT_12 ""
#define INSTRUCTION_TEXT_13 "In multiplayer mode, a Mamba loses if touch the other "
#define INSTRUCTION_TEXT_14 "one or the maze. If they touch each other on the heads"
#define INSTRUCTION_TEXT_15 "it will win the Mamba with an higher score.           "


#define SCORE_TEXT_1  "Green Mamba "
#define SCORE_TEXT_2  "   Total matches won: "
#define SCORE_TEXT_3  "   Total score: "
#define SCORE_TEXT_4  "Red Mamba "
#define SCORE_TEXT_5  "   Total matches won: "
#define SCORE_TEXT_6  "   Total score: "
#define SCORE_TEXT_7  "  "
#define SCORE_TEXT_8  "Total matches: "

#define LEVEL_1 "Snail"
#define LEVEL_2 "Easy"
#define LEVEL_3 "Normal"
#define LEVEL_4 "Hard"
#define LEVEL_5 "Hurt me plenty!"
#define LEVEL_6 "Time race"


#define LEVEL_1_C "Snail * ah ah"
#define LEVEL_2_C "Easy *"
#define LEVEL_3_C "Normal *"
#define LEVEL_4_C "Hard *"
#define LEVEL_5_C "Hurt me plenty! * Are you sure???"
#define LEVEL_6_C "Time race *"

#define SIZE_1 "Tiny"
#define SIZE_2 "Regular"
#define SIZE_3 "Huge"

#define SIZE_1_C "Tiny *"
#define SIZE_2_C "Regular *"
#define SIZE_3_C "Huge *"

#define FPS_1 8
#define FPS_2 12
#define FPS_3 17
#define FPS_4 25
#define FPS_5 40

#define MAZE_1 "Freedom"
#define MAZE_2 "Crossing"
#define MAZE_3 "Frame"

#define MAZE_1_C "Freedom *"
#define MAZE_2_C "Crossing *"
#define MAZE_3_C "Frame *"

#define VIEW_1 "Small \tF5"
#define VIEW_2 "Medium \tF6"
#define VIEW_3 "Full screen \tF7"

#define PLAYERS_1 "Single player"
#define PLAYERS_2 "Two players"

#define PLAYERS_1_C "Single player *"
#define PLAYERS_2_C "Two players *"

#define ON "On"
#define OFF "Off"

#define ON_C "On *"
#define OFF_C "Off *"

#define START_SOUND "Sound/start.wav"
#define APPLE_SOUND "Sound/apple.wav"
#define LOSE_SOUND "Sound/lose.wav"
#define START_NORMAL_SOUND "Sound/normal.wav"

#define GREEN_SNAKE_TEXTURE "Textures/greensnake.tga"
#define RED_SNAKE_TEXTURE "Textures/redsnake.tga"
#define STONE_TEXTURE "Textures/stone2.tga"
#define GRASS_TEXTURE "Textures/grass.tga"
#define APPLE_TEXTURE "Textures/apple.tga"

#define TGA_FILE_NOT_FOUND          13 /* file was not found */
#define TGA_BAD_IMAGE_TYPE          14 /* color mapped image or image is not uncompressed */
#define TGA_BAD_DIMENSION			15 /* dimension is not a power of 2 */
#define TGA_BAD_BITS				16 /* image bits is not 8, 24 or 32 */
#define TGA_BAD_DATA				17 /* image data could not be loaded */

#define PI 3.14159265
#define Y_HEADER 35
#define START_LENGTH 5
#define LINE_THICKNESS 1.5
#define SCORE_POSITION 0.618
#define FONT GLUT_BITMAP_9_BY_15
#define RESHAPE_1 1.35
#define RESHAPE_2 1.7
#define SIZE_MAX_1 25
#define SIZE_MAX_2 50
#define SIZE_MAX_3 80
#define SCORE_DELTA Y_HEADER/5
#define DELTA_Y 8
#define DELTA_X 15

typedef struct rgb_color_tag
{
    float r, g, b;
} rgb_color;

typedef struct elem_tag
{
	int x;
	int y;
	struct elem_tag *p_next;
} elem;
typedef enum directions_tag {LEFT, RIGHT, UP, DOWN} directions;
typedef enum colors_tag {BLACK, RED, GREEN, BLUE, WHITE, GRAY, YELLOW} colors; 
typedef enum my_boolean_tag {MY_FALSE, MY_TRUE} my_boolean; 
typedef enum my_block_tag {MY_FREE, MAZE, SNAKE0, SNAKE1, TOKEN} my_block; 
typedef enum status_tag {PLAY, MESSAGE, PAUSE, START, READY} status;
typedef struct snake_tag {
    int length; // actual length of the snake in my_blocks;
	int wanted_length; // length of the snake, to be reached;
	directions prev_direction; // previous direction of the snake;
	directions direction; // actual direction of the snake;
	int x; // x coordinate of the head my_block;
	int y; // y coordinate of the head my_block;
	elem *p_head; // head pointer of the FIFO;
	elem *p_tail; // tail pointer of the FIFO;
	colors color; // color of the snake if textures are disabled
	int score; // score in the current match
	int total_score; // total score
	int matches_win; // nr. of won matches 
} snake;

int  loadTGA (char *name, int id); 
void add_fifo(elem **p_p_head, elem **p_p_tail, int x, int y); 
void remove_fifo(elem **p_p_tail);
void touch(int x, int y, int snake_id);
void myTimer(int value);
void put_my_block(int x, int y, colors color);
void find_color(colors color, rgb_color *rgb_value);
void free_casual_block(int *x, int *y);
void display(void);
void initialization(void);
void myReshape(int w,int h);
void keyboard (unsigned char key, int x, int y);
void special_keyboard (int key, int x, int y);
void renderBitmapString(float x, float y, float z, void *font, char *string);
void createGLUTMenus(void);
void processMenuEvents(int option);
void writeInstructions(void);
void writeTotalScore(void);
void draw_texture(int x, int y, int texture_id);
void draw_eyes(int x, int y, directions direction, colors color);
