Пример #1
0
void		init_menu(t_var **var)
{
  (*var)->pos_wall.x = 0;
  (*var)->pos_wall.y = 0;
  (*var)->pos_pai.x = 150;
  (*var)->pos_pai.y = 100;
  (*var)->pos_pvp.x = 150;
  (*var)->pos_pvp.y = 350;
  xSDL_BlitSurface((*var)->wall, NULL, (*var)->screen, &((*var)->pos_wall));
  if (SDL_SetColorKey((*var)->play_play, SDL_SRCCOLORKEY,
		      SDL_MapRGB((*var)->play_play->format, 0, 0, 255)) == -1)
    {
      my_puterror("Sdl Set Color Key Failed");
      exit(EXIT_FAILURE);
    }
  xSDL_BlitSurface((*var)->play_play, NULL, (*var)->screen, &((*var)->pos_pai));
  if (SDL_SetColorKey((*var)->play_cpu, SDL_SRCCOLORKEY,
		      SDL_MapRGB((*var)->play_cpu->format, 0, 0, 255)) == -1)
    {
      my_puterror("Sdl Set Color Key Failed");
      exit(EXIT_FAILURE);
    }
    xSDL_BlitSurface((*var)->play_cpu, NULL,
		     (*var)->screen, &((*var)->pos_pvp));
  xSDL_Flip((*var)->screen);
}
Пример #2
0
/*
** Here, put and make animation for each player ont the map,
** bcast, incant, movement.
** [STATIC] raison: animation for each player [loop in the player img]
*/
void		put_users(t_sdl *sdl)
{
  t_sdl_user	*user;
  SDL_Rect	rct_pos;
  static int	i = 0;
  int		i2;

  SDL_mutexP(sdl->elem->mut_user);
  user = sdl->elem->user;
  while (user)
    {
      i2 = i;
      if (user->team != NULL &&
	  (user->x >= sdl->scrollX && user->y >= sdl->scrollY))
	{
	  action_for_user(sdl, user);
	  sdl_user_sprite(sdl, user, rct_pos, i2);
	  xSDL_BlitSurface(sdl->game.player, &sdl->game.rect_player,
			  SDL_GetVideoSurface(), &sdl->game.pos_player);
	  if (++i2 > 47)
	    i2 = 0;
	}
      user = user->next;
    }
  if (++i > 47)
    i = 0;
  SDL_mutexV(sdl->elem->mut_user);
}
Err		show_gamespace(t_info *info)
{
  xSDL_BlitSurface(info->game.gamespace, NULL,
		  info->mysdl.screen, NULL);
  SDL_Flip(info->mysdl.screen);
  return (0);
}
void			event_radar(t_sdl *sdl)
{
  int			xaff;
  int			yaff;
  int			w;
  int			h;
  static int		first = 1;

  get_size_aff(sdl, &xaff, &yaff);
  count_size(&w, xaff, &h, yaff);
  if (first)
    {
      sdl->radar.screen_radar = SDL_CreateRGBSurface(SDL_HWSURFACE, w, h,
						     32, 0, 0, 0, 0);
      SDL_FillRect(sdl->radar.screen_radar, NULL,
		   SDL_MapRGB(sdl->screen->format, 255, 255, 255));
      SDL_SetAlpha(sdl->radar.screen_radar, SDL_SRCALPHA, 75);
      first = 0;
    }
  sdl->radar.rect_radar.x = (sdl->scrollX * w * 64) / xaff + 920;
  sdl->radar.rect_radar.y = (sdl->scrollY * h * 64) / yaff + 42;
  xSDL_BlitSurface(sdl->radar.screen_radar, NULL, sdl->screen,
		  &sdl->radar.rect_radar);
  put_monster_minimap(sdl);
}
void		put_items(int x, int y,
			t_sdl *sdl, SDL_Rect *pos)
{
  t_map_elt	*map_elt;
  int		cpt;
  int		flag;

  flag = 0;
  map_elt = get_cell(x, y);
  if (map_elt->food != 0)
    flag += 1;
  cpt = 0;
  while (cpt < NB_ROCKS)
    {
      if (map_elt->rocks[cpt] != 0)
	flag += 1;
      cpt++;
    }
  if (flag > 0)
    {
      put_sprite_item(&sdl->game.pos_item, pos, 0);
      sdl_update_item(&sdl->game.rect_item, 0, 0);
      xSDL_BlitSurface(sdl->game.item, &sdl->game.rect_item,
		      sdl->screen, &sdl->game.pos_item);
    }
}
void		put_item_user(int x, int y, t_sdl *sdl, SDL_Rect *pos)
{
  t_sdl_user	*usr;
  int		nb_usr_cell;

  usr = sdl->elem->user;
  nb_usr_cell = 0;
  while (usr)
    {
      if (usr->team != NULL)
	{
	  if (usr->x == x && usr->y == y)
	    nb_usr_cell++;
	}
      usr = usr->next;
    }
  if (nb_usr_cell > 0)
    {
      put_sprite_item(&sdl->game.pos_item, pos, 1);
      sdl_update_item(&sdl->game.rect_item,
		      (nb_usr_cell > 1) ? 1 : 2, 0);
      xSDL_BlitSurface(sdl->game.item, &sdl->game.rect_item,
		      sdl->screen, &sdl->game.pos_item);
    }
}
void		update_map(t_sdl *sdl, SDL_Rect *pos, int x, int y)
{
  up_date_position(pos, x - sdl->scrollX, y - sdl->scrollY);
  if (x != sdl->mousex || y != sdl->mousey)
    {
      sdl_update_grass(&sdl->game.rect_game, 0, 0);
      xSDL_BlitSurface(sdl->game.screen_game, &sdl->game.rect_game,
		      sdl->screen, pos);
    }
  else
    {
      sdl_update_grass(&sdl->game_select.rect_game, 0, 0);
      xSDL_BlitSurface(sdl->game_select.screen_game,
		      &sdl->game_select.rect_game,
		      sdl->screen, pos);
    }
}
Пример #8
0
int		aff_win_pvp(t_var var, int in_prog, int who_play)
{
  SDL_Event	event;
  SDL_Rect	pos;

  pos.x = 0;
  pos.y = 0;
  if (who_play != 0)
    xSDL_BlitSurface(var.winp2, NULL, var.screen, &pos);
  else
    xSDL_BlitSurface(var.winp1, NULL, var.screen, &pos);
  xSDL_Flip(var.screen);
  while (in_prog == 1)
    {
      xSDL_WaitEvent(&event);
      if (event.type == SDL_KEYDOWN)
	if (event.key.keysym.sym == SDLK_ESCAPE)
	  in_prog = 42;
    }
  return (42);
}
Пример #9
0
static void		aff_obj(char c, SDL_Rect position, SDL_Surface *ecran)
{
  static SDL_Surface	*ladder = NULL;
  static SDL_Surface	*wall = NULL;
  static SDL_Surface	*monster = NULL;
  static SDL_Surface	*pj = NULL;
  static SDL_Surface	*door = NULL;
  static SDL_Surface	*key = NULL;

  if (!ladder)
    {
      init_sprites(&ladder, &wall, &monster, &pj);
      door = xIMG_Load("../image/exit.png");
      key = xIMG_Load("../image/key.png");
    }
  if (c == Wall)
    xSDL_BlitSurface(wall, NULL, ecran, &position);
  else if (c == Ladder)
    xSDL_BlitSurface(ladder, NULL, ecran, &position);
  else if (c == Monster)
    xSDL_BlitSurface(monster, NULL, ecran, &position);
  else if (c == Entry)
    xSDL_BlitSurface(pj, NULL, ecran, &position);
  else if (c == Exit)
    xSDL_BlitSurface(door, NULL, ecran, &position);
  else if (c == Key)
    xSDL_BlitSurface(key, NULL, ecran, &position);
}
Пример #10
0
void		aff_player(t_board* board, t_perso* pl, int x, int y)
{
  int		pos;
  SDL_Rect	SDL_pos;

  SDL_pos.x = x * 30;
  SDL_pos.y = y * 30;
  aff_obj(Empty, SDL_pos, board->ecran);
  pos = x + (y * board->size) + y;
  if (board->map[pos] != Entry)
    aff_obj(board->map[pos], SDL_pos, board->ecran);
  SDL_pos.x = pl->x * 30;
  SDL_pos.y = pl->y * 30;
  xSDL_BlitSurface(pl->img[pl->way - Walk][pl->dir - LEFT], NULL, board->ecran, &SDL_pos);
  xSDL_Flip(board->ecran);
}
/*
** Manage incantation animations
*/
void		put_incantation(t_sdl *sdl, int x, int y)
{
  SDL_Surface	*inca;
  SDL_Rect	pos;
  SDL_Rect	rect_inca;
  int		i;

  i = 0;
  inca = initialise_surface("src_graphic/img/inca.png");
  pos.x = (x - sdl->scrollX) * MAP_W + 25;
  pos.y = (y - sdl->scrollY) * MAP_H + HEADER_MENU + 25;
  pos.h = 25;
  pos.w = 32;
  sdl_up_incantation(&rect_inca, i, 0);
  xSDL_BlitSurface(inca, &rect_inca,
		  sdl->screen, &pos);
  i++;
  if (i > 16)
    i = 0;
  SDL_FreeSurface(inca);
}
Пример #12
0
/*
** Put int the map cell sprite of egg
*/
void		put_eggs(int x, int y, t_sdl *sdl, SDL_Rect *pos)
{
  t_sdl_egg	*egg;
  int		cpt;

  SDL_mutexP(sdl->elem->mut_egg);
  egg = sdl->elem->egg;
  cpt = 0;
  while (egg)
    {
      if (egg->x == x && egg->y == y)
	cpt++;
      egg = egg->next;
    }
  if (cpt > 0)
    {
      sdl_sprite_egg(&sdl->egg.pos_egg, pos, 0);
      sdl_update_egg(&sdl->egg.rct_egg,
		     (cpt > 1) ? 1 : 0, 0);
      xSDL_BlitSurface(sdl->egg.sdl_egg, &sdl->egg.rct_egg,
		      sdl->screen, &sdl->egg.pos_egg);
    }
  SDL_mutexV(sdl->elem->mut_egg);
}
int		put_song_bcast(t_sdl *sdl, int x, int y)
{
  FSOUND_SAMPLE	*turkey;

  FSOUND_Init(44100, 32, 0);
  sdl->game.rec.x = (x - sdl->scrollX) * MAP_W + 30;
  sdl->game.rec.y = (y - sdl->scrollY) * MAP_H + HEADER_MENU + 10;
  sdl->game.rec.h = 17;
  sdl->game.rec.w = 17;
  xSDL_BlitSurface(sdl->game.bcast, NULL, sdl->screen, &sdl->game.rec);
  SDL_UpdateRects(sdl->screen, 1, &sdl->game.rec);
  if ((turkey = FSOUND_Sample_Load(FSOUND_FREE, "src_graphic/sound/gobble.wav",
				   0, 0, 0)) == NULL)
    {
      my_printf("Warning: Sound loading failled\n");
      SDL_Delay(1000);
      return (0);
    }
  FSOUND_PlaySound(FSOUND_FREE, turkey);
  SDL_Delay(1000);
  FSOUND_Sample_Free(turkey);
  FSOUND_Close();
  return (1);
}