#ifndef BASE_H
#define BASE_H
#include "../Defines.h"
#include "../Camera/Camera.h"
#include "../InputHandler/InputHandler.h"
#include "../Orbiter/Orbiter.h"
class Base
{
public:
Base() {}
virtual ~Base() {}
static void CallBackFunc(int button,int typeCB, void* cla)
{
Base* BASEP = static_cast<Base*>(cla);
switch(typeCB)
{
case MOUSE_DOWN:
BASEP->MouseDown(button);
break;
case MOUSE_UP:
BASEP->MouseUp(button);
break;
case BUTTON_DOWN:
BASEP->ButtonDown(button);
break;
case BUTTON_UP:
BASEP->ButtonUp(button);
break;
}
}
void ButtonDown(int button)
{
if(button == SDLK_z)
{
control_num++;
if(control_num>=30)
{
control_num = -1;
}
//save the map
//IO_Wrapper::Write_binary_data("save_file.bin", (char*)newGame.map);
}
if(button == SDLK_x)
{
control_num--;
if(control_num<-1)
{
control_num = 29;
}
//load a map
//newGame.map = *((int[80][60]*)IO_Wrapper::Read_binary_data("save_file.bin", sizeof(newGame.map)));
//dumpFrame();
//INHANDLER.ssFunc();
}
}
void ButtonUp(int button)
{
}
void MouseDown(int button)
{
if(button == 1)
{
}
if(button == 2)
{
}
}
void MouseUp(int button)
{
}
void checkButtons()
{
if(INHANDLER.ButtonDown(SDLK_w) == true)
{
o[control_num].ApplyForce(0,0.01);
}
if(INHANDLER.ButtonDown(SDLK_s) == true)
{
o[control_num].ApplyForce(0,-0.01);
}
if(INHANDLER.ButtonDown(SDLK_a) == true)
{
o[control_num].ApplyForce(-0.01,0);
}
if(INHANDLER.ButtonDown(SDLK_d) == true)
{
o[control_num].ApplyForce(0.01,0);
}
}
void checkMouse()
{
float x = INHANDLER.GetSDLMousePosX();
float y = INHANDLER.GetSDLMousePosY();
glBegin(GL_LINES);
glVertex2f(x,y+5);
glVertex2f(x,y-5);
glVertex2f(x-5,y);
glVertex2f(x+5,y);
glEnd();
/*for(int i = 0;i<800;i+=10)
{
for(int j = 0;j<600;j+=10)
{
int dist = ((x-i)*(x-i))+((y-j)*(y-j));
if(dist<=3600 and dist>=1600)
{
glBegin(GL_LINES);
glVertex2f(i,j);
glVertex2f(x,y);
glEnd();
}
}
}*/
}
void Initialise()
{
std::cout<<"initalise\n";
control_num = 0;
for(int i = 0;i<30;i++)
{
o[i].x = (rand()%200);//+300;
o[i].y = 400;//300+(rand()%200);
o[i].ApplyForce(0,(float(rand()%200))/200);
}
CAMERA.MoveTo(0,0,0);
CAMERA.RotateTo(0,0,0);
INHANDLER.RegisterCallback(&CallBackFunc,this);
}
void Render()
{
checkMouse();
checkButtons();
//CAMERA.MoveTo(-400.0,-50.0,0.0);
//CAMERA.Look();
glBegin(GL_POINTS);
for(int i = 0;i<30;i++)
{
o[i].ApplyGravity(400,400);
glVertex2f(o[i].x,o[i].y);
}
for(float i = 0;i<2*pi;i+=pi/10)
{
float x = 400+(20*sin(i));
float y = 400+(20*cos(i));
glVertex2f(x,y);
}
glEnd();
if(control_num>-1&&control_num<30)
{
o[control_num].Trace_Path(400,400,10000);
}
}
int control_num;
//float xp,yp,xa,ya;
Orbiter o[30];
//MAIN COMPONENTS
InputHandler INHANDLER;
Camera CAMERA;
protected:
private:
};
#endif // BASE_H