This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Base.h

By: a guest on Jan 21st, 2011  |  syntax: C++  |  size: 3.95 KB  |  views: 42  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #ifndef BASE_H
  2. #define BASE_H
  3. #include "../Defines.h"
  4. #include "../Camera/Camera.h"
  5. #include "../InputHandler/InputHandler.h"
  6. #include "../Orbiter/Orbiter.h"
  7. class Base
  8. {
  9. public:
  10.     Base() {}
  11.     virtual ~Base() {}
  12.     static void CallBackFunc(int button,int typeCB, void* cla)
  13.     {
  14.         Base* BASEP = static_cast<Base*>(cla);
  15.         switch(typeCB)
  16.         {
  17.             case MOUSE_DOWN:
  18.             BASEP->MouseDown(button);
  19.             break;
  20.             case MOUSE_UP:
  21.             BASEP->MouseUp(button);
  22.             break;
  23.             case BUTTON_DOWN:
  24.             BASEP->ButtonDown(button);
  25.             break;
  26.             case BUTTON_UP:
  27.             BASEP->ButtonUp(button);
  28.             break;
  29.         }
  30.     }
  31.     void ButtonDown(int button)
  32.     {
  33.         if(button == SDLK_z)
  34.         {
  35.             control_num++;
  36.             if(control_num>=30)
  37.             {
  38.                 control_num = -1;
  39.             }
  40.             //save the map
  41.             //IO_Wrapper::Write_binary_data("save_file.bin", (char*)newGame.map);
  42.         }
  43.         if(button == SDLK_x)
  44.         {
  45.             control_num--;
  46.             if(control_num<-1)
  47.             {
  48.                 control_num = 29;
  49.             }
  50.             //load a map
  51.             //newGame.map = *((int[80][60]*)IO_Wrapper::Read_binary_data("save_file.bin", sizeof(newGame.map)));
  52.             //dumpFrame();
  53.             //INHANDLER.ssFunc();
  54.         }
  55.     }
  56.     void ButtonUp(int button)
  57.     {
  58.     }
  59.     void MouseDown(int button)
  60.     {
  61.         if(button == 1)
  62.         {
  63.  
  64.         }
  65.         if(button == 2)
  66.         {
  67.  
  68.         }
  69.     }
  70.     void MouseUp(int button)
  71.     {
  72.     }
  73.     void checkButtons()
  74.     {
  75.         if(INHANDLER.ButtonDown(SDLK_w) == true)
  76.         {
  77.             o[control_num].ApplyForce(0,0.01);
  78.         }
  79.         if(INHANDLER.ButtonDown(SDLK_s) == true)
  80.         {
  81.             o[control_num].ApplyForce(0,-0.01);
  82.         }
  83.         if(INHANDLER.ButtonDown(SDLK_a) == true)
  84.         {
  85.             o[control_num].ApplyForce(-0.01,0);
  86.         }
  87.         if(INHANDLER.ButtonDown(SDLK_d) == true)
  88.         {
  89.             o[control_num].ApplyForce(0.01,0);
  90.         }
  91.     }
  92.     void checkMouse()
  93.     {
  94.         float x = INHANDLER.GetSDLMousePosX();
  95.         float y = INHANDLER.GetSDLMousePosY();
  96.         glBegin(GL_LINES);
  97.             glVertex2f(x,y+5);
  98.             glVertex2f(x,y-5);
  99.             glVertex2f(x-5,y);
  100.             glVertex2f(x+5,y);
  101.         glEnd();
  102.  
  103.         /*for(int i = 0;i<800;i+=10)
  104.         {
  105.             for(int j = 0;j<600;j+=10)
  106.             {
  107.                 int dist = ((x-i)*(x-i))+((y-j)*(y-j));
  108.                 if(dist<=3600 and dist>=1600)
  109.                 {
  110.                     glBegin(GL_LINES);
  111.                     glVertex2f(i,j);
  112.                     glVertex2f(x,y);
  113.                     glEnd();
  114.                 }
  115.             }
  116.         }*/
  117.     }
  118.     void Initialise()
  119.     {
  120.         std::cout<<"initalise\n";
  121.         control_num = 0;
  122.         for(int i = 0;i<30;i++)
  123.         {
  124.             o[i].x = (rand()%200);//+300;
  125.             o[i].y = 400;//300+(rand()%200);
  126.             o[i].ApplyForce(0,(float(rand()%200))/200);
  127.         }
  128.         CAMERA.MoveTo(0,0,0);
  129.         CAMERA.RotateTo(0,0,0);
  130.         INHANDLER.RegisterCallback(&CallBackFunc,this);
  131.     }
  132.     void Render()
  133.     {
  134.         checkMouse();
  135.         checkButtons();
  136.         //CAMERA.MoveTo(-400.0,-50.0,0.0);
  137.         //CAMERA.Look();
  138.  
  139.         glBegin(GL_POINTS);
  140.         for(int i = 0;i<30;i++)
  141.         {
  142.             o[i].ApplyGravity(400,400);
  143.             glVertex2f(o[i].x,o[i].y);
  144.         }
  145.             for(float i = 0;i<2*pi;i+=pi/10)
  146.             {
  147.                 float x = 400+(20*sin(i));
  148.                 float y = 400+(20*cos(i));
  149.                 glVertex2f(x,y);
  150.             }
  151.         glEnd();
  152.         if(control_num>-1&&control_num<30)
  153.         {
  154.             o[control_num].Trace_Path(400,400,10000);
  155.         }
  156.     }
  157.     int control_num;
  158.     //float xp,yp,xa,ya;
  159.     Orbiter o[30];
  160.     //MAIN COMPONENTS
  161.     InputHandler INHANDLER;
  162.     Camera CAMERA;
  163. protected:
  164. private:
  165. };
  166. #endif // BASE_H
clone this paste RAW Paste Data