Esempio n. 1
0
int				loop_hook(t_env *e)
{
	t_rgb	c;
	int		x;

	if (e->img.img != NULL)
	{
		mlx_destroy_image(e->mlx, e->img.img);
		e->img.img = NULL;
	}
	e->img.img = mlx_new_image(e->mlx, WIN_WIDTH, WIN_HEIGH);
	x = 0;
	while (x < WIN_WIDTH)
	{
		initray(e, x);
		raydir(e);
		dda(e);
		compute(e);
		colors(e, &c);
		drawline(x, e, &c);
		x++;
	}
	get_timeframe(e);
	move(e);
	mlx_put_image_to_window(e->mlx, e->win, e->img.img, 0, 0);
	return (0);
}
Esempio n. 2
0
void	ft_detect_wall(t_glob *gl)
{
	int x;

	x = 0;
	while (x < gl->s_x)
	{
		gl->camx = 2 * x / (double)gl->s_x - 1;
		ft_init_raycast(gl);
		ft_rayhandle(gl);
		dda(gl);
		handle_wall(gl);
		ft_verline(x, gl);
		x++;
	}
	gl->oldtime = gl->time;
	gl->time = clock();
	gl->ftime = (gl->time - gl->oldtime) / CLOCKS_PER_SEC;
	gl->ms = gl->ftime * 5.0;
	gl->rs = gl->ftime * 3.0;
	ft_minimap(gl);
	ft_posmap(gl);
	mlx_put_image_to_window(gl->mlx, gl->win, gl->img, 0, 0);
	mlx_put_image_to_window(gl->mlx, gl->win, gl->minimap, 1170, 600);
	mlx_destroy_image(gl->mlx, gl->img);
	mlx_destroy_image(gl->mlx, gl->minimap);
}
Esempio n. 3
0
File: q.c Progetto: ishaj/snake
void view()
{
  glClear(GL_COLOR_BUFFER_BIT);
  pointsz(1.0);
  glBegin(GL_POINTS);
  dda(outx,outy,outx,outx);
  dda(outy,outy,outy,outx);
  dda(outy,outy,outx,outy);
  dda(outy,outx,outx,outx);//outer border
  dda(inx+50,inx,inx+50,iny);
  dda(iny-50,inx,inx+50,inx);
  dda(iny-50,iny,iny-50,inx);
  dda(iny-50,iny,inx+50,iny);//inner border
  glEnd();
}
int Graph::drawLine( Point p1, Point p2,  float r, float g, float b, int method){ 
  //DPRINT( "drawLine: (%d, %d) and (%d, %d)\n", p1.x, p1.y, p2.x, p2.y);
  if(p1.x == p2.x){ //vertical line
    int y,y_end; 
    if(p1.y <= p2.y){
      y = p1.y;
      y_end = p2.y;
    }else{
      y = p2.y;
      y_end = p1.y;
    }
    for(; y<=y_end; y++)
      drawPixel(p1.x, y, r,g,b);
    return 0;
  }
  else if(p1.y == p2.y){ // horizontal line
    int x, x_end;
    if(p1.x <= p2.x){
      x = p1.x;
      x_end =  p2.x;
    }
    else{
      x = p2.x;
      x_end = p1.x; 
    }
    for(; x <= x_end; x++)
      drawPixel(x, p1.y, r,g,b);
    return 0;
  }

  // all other cases are taken care below
  if(method == BRESENHAM) 
    bresenham(p1, p2, r, g, b);
  else
    dda(p1,p2,r,g,b);
  //
  return 0;
}
Esempio n. 5
0
File: q.c Progetto: ishaj/snake
void display2()
{
  if((xa>=inx+50) ||(xa<=iny-50)||(ya>=inx) ||(ya<=iny))
  	{	
		glClear(GL_COLOR_BUFFER_BIT);
		pointsz(1.0);
		glBegin(GL_POINTS);
		//show();
		glColor3f(0.0,0.0,0.0);
		view();
		//call3();
		glutSwapBuffers();
		glEnd();
       	        glFlush();	
	}
  else
 {
  glColor3f(0.0,0.0,1.0);
  pointsz(1.0);
  view();
  pointsz(4.0);
  glBegin(GL_POINTS);
  dda(xa,ya,xb,yb);//snake
	  if(start == 0) 
	  {
		   glColor3f(1.0,1.0,1.0);
		   food();
		   start++;
	  }
	if((((xf-20) <= xa) && ((xf +20) >= xa) && ((yf-20) <= ya) && ((yf +20) >= ya)))
		 {
	score++;
		printf("%d\n",score);
	tailgrow(xf,yf,xa,ya,xb,yb);
	} 
  glutSpecialFunc(specialKeys);
  //sleep(1);
  pointsz(4.0);
	if(xa==xb)
	{
 		if(ya>yb)
 		{
 			 ya=ya+i;
 			 yb=yb+i;
 		}
 		else
 		{
 			 ya=ya-i;
 			 yb=yb-i;
 		}
	}
	else if(ya==yb)
	{
		 if(xa>xb)
		 {
			  xa=xa+i;
			  xb=xb+i;
		 }
		 else
		 {
  			xa=xa-i;
  			xb=xb-i;
 		}	
	}	
  	glBegin(GL_POINTS);
  	dda(xa,ya,xb,yb);
  	glEnd();
  	glFlush();
  	glutPostRedisplay();
  	pointsz(6.0);
	glColor3f(1.0,1.0,1.0);
  	glBegin(GL_POINTS);
  	SetPixel(xf,yf);
	pointsz(1.0);
  	glFlush();
	}
}
Esempio n. 6
0
File: q.c Progetto: ishaj/snake
void motion()
{
if(key1==0)
{
   while(t>r)
   {
	 setup();
	xa=xa+i;
	dda(xa,ya,w,p);
	if(p>yb)
	{
		yb=yb+i;
		r=yb;
	}
	else
	{
		yb=yb-i;
		t=yb;
	}
	dda(w,p,xb,yb);
	if((((xf-20) <= xa) && ((xf +20) >= xa) && ((yf-20) <= ya) && ((yf +20) >= ya)))
	{
	score++;
	tailgrow(xf,yf,xa,ya,xb,yb);
	} 
	glEnd();
	glFlush();
   }
	pointsz(1.0);
}
if( key1 == 3)
{
  while(t>r)
  {
	setup();
	ya=ya-i;
	dda(xa,ya,w,p);
	if(w>xb)
	{
		xb=xb+i;
		r=xb;
	}
	else
	{
		xb=xb-i;
		t=xb;
	}
	dda(w,p,xb,yb);
	if((((xf-20) <= xa) && ((xf +20) >= xa) && ((yf-20) <= ya) && ((yf +20) >= ya)))
		{
	score++;
		printf("%d\n",score);
	tailgrow(xf,yf,xa,ya,xb,yb);
	} 
	glEnd();
	glFlush();
  }
	pointsz(1.0);
}
if(key1==1)
{
   while(t>r)
  {
	setup();
	xa=xa-i;
	dda(xa,ya,w,p);
	if(p>yb)
	{
		yb=yb+i;
		r=yb;
	}
	else
	{
		yb=yb-i;
		t=yb;
	}
	dda(w,p,xb,yb);
	if((((xf-20) <= xa) && ((xf +20) >= xa) && ((yf-20) <= ya) && ((yf +20) >= ya)))
		{
	score++;
		printf("%d\n",score);
	tailgrow(xf,yf,xa,ya,xb,yb);
	} 
	glEnd();
	glFlush();
  }
	pointsz(1.0);
}
if(key1==2)
{
   while(t>r)
  {
	setup();
	ya=ya+i;
	dda(xa,ya,w,p);
	if(w>xb)
	{
		xb=xb+i;
		r=xb;
	}
	else
	{
		xb=xb-i;
		t=xb;
	}
	dda(w,p,xb,yb);
	if((((xf-20) <= xa) && ((xf +20) >= xa) && ((yf-20) <= ya) && ((yf +20) >= ya)))
		{
	score++;
		printf("%d\n",score);
	tailgrow(xf,yf,xa,ya,xb,yb);
	} 
	glEnd();
	glFlush();
  }
	pointsz(1.0);
}
}