unit Init;

interface

uses
  SysUtils,
  OPENGL,
  glfw,
  bibli;
procedure initialisation();

implementation



procedure initialisation();
const
rayonD=8;
rayonT=25;


var
jouer:boolean;
x : integer;
rayon: integer;
mouvement : boolean;
alphaDM:integer;
alphaDT:integer;
deg :integer;   //regalge camera
y : integer;
zoom: integer;
pivot :  integer;


begin

jouer:=TRUE;
x:=0;
rayon:=0;
y:=0;
mouvement := TRUE;
alphaDM:=30;
alphaDT:=0;
deg:=0;
zoom:=0;
pivot:=0;

while (jouer) do
begin


  //initialisation de la fenetre OPENGL
  glfwInit();
   glfwOpenWindow(1024, 768, 0, 0, 0, 0, 42, 0, GLFW_FULLSCREEN);
   glfwSetWindowTitle('Moteur'); // optionnel
   glClear(GL_COLOR_BUFFER_BIT Or GL_DEPTH_BUFFER_BIT);
    glClearColor( 0.0, 0.0, 0.0, 0.0 );
    glEnable( GL_DEPTH_TEST );
   //le blabla pour calibrer la fenetre
    glViewPort(0, 0, 1024, 768);
   

     //matrice de projection
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity;
    //glOrtho(-16,16,-8,24,10,-10); donner un effet de perspective
    gluperspective(70,(640/480),1,100);
         //initialisation de la matrice de modelisation
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity;
    gluLookAt(-17+x+zoom, 0+y, 20-zoom, 0+x+deg+zoom, 0+y+pivot, 10+deg, 0, 0, 1);// Placement de la caméra

    glBlendFunc(GL_SRC_ALPHA,GL_ONE);
 
  

   //matrice de la carte
   glpushmatrix();

   pave(10,10,0,3,4,6,'bleu',200);
   pave(5,15,0,5,3,3,'jaune',100);
   pave(0,4,0,5,3,5,'blanc',100);
   pave(-10,30,0,6,6,4,'bleu',200);
   pave(-10,30,4,3,3,2,'pouet',200);
   pave(-10,-20,0,4,4,4,'vert',200);
   maison(10,-20,0,6,4,6,'vert',200);
   skybox(0,0,0,100,100,30,'vert','bleu',50);
   pave(15,10,0,10,4,5,'blanc',200);


   maison(-18,0,0,14,10,8,'grisf',200);
   pave(-14,7,0,2,2,12,'gris',200);
   pave(-22,7,0,2,2,12,'gris',200);
  //matrice du pave

  glpushmatrix();
     gltranslate(x,y,1);
     sablier(2,3,'bleu',200);

  glpopmatrix();

  //matrice pour le disque transparent
  glpushmatrix();

    
    glDepthMask(GL_FALSE);  
    glenable(Gl_BLEND);
    gltranslate(x,y,1);
    disk(0,rayonD-rayon,'bleu',alphaDM);
    gldisable(GL_BLEND);
    glDepthMask(GL_TRUE);
  glpopmatrix();


  //matrice du disque d'attaque
  glpushmatrix();
    glDepthMask(GL_FALSE);
    glenable(Gl_BLEND);
    gltranslate(x,y,1);
    disk(0,rayonT,'rouge',alphaDT);
    gldisable(GL_BLEND);
    glDepthMask(GL_TRUE);
  glpopmatrix();


  glflush();

  glfwSwapBuffers();

//definition des touches



if rayon<rayonD then
  if glfwGetKey(GLFW_KEY_UP) = GLFW_PRESS then
    begin
    x:=x+1;
    rayon:=rayon+1;
    end
else begin
     x:=x;
     rayon:=rayon;
     end;
if mouvement = TRUE then
begin
if rayon <rayonD then
  if glfwGetKey(GLFW_KEY_DOWN) = GLFW_PRESS then
    begin
    x:=x-1;
    rayon:=rayon+1;
    end
   else begin
          x:=x;
          rayon:=rayon;
         end;

  if rayon<rayonD then

    if glfwGetKey(GLFW_KEY_LEFT) = GLFW_PRESS then
      begin
      y:=y+1;
      rayon:=rayon+1;
      end
    else
      if glfwGetKey(GLFW_KEY_RIGHT) = GLFW_PRESS then
        begin
          y:=y-1;
          rayon:=rayon+1;
        end;
//on definie la touche qui fait passer en mouvement vers l'attaque
  if rayon=rayonD then
    if glfwGetKey(GLFW_KEY_SPACE) = GLFW_PRESS then
    begin
      rayon:=0;
      alphaDM:=30;
     alphaDT:=0;
    end;
  if (glfwGetKey(GLFW_KEY_DEL) = GLFW_PRESS)and (rayon>7) then
   begin
    alphaDM:=0;
    alphaDT:=50;
    end;


//reglage de la camera vec les bouton F2 a F8



if (glfwGetKey(GLFW_KEY_F6) = GLFW_PRESS) then
  begin
    deg:=deg+1;
  end;

  if (glfwGetKey(GLFW_KEY_F7) = GLFW_PRESS )then
  deg := deg-1;

if (glfwGetKey(GLFW_KEY_F5) = GLFW_PRESS) then
  begin
    zoom:=zoom+1;
  end;

  if (glfwGetKey(GLFW_KEY_F4) = GLFW_PRESS )then
  zoom := zoom-1;

if (glfwGetKey(GLFW_KEY_F2) = GLFW_PRESS )then
  pivot:=pivot+1;

 if (glfwGetKey(GLFW_KEY_F3) = GLFW_PRESS )then
  pivot:=pivot-1;



sleep(100);

if glfwGetKey(GLFW_KEY_ESC)=GLFW_PRESS then
begin
  jouer:=FALSE;
  glfwTerminate();
end;


end;
end;

end;
end.
