Ejemplo n.º 1
0
int			expose_hook(t_env *env)
{
	double			x;
	t_ray			ray;
	t_dda			dda;
	t_draw			draw;

	env->old_time = clock();
	x = 0;
	while (x <= env->vec.width)
	{
		init_ray(*env, &ray, x);
		init_dda(*env, ray, &dda);
		compute_dda(*env, &dda, ray);
		correction(&dda, ray);
		get_height(&draw, *env, dda);
		draw_walls(*env, draw, dda, x);
		draw_decor(*env, draw, x);
		x++;
	}
	mlx_put_image_to_window(env->mlx, env->win, env->img.img, 0, 0);
	env->time = clock();
	compute_fps(*env);
	move(env);
	return (0);
}
Ejemplo n.º 2
0
Archivo: tank.c Proyecto: d11/sdl_tank
// Render the entire screen
// (in the right order)
void render()
{   
	// Lock video surface (if needed)
	if (SDL_MUSTLOCK(screen)) 
		if (SDL_LockSurface(screen) < 0) 
			return;

	// Draw game objects to the screen
	draw_walls(screen, wal);
	draw_player(screen, &plr);
	draw_bots(screen, bot);
	draw_bullets(screen, bul);

	// Health bar
	int y, x;
	x = DISPLAY_WIDTH - 10 - plr.max_hp;
	for (y = DISPLAY_HEIGHT - 20; y < DISPLAY_HEIGHT - 10; y++)
	{
		put_line(screen, x, y, x + plr.hp, y, HEALTH_COLOR_GOOD);
		put_line(screen, x + plr.hp, y, DISPLAY_WIDTH - 10, y, HEALTH_COLOR_BAD);
	}

	// Unlock screen (if needed)
	if (SDL_MUSTLOCK(screen)) 
		SDL_UnlockSurface(screen);

	// Tell SDL to update the whole screen
	SDL_UpdateRect(screen, 0, 0, DISPLAY_WIDTH, DISPLAY_HEIGHT);    
}
Ejemplo n.º 3
0
int		init_draw_board(char **map, SDL_Surface **bg, t_assets *assets)
{
  int	i;

  i = 0;
  while (map[0][i] != -1)
    i++;
  assets->width = i / 3 - 2;
  assets->length = tab_len(map) - 2;
  *bg = SDL_CreateRGBSurface(SDL_HWSURFACE, WIN_X, WIN_Y, BPP, 0, 0, 0, 0);
  fill_bg(*bg, assets);
  draw_grille(*bg, assets);
  draw_walls(*bg, assets);
  return (1);
}
Ejemplo n.º 4
0
int	MlxLib::init(void)
{
  std::stringstream	_val;

  /* ************** Check height and width max values ************** */
  if ((_h * _sqsize) > HEIGHT_MAX) {
    _val << "height must be < " << (HEIGHT_MAX / _sqsize);
    _lerr = _val.str();
    return (LIB_FAILURE);
  }
  if ((_w * _sqsize) > WIDTH_MAX) {
    _val << "width must be < " << (WIDTH_MAX / _sqsize);
    _lerr = _val.str();
    return (LIB_FAILURE);
  }
  /* **************************************************************** */

  if (0 == (_mlx = mlx_init())) {
    _lerr = "mlx_init() failed!";
    return (LIB_FAILURE);
  }

  if (0 == (_win = mlx_new_window(_mlx, (_w * _sqsize), (_h * _sqsize),
  				  _wname.c_str()))) {
    _lerr = "window creation failed!";
    return (LIB_FAILURE);
  }

  if (0 == (_img = mlx_new_image(_mlx, (_w * _sqsize), (_h * _sqsize)))) {
    _lerr = "image creation failed!";
    return (LIB_FAILURE);
  }

  if (0 == (_data = mlx_get_data_addr(_img, &_bpp, &_szline, &_endian))) {
    _lerr = "unable to fetch basic data (mlx_get_data_addr() returned 0)";
    return (LIB_FAILURE);
  }

  draw_walls();
  mlx_do_key_autorepeaton(_mlx);
  return (LIB_SUCCESS);
}