/*======================================
ALLEGRO 5 TEMPLATE
======================================== */

#include <stdlib.h>  //Standard library
#include <string.h>  //String functions
#include <sstream>  //More string functions

#include <allegro5/allegro.h>
#include <allegro5/allegro5.h>
#include <allegro5/allegro_image.h>
#include <allegro5/allegro_primitives.h>
#include <allegro5/allegro_audio.h>
#include <allegro5/allegro_font.h>
#include <allegro5/allegro_ttf.h>
#include <allegro5/allegro_vorbis.h>
#include <allegro5/allegro_flac.h>
#include <allegro5/allegro_opengl.h>
#include <allegro5/allegro_physfs.h>
#include <physfs.h>

#include <vector>    //Dynamic array data structure
#include <queue>	//Queue FIFO data structure
#include <cmath>    // C Math functions
#include <ctime>	// C Time functions

#define FRAME_RATE 60

//Declarations
ALLEGRO_DISPLAY *display;
ALLEGRO_MONITOR_INFO info;
ALLEGRO_TIMER *timer;
bool done;
//color
ALLEGRO_COLOR BLACK = al_map_rgb(0,0,0);

//Keyboard
bool key[256];

//Mouse
int mX = 0;
int mY = 0;

void init() {
	//Install event handlers
		al_init();
		al_init_image_addon();
		al_init_font_addon();
		al_init_ttf_addon();
		al_install_mouse();
		al_install_keyboard();
		al_install_joystick();
		al_install_audio(ALLEGRO_AUDIO_DRIVER_AUTODETECT);
		al_init_ogg_vorbis_addon();
		
		//For PhysFS
		//PHYSFS_init(0);
		//PHYSFS_addToSearchPath("",1);
		
	// Start a timer to regulate speed

	timer = al_install_timer(1.0/FRAME_RATE);
	al_start_timer(timer);

	//for audio....
	al_reserve_samples(64);

	//for keyboard...
	memset(key,0,sizeof(key));

	//show the mouse
	al_show_mouse_cursor(); 

	//make the random function randomer
	srand(time(NULL));


	//show screen
		al_set_new_display_flags(ALLEGRO_RESIZABLE);
		display = al_create_display(640, 480);

		//For PhysFS
		//al_set_physfs_file_interface();

		//Window Title
		al_set_window_title("Allegro 5 Template");
	

	
	
}

//Mouse_Down
void mousedown(ALLEGRO_MOUSE_EVENT *mouse) {

	}
//Mouse Up
void mouseup(ALLEGRO_MOUSE_EVENT *mouse) {
	
	}

// If a key is pressed down, add it to the key array
void keydown(ALLEGRO_KEYBOARD_EVENT *kb) {
	key[kb->keycode] = true;


	if(kb->keycode == ALLEGRO_KEY_ESCAPE) {
		
		done = true;
	}
}

// If a key is released, mark it as unpressed
void keyup(ALLEGRO_KEYBOARD_EVENT *kb) {
	key[kb->keycode] = false;
}

// If an operating system repeat event comes in, set the flag
void keyrepeat(ALLEGRO_KEYBOARD_EVENT *kb) {

}

//Mouse Move

void mouseaxes(ALLEGRO_MOUSE_EVENT *mouse) {
	mX = mouse->x;
	mY = mouse->y;

	}
//RENDER CURRENT FRAME
	void render()
	{
 //draw to the screen

 al_clear_to_color(BLACK);
 //code goes here
 al_flip_display();



	}

int main(int argc, char *argv[])

{
	//initialize game
	init();
	bool need_redraw = true;

	//Main Loop

//***** Start Main Code Here *****

	// Start the event queue to handle keyboard input and our timer
	ALLEGRO_EVENT_QUEUE *queue = al_create_event_queue();
	al_set_new_bitmap_flags(ALLEGRO_VIDEO_BITMAP);
	al_register_event_source(queue, (ALLEGRO_EVENT_SOURCE*)al_get_keyboard_event_source());
	al_register_event_source(queue, (ALLEGRO_EVENT_SOURCE*)al_get_mouse_event_source());
	al_register_event_source(queue, (ALLEGRO_EVENT_SOURCE*)timer);
	al_register_event_source(queue, (ALLEGRO_EVENT_SOURCE*)display);
		ALLEGRO_EVENT event;
	while(!done) {
	
		// Block until an event enters the queue
		    if (need_redraw && al_event_queue_is_empty(queue)) {
				render();
				need_redraw = false;
			}
		al_wait_for_event(queue, &event);

		switch(event.type) {
		case ALLEGRO_EVENT_MOUSE_AXES:
		mouseaxes(&event.mouse);
		break;
	
	case ALLEGRO_EVENT_MOUSE_BUTTON_DOWN:
		mousedown(&event.mouse);
		break;
	
	case ALLEGRO_EVENT_MOUSE_BUTTON_UP:
		mouseup(&event.mouse);
		break;

	case ALLEGRO_EVENT_KEY_DOWN:
		keydown(&event.keyboard);
		break;

	case ALLEGRO_EVENT_KEY_UP:
		keyup(&event.keyboard);
		break;
			
	case ALLEGRO_EVENT_KEY_REPEAT:
		keyrepeat(&event.keyboard);
		break;
	
	case ALLEGRO_EVENT_TIMER:
		need_redraw = true;
		break;
	case ALLEGRO_EVENT_DISPLAY_RESIZE:
		al_acknowledge_resize(event.display.source);
		break;
	case ALLEGRO_EVENT_DISPLAY_CLOSE:
		return 0;
		break;
		}
		
	
	}
//***** End Main Code Here *****


	return 0;
}
