Beispiel #1
0
void scr_play_init(int init_value)
{
	context_t * ctx;

	init = init_value;

	if(init_value == true) {
		ctx = context_get_player();
		sfx_stop(ctx,sfx);
	}
}
Beispiel #2
0
int __cdecl PressEscKey()
{
	int result; // eax

	result = 0;
	if ( doomflag )
	{
		doom_close();
		result = 1;
	}
	if ( helpflag )
	{
		helpflag = 0;
		result = 1;
	}
	if ( qtextflag )
	{
		qtextflag = 0;
		sfx_stop();
	}
	else
	{
		if ( !stextflag )
			goto LABEL_10;
		STextESC();
	}
	result = 1;
LABEL_10:
	if ( msgflag )
	{
		msgdelay = 0;
		result = 1;
	}
	if ( talkflag )
	{
		control_reset_talk();
		result = 1;
	}
	if ( dropGoldFlag )
	{
		control_drop_gold(VK_ESCAPE);
		result = 1;
	}
	if ( spselflag )
	{
		spselflag = 0;
		result = 1;
	}
	return result;
}
static void process_map(struct map * map, struct gamedata * gamedata)
{
  assert(map != NULL);

  memset(map->processed, 0, map->width * map->height);

  map->ameba_blocked = 0;
  for(int order = 0; order < map->width * map->height; order++)
    {
      int x, y;

      x = map->order[order * 2 + 0];
      y = map->order[order * 2 + 1];
      if(!map->processed[x + y * map->width])
	{
	  int check_for_player_kill;

	  map->processed[x + y * map->width] = 1;
	  check_for_player_kill = 0;
	  switch((enum MAP_GLYPH) map->data[x + y * map->width])
	    {
	    case MAP_EMPTY:
	    case MAP_BORDER:
	    case MAP_ILLEGAL:
	    case MAP_SAND:
	    case MAP_SMOKE:
	    case MAP_EXIT_LEVEL:
	    case MAP_EXTRA_LIFE_ANIM:
	    case MAP_BRICK:
	    case MAP_BRICK_UNBREAKABLE:
	    case MAP_BRICK_MORPHER:
	    case MAP_PLAYER_ARMOUR0:
	    case MAP_PLAYER_ARMOUR1:
	    case MAP_PLAYER_ARMOUR2:
            case MAP_TREASURE:
	      break;
	    case MAP_BRICK_EXPANDING:
	      if(x > 0 && map->data[x - 1 + y * map->width] == MAP_EMPTY)
		{
		  map->data[x - 1 + y * map->width]      = MAP_BRICK_EXPANDING;
		  map->processed[x - 1 + y * map->width] = 1;
                  if(map->fast_forwarding == false)
                    sfx_emit(SFX_BOULDER_MOVE, x - 1, y);
		}
	      else if(x + 1 < map->width && map->data[x + 1 + y * map->width] == MAP_EMPTY)
		{
		  map->data[x + 1 + y * map->width]      = MAP_BRICK_EXPANDING;
		  map->processed[x + 1 + y * map->width] = 1;
                  if(map->fast_forwarding == false)
                    sfx_emit(SFX_BOULDER_MOVE, x + 1, y);
		}
	      break;
	    case MAP_SMOKE2:
	      map->data[x + y * map->width] = MAP_SMOKE1;
	      break;
	    case MAP_SMOKE1:
	      map->data[x + y * map->width] = MAP_EMPTY;
	      break;
	    case MAP_ENEMY1:
	      {
		enum MOVE_DIRECTION current_direction;
		int nx, ny, do_move;
		
		check_for_player_kill = 1;

		current_direction = map->move_directions[x + y * map->width];

		/* try to turn left */
		switch(current_direction)
		  {
		  case MOVE_NONE:
		    break;
		  case MOVE_UP:
		    current_direction = MOVE_LEFT;
		    break;
		  case MOVE_RIGHT:
		    current_direction = MOVE_UP;
		    break;
		  case MOVE_DOWN:
		    current_direction = MOVE_RIGHT;
		    break;
		  case MOVE_LEFT:
		    current_direction = MOVE_DOWN;
		    break;
		  }

		nx = x;
		ny = y;
		do_move = 0;
		for(int i = 0; i < 2 && !do_move; i++)
		  switch(current_direction)
		    {
		    case MOVE_NONE:
		      current_direction = MOVE_UP;
		      i = 2;
		      break;
		    case MOVE_UP:
		      if(y > 0 && map->data[x + (y - 1) * map->width] == MAP_EMPTY)
			{
			  ny--;
			  do_move = 1;
			}
		      else
			current_direction = MOVE_RIGHT;
		      break;
		    case MOVE_RIGHT:
		      if(x < map->width - 1 && map->data[x + 1 + y * map->width] == MAP_EMPTY)
			{
			  nx++;
			  do_move = 1;
			}
		      else
			current_direction = MOVE_DOWN;
		      break;
		    case MOVE_DOWN:
		      if(y < map->height - 1 && map->data[x + (y + 1) * map->width] == MAP_EMPTY)
			{
			  ny++;
			  do_move = 1;
			}
		      else
			current_direction = MOVE_LEFT;
		      break;
		    case MOVE_LEFT:
		      if(x > 0 && map->data[x - 1 + y * map->width] == MAP_EMPTY)
			{
			  nx--;
			  do_move = 1;
			}
		      else
			current_direction = MOVE_UP;
		      break;
		    }

		map->data[x + y * map->width] = MAP_EMPTY;
		map->data[nx + ny * map->width]            = MAP_ENEMY1;
		map->processed[nx + ny * map->width]       = 1;
		map->move_directions[nx + ny * map->width] = current_direction;
                map->move_offsets[2 * (nx + ny * map->width) + 0] = (x - nx) * 23;
                map->move_offsets[2 * (nx + ny * map->width) + 1] = (y - ny) * 23;
	      }
	      break;
	    case MAP_ENEMY2:
	      {
		enum MOVE_DIRECTION current_direction;
		int nx, ny, do_move;

		check_for_player_kill = 1;

		current_direction = map->move_directions[x + y * map->width];

		/* try to turn right */
		switch(current_direction)
		  {
		  case MOVE_NONE:
		    current_direction = MOVE_DOWN;
		    break;
		  case MOVE_UP:
		    current_direction = MOVE_RIGHT;
		    break;
		  case MOVE_RIGHT:
		    current_direction = MOVE_DOWN;
		    break;
		  case MOVE_DOWN:
		    current_direction = MOVE_LEFT;
		    break;
		  case MOVE_LEFT:
		    current_direction = MOVE_UP;
		    break;
		  }

		nx = x;
		ny = y;
		do_move = 0;
		for(int i = 0; i < 2 && !do_move; i++)
		  switch(current_direction)
		    {
		    case MOVE_NONE:
		      current_direction = MOVE_UP;
		      break;
		    case MOVE_UP:
		      if(y > 0 && map->data[x + (y - 1) * map->width] == MAP_EMPTY)
			{
			  ny--;
			  do_move = 1;
			}
		      else
			current_direction = MOVE_LEFT;
		      break;
		    case MOVE_RIGHT:
		      if(x < map->width - 1 && map->data[x + 1 + y * map->width] == MAP_EMPTY)
			{
			  nx++;
			  do_move = 1;
			}
		      else
			current_direction = MOVE_UP;
		      break;
		    case MOVE_DOWN:
		      if(y < map->height - 1 && map->data[x + (y + 1) * map->width] == MAP_EMPTY)
			{
			  ny++;
			  do_move = 1;
			}
		      else
			current_direction = MOVE_RIGHT;
		      break;
		    case MOVE_LEFT:
		      if(x > 0 && map->data[x - 1 + y * map->width] == MAP_EMPTY)
			{
			  nx--;
			  do_move = 1;
			}
		      else
			current_direction = MOVE_DOWN;
		      break;
		    }

		map->data[x + y * map->width] = MAP_EMPTY;
		map->data[nx + ny * map->width]            = MAP_ENEMY2;
		map->processed[nx + ny * map->width]       = 1;
		map->move_directions[nx + ny * map->width] = current_direction;
                map->move_offsets[2 * (nx + ny * map->width) + 0] = (x - nx) * 23;
                map->move_offsets[2 * (nx + ny * map->width) + 1] = (y - ny) * 23;
	      }
	      break;
	    case MAP_BOULDER:
	    case MAP_DIAMOND:
	      if(y < map->height - 1)
		{
		  int fall;
		  char type;

		  type = map->data[x + y * map->width];

		  fall = 0;
		  if(map->data[x + (y + 1) * map->width] == MAP_EMPTY)
		    fall = map->width;
		  else if(map->data[x + (y + 1) * map->width] == MAP_BOULDER ||
                          map->data[x + (y + 1) * map->width] == MAP_DIAMOND ||
			  map->data[x + (y + 1) * map->width] == MAP_BRICK)
		    {
		      if(x > 0                   && map->data[x - 1 + y * map->width] == MAP_EMPTY && map->data[x - 1 + (y + 1) * map->width] == MAP_EMPTY)
			fall = -1;
		      else if(x < map->width - 1 && map->data[x + 1 + y * map->width] == MAP_EMPTY && map->data[x + 1 + (y + 1) * map->width] == MAP_EMPTY)
			fall = 1;
		    }
                  else if(y < map->height - 2 && map->data[x + (y + 1) * map->width] == MAP_SLIME)
                    {
                      if((int) map->move_directions[x + (y + 1) * map->width] >= 40) // Typecasted to int because move_directions is enum MOVE_DIRECTION.
                        {
                          map->move_directions[x + (y + 1) * map->width] = 0;
                          if(map->data[x + (y + 2) * map->width] == MAP_EMPTY)
                            {
                              map->data[x + y * map->width] = MAP_EMPTY;
                              map->data[x + (y + 2) * map->width]            = type;
                              map->processed[x + (y + 2) * map->width]       = 1;
                              map->move_directions[x + (y + 2) * map->width] = MOVE_NONE;
                            }
                        }
                      map->move_directions[x + (y + 1) * map->width] += 1;
                    }

		  if(fall)
		    {
		      int bx, by;

		      bx = x;
		      by = y;
		      if(fall == 1 || fall == -1)
			{
			  map->data[x + y * map->width] = MAP_EMPTY;
			  bx += fall;
                          map->move_offsets[2 * (bx + by * map->width) + 0] = -fall * 23;
                          map->move_offsets[2 * (bx + by * map->width) + 1] = 0;
			}
		      if(type == MAP_BOULDER)
                        map->data[bx + by * map->width] = MAP_BOULDER_FALLING;
		      else if(type == MAP_DIAMOND)
			map->data[bx + by * map->width] = MAP_DIAMOND_FALLING;
		      else
			{
			  assert(0);
			}
		      map->processed[bx + by * map->width]       = 1;
                      map->move_directions[bx + by * map->width] = MOVE_NONE;
		    }
		}
	      break;
	    case MAP_BOULDER_FALLING:
	    case MAP_DIAMOND_FALLING:
	      {
		int cont_falling;

		cont_falling = 0;
		if(y < map->height - 1)
		  {
		    switch(map->data[x + (y + 1) * map->width])
		      {
		      case MAP_EMPTY:
			cont_falling = 1;
			break;
		      case MAP_PLAYER:
			map->girl->mob->armour = 0;
                        if(map->player_death != NULL)
                          map->player_death(gamedata, 1);
			break;
		      case MAP_ENEMY1:
			enemy_death(map, gamedata, MAP_SMOKE2, x, y + 1);
			break;
		      case MAP_ENEMY2:
			enemy_death(map, gamedata, MAP_DIAMOND, x, y + 1);
			break;
		      case MAP_BRICK_MORPHER:
			if(map->morpher_is_on == 0)
			  {
			    map->morpher_is_on = 1;
			    map->morpher_end_time = map->game_time - 30 * map->frames_per_second;
			  }
			if(map->morpher_is_on == 1)
			  {
			    if(y < map->height - 2)
			      if(map->data[x + (y + 2) * map->width] == MAP_EMPTY)
				{
				  enum MAP_GLYPH g;
				  
				  if(map->data[x + y * map->width] == MAP_DIAMOND_FALLING)
				    g = MAP_BOULDER;
				  else
				    g = MAP_DIAMOND;

				  map->data[x + (y + 2) * map->width]            = g;
				  map->processed[x + (y + 2) * map->width]       = 1;
                                  map->move_directions[x + (y + 2) * map->width] = MOVE_NONE;
                                  if(map->fast_forwarding == false)
                                    sfx_emit(SFX_DIAMOND_COLLECT, x, y + 2);
				}
			    map->data[x + y * map->width] = MAP_EMPTY;
			  }
			break;
		      }
		  }

		{
		  char type;

		  type = map->data[x + y * map->width];

		  if(cont_falling)
		    {
		      map->data[x + (y + 1) * map->width]            = type;
		      map->processed[x + (y + 1) * map->width]       = 1;
                      map->move_directions[x + (y + 1) * map->width] = MOVE_NONE;
		      map->data[x + y * map->width] = MAP_EMPTY;
                      map->move_offsets[2 * (x + (y + 1) * map->width) + 0] =   0;
                      map->move_offsets[2 * (x + (y + 1) * map->width) + 1] = -23;
		    }
		  else
		    {
		      if(type == MAP_BOULDER_FALLING)
			{
                          int dist;

                          dist = abs(map->girl->mob->x - x) + abs(map->girl->mob->y - y);
                          if(dist < 10)
                            dist = 0;
                          else if(dist < 20)
                            dist = 1;
                          else
                            dist = 2;

			  map->data[x + y * map->width]            = MAP_BOULDER;
			  map->processed[x + y * map->width]       = 1;
                          if(map->fast_forwarding == false)
                            sfx_emit(SFX_BOULDER_FALL, x, y);

                          map->tilt += 3 - dist;
                          if(map->tilt > 12)
                            map->tilt = 12;
			}
		      else if(type == MAP_DIAMOND_FALLING)
			{
			  map->data[x + y * map->width]            = MAP_DIAMOND;
			  map->processed[x + y * map->width]       = 1;
                          map->move_directions[x + y * map->width] = MOVE_NONE;
                          if(map->fast_forwarding == false)
                            sfx_emit(SFX_DIAMOND_FALL, x, y);
			}
		    }
		}
	      }
	      break;
	    case MAP_PLAYER:
	      break;
	    case MAP_AMEBA:
	      {
		int dx, dy;

		dx = -1;
		dy = -1;
		if(x > 0 && (map->data[x - 1 + y * map->width] == MAP_ENEMY1 || map->data[x - 1 + y * map->width] == MAP_ENEMY2))
		  {
		    dx = x - 1;
		    dy = y;
		  }
		else if(x < map->width - 1 && (map->data[x + 1 + y * map->width] == MAP_ENEMY1 || map->data[x + 1 + y * map->width] == MAP_ENEMY2))
		  {
		    dx = x + 1;
		    dy = y;
		  }
		else if(y > 0 && (map->data[x + (y - 1) * map->width] == MAP_ENEMY1 || map->data[x + (y - 1) * map->width] == MAP_ENEMY2))
		  {
		    dx = x;
		    dy = y - 1;
		  }
		else if(y < map->height - 1 && (map->data[x + (y + 1) * map->width] == MAP_ENEMY1 || map->data[x + (y + 1) * map->width] == MAP_ENEMY2))
		  {
		    dx = x;
		    dy = y + 1;
		  }

		if(dx != -1)
		  {
		    if(map->data[dx + dy * map->width] == MAP_ENEMY1)
		      enemy_death(map, gamedata, MAP_SMOKE2, dx, dy);
		    else if(map->data[dx + dy * map->width] == MAP_ENEMY2)
		      enemy_death(map, gamedata, MAP_DIAMOND, dx, dy);
		  }
	      }
	      if(map->data[x + y * map->width] == MAP_AMEBA)
		{
		  int r;
		  
		  r = get_rand_state(200, map->ameba_random_state);
		  if(r < 5)
		    expand_ameba(map, x - 1, y);
		  else if(r < 10)
		    expand_ameba(map, x + 1, y);
		  else if(r < 15)
		    expand_ameba(map, x, y - 1);
		  else if(r < 20)
		    expand_ameba(map, x, y + 1);

                  if(map->ameba_blocked == 0 || map->ameba_blocked == 1)
                    check_ameba(map, x, y);
		}
	      break;
            case MAP_SLIME:
              break;
            case MAP_SIZEOF_:
              break;
	    }

	  if(check_for_player_kill)
            if(map->player_death != NULL)
              {
                if(x > 0 && map->data[x - 1 + y * map->width] == MAP_PLAYER)
                  map->player_death(gamedata, 1);
                else if(x < map->width - 1 && map->data[x + 1 + y * map->width] == MAP_PLAYER)
                  map->player_death(gamedata, 1);
                else if(y > 0 && map->data[x + (y - 1) * map->width] == MAP_PLAYER)
                  map->player_death(gamedata, 1);
                else if(y < map->height - 1 && map->data[x + (y + 1) * map->width] == MAP_PLAYER)
                  map->player_death(gamedata, 1);
              }
	}
    }

  if(map->ameba_blocked == -1)
    map->ameba_blocked_timer = map->frames_per_second * 4;
  else if(map->ameba_blocked == 1 && map->ameba_blocked_timer > 0)
    map->ameba_blocked_timer--; 

  if((map->ameba_blocked == 1 && map->ameba_blocked_timer == 0) || (map->ameba_time > 0 && map->ameba_time == map->game_time / map->frames_per_second))
    { /* turn ameba into diamonds or boulders */
      enum MAP_GLYPH g;

      sfx_stop();
      map->ameba_time = 0;

      g = MAP_DIAMOND;
      for(int y = 0; y < map->height && g == MAP_DIAMOND; y++)
        for(int x = 0; x < map->width && g == MAP_DIAMOND; x++)
          if(map->data[x + y * map->width] == MAP_AMEBA)
            {
              if(x > 0 && (map->data[x - 1 + y * map->width] == MAP_EMPTY || map->data[x - 1 + y * map->width] == MAP_SAND))
                g = MAP_BOULDER;
              else if(x < map->width - 1 && (map->data[x + 1 + y * map->width] == MAP_EMPTY || map->data[x + 1 + y * map->width] == MAP_SAND))
                g = MAP_BOULDER;
              else if(y > 0 && (map->data[x + (y - 1) * map->width] == MAP_EMPTY || map->data[x + (y - 1) * map->width] == MAP_SAND))
                g = MAP_BOULDER;
              else if(y < map->height - 1 && (map->data[x + (y + 1) * map->width] == MAP_EMPTY || map->data[x + (y + 1) * map->width] == MAP_SAND))
                g = MAP_BOULDER;
            }

      for(int y = 0; y < map->height; y++)
        for(int x = 0; x < map->width; x++)
          if(map->data[x + y * map->width] == MAP_AMEBA)
            map->data[x + y * map->width] = g;
    }
  
  if(map->morpher_is_on == 1)
    if(map->game_time <= map->morpher_end_time)
      map->morpher_is_on = 2;

}
Beispiel #4
0
/**********************************
Compose the character select screen
**********************************/
item_t * scr_play_compose(context_t * ctx)
{
	int bg_red = 0;
	int bg_blue = 0;
	int bg_green = 0;
	char * map_filename;
	int layer_index = 0;
	char * old_sfx = NULL;

	option = option_get();

	if(item_list) {
		item_list_free(item_list);
		item_list = NULL;
	}

	if(ctx->map == NULL ) {
		if(context_update_from_file(ctx) == RET_NOK) {
			return NULL;
		}
	}

	if(init) {
		/* Register this character to receive server notifications */
		network_request_start(ctx,ctx->id);
		ui_play_init();
		init = false;
	}

	sdl_free_keycb();
	sdl_free_mousecb();
	sdl_add_mousecb(MOUSE_WHEEL_UP,cb_zoom);
	sdl_add_mousecb(MOUSE_WHEEL_DOWN,cb_unzoom);

	change_map = ctx->change_map;

	if( change_map == true ) {
		map_filename = strconcat( MAP_TABLE,"/",ctx->map,NULL);
		network_send_req_file(ctx,map_filename);
		free(map_filename);
		if(default_layer) {
			map_layer_delete(default_layer);
		}
		default_layer = map_layer_new(ctx->map,DEFAULT_LAYER,NULL);
	}

	if( default_layer && default_layer->active ) { // Make sure map data are available
		for(layer_index = 0; layer_index < MAX_LAYER; layer_index++) {
			compose_map_set(ctx,layer_index);
			compose_map_scenery(ctx,layer_index);
			compose_item(ctx,layer_index);
			compose_sprite(ctx,layer_index);
			compose_type(ctx,layer_index);
		}
		compose_map_button(ctx);
		compose_select(ctx);

		ui_play_compose(ctx,item_list);

		// force virtual coordinate on map change
		if( change_map == true ) {
			sdl_force_virtual_x(map_t2p_x(ctx->pos_tx,ctx->pos_ty,default_layer) + default_layer->col_width[ctx->pos_tx%default_layer->col_num]/2 + default_layer->row_width[ctx->pos_ty%default_layer->row_num]/2 );
			sdl_force_virtual_y(map_t2p_y(ctx->pos_tx,ctx->pos_ty,default_layer) + default_layer->col_height[ctx->pos_tx%default_layer->col_num]/2 + default_layer->row_height[ctx->pos_ty%default_layer->row_num]/2 );
		}
		// set virtual coordinate on the same map
		else {
			sdl_set_virtual_x(map_t2p_x(ctx->pos_tx,ctx->pos_ty,default_layer) + default_layer->col_width[ctx->pos_tx%default_layer->col_num]/2 + default_layer->row_width[ctx->pos_ty%default_layer->row_num]/2 );
			sdl_set_virtual_y(map_t2p_y(ctx->pos_tx,ctx->pos_ty,default_layer) + default_layer->col_height[ctx->pos_tx%default_layer->col_num]/2 + default_layer->row_height[ctx->pos_ty%default_layer->row_num]/2 );
		}
	}

	entry_read_int(MAP_TABLE,ctx->map,&bg_red,MAP_KEY_BG_RED,NULL);
	entry_read_int(MAP_TABLE,ctx->map,&bg_blue,MAP_KEY_BG_BLUE,NULL);
	entry_read_int(MAP_TABLE,ctx->map,&bg_green,MAP_KEY_BG_GREEN,NULL);
	SDL_SetRenderDrawColor(ctx->render, bg_red, bg_blue, bg_green, 255);

	old_sfx = sfx;
	sfx = NULL;

	entry_read_string(MAP_TABLE,ctx->map,&sfx,MAP_SFX,NULL);

	if(old_sfx)  {
		if( sfx ) {
			if( strcmp(old_sfx,sfx) ) {
				sfx_stop(ctx,old_sfx);
			}
		} else  { // sfx == NULL
			sfx_stop(ctx,old_sfx);
		}
		free(old_sfx);
	}

	if( sfx && sfx[0]!=0 ) {
		sfx_play(ctx,sfx,NO_RESTART);
	}

	return item_list;
}