示例#1
0
int main(int argc, char** argv)
{
    map_config_t config;
    dataset_t* dataset;
    map_t* map;

    configure(&config, argc, argv);

    if(config.ot == OT_CREATE)
    {
        dataset = dataset_load(config.infile);
        if(dataset)
        {
            map = map_create(dataset, &config.level);
            if(config.print)
                map_print(map);
            map_save(config.outfile, map);
            map_destroy(map);
        }
        dataset_destroy(&dataset);
    }
    else if(config.ot == OT_READ)
    {
        map = map_load(config.infile);
        if(config.print)
            map_print(map);
        map_destroy(map);
    }
    return 0;
}
示例#2
0
void save_dialog_ok(char *filename)
{
/*	gtk_widget_set_sensitive(GTK_WIDGET(file_selection), 0);
	
	while(gtk_events_pending())
		gtk_main_iteration_do(0);
*/	
	stop_working();
	
	int r = 0;
	
	if(!map_filename->text[0])
		r = 1;

	string_clear(map_filename);
	char *cc = filename;
		
	while(*cc && *cc != '.')
		string_cat_char(map_filename, *cc++);

	string_cat_text(map_filename, ".map");


	set_map_path();
	
	if(r)
		make_wall_texture_paths_relative();
	
	map_save();
	
	start_working();
}
示例#3
0
bool dialog_save_run(void)
{
	bool				dialog_save_ok;
	WindowRef			dialog_save_wind;

	SetCursor(*GetCursor(watchCursor));

	dialog_open(&dialog_save_wind,"Save");
	ShowWindow(dialog_save_wind);

	node_path_rebuild();
	dialog_save_ok=map_save(&map);
	
	DisposeWindow(dialog_save_wind);
	
	InitCursor();
	
	return(dialog_save_ok);
}
示例#4
0
// add by wenzy
size_t map_io::import_tmi(map_context* oldContext,map_context* context,const char *mapFileName)
{
	//merge old map's tile map information to context

	// head 只有int block_size;	// 块数据大小为改变,不过写文件是动态计算了,所以不用改变 

	//change 来自策划配置的cell_data  in block 1 : terrain
	assert(oldContext->terrain.cell_data_size == context->terrain.cell_data_size);
	memcpy(context->terrain.cell_data,oldContext->terrain.cell_data,oldContext->terrain.cell_data_size);

	// block 3 : part (后面策划配置) 
	context->part_count = oldContext->part_count;
	if(context->parts)
	{
		delete [] context->parts;
		context->parts = NULL;
	}
	if(oldContext->part_count > 0)
	{
		//context->parts = new map_part[oldContext->part_count];
		//memcpy(oldContext->parts,context->parts,oldContext->part_count*sizeof(map_part) );

		context->parts = new map_part[oldContext->part_count];

		for ( int i = 0; i< oldContext->part_count; ++i )
		{
			context->parts[i].x = oldContext->parts[i].x;
			context->parts[i].y = oldContext->parts[i].y;
			context->parts[i].h = oldContext->parts[i].h;
			context->parts[i].dataid = oldContext->parts[i].dataid;
			context->parts[i].name = oldContext->parts[i].name;
		}
	}

	// block 4 : region (后面策划配置) 
	if(context->regions)
	{
		for ( int i = 0;i < context->region_count; ++i )
		{
			if ( context->regions[i].property_count > 0 )
			{
				delete [] context->regions[i].properties;
			}

		}
		delete [] context->regions;
		context->regions = NULL;
	}
	
	int regionCnt = oldContext->region_count;
	context->region_count = regionCnt;
	if ( regionCnt > 0 )
	{
		context->regions = new map_region[regionCnt];
		for ( int i = 0;i < regionCnt; ++i )
		{
			context->regions[i].x = oldContext->regions[i].x;
			context->regions[i].y = oldContext->regions[i].y;
			context->regions[i].w = oldContext->regions[i].w;
			context->regions[i].h = oldContext->regions[i].h;
			context->regions[i].property_count = oldContext->regions[i].property_count;

			if ( context->regions[i].property_count > 0 )
			{
				context->regions[i].properties = new map_region_property[context->regions[i].property_count];
			}

			for (int j = 0; j < context->regions[i].property_count; j++)
			{
				context->regions[i].properties[j].name = oldContext->regions[i].properties[j].name;
				context->regions[i].properties[j].val = oldContext->regions[i].properties[j].val;
			}
		}
	}

	// save context to map file
	map_save(mapFileName,context);

	return 0;
}
示例#5
0
bool _editor_handle_generic_event(map_editor *mapEditor, SDL_Event *sdlEvent) {
	if (sdlEvent->type != SDL_KEYDOWN) {
		// Only key events are independent of state.
		return false;
	}
	
	switch (sdlEvent->key.keysym.sym) {
	case SDLK_ESCAPE:
		SDL_StopTextInput();
		map_draw_view();
		if (mapEditor->m_bGrid == true) {
			map_draw_grid_view();
		}
		mapEditor->m_iMapEditorState = MAPEDITOR_EDIT;
		break;
	
	case SDLK_F1:
		SDL_StartTextInput();
		mapEditor->m_iMapEditorState = MAPEDITOR_NAME;
		break;
	
	case SDLK_F2:
		// Choose new tile from sprite sheet
		break;
	
	case SDLK_F3:
		// Choose new sprite sheet
		break;
	
	case SDLK_F4:
		// Change to walk edit mode.
		if (mapEditor->m_iMapEditorState == MAPEDITOR_WALK) {
			mapEditor->m_iMapEditorState = MAPEDITOR_EDIT;
			map_draw();
			if (mapEditor->m_bGrid == true) {
				map_draw_grid_view();
			}
		}
		else {
			mapEditor->m_iMapEditorState = MAPEDITOR_WALK;
			map_editor_draw_walk();
		}
		break;
	
	case SDLK_F5:
		map_save();
		break;
	
	case SDLK_F6:
		// Turn grid on/off.
		if (mapEditor->m_bGrid == true) { // turn off grid
			mapEditor->m_bGrid = false;
			map_draw();
		}
		else {
			mapEditor->m_bGrid = true;
			map_draw_grid();
		}
		break;
	
	case SDLK_F7:
		// Change LUA script associated with this map.
		break;
	
	case SDLK_F8:
		SDL_StartTextInput();
		mapEditor->m_iMapEditorState = MAPEDITOR_LOAD;
		break;
	
	default:
		return false;
	}
	return true;
}
示例#6
0
文件: main.c 项目: odrevet/GE2
game_status state_in_game(SDL_Renderer *renderer, game* p_game)
{
  bool done=false;

  game_status ret_code = QUIT;
  map *p_map = p_game->p_map;

  while (!done){
    //draw
    SDL_SetRenderDrawColor(renderer, 0x42, 0x4C, 0x4C, 0xFF);
    SDL_RenderClear(renderer);

    //draw the map
    map_draw(p_game->p_map, renderer);
    
    //draw the chipset
    image_draw(p_map->p_chipset, renderer, 0, 0);

    //input
    SDL_Event event;
    while (SDL_PollEvent(&event)){

      if(event.type ==  SDL_QUIT){
        return QUIT;
      }

      const int cam_speed = 8;
      
      switch ( event.type )
	{
	case SDL_KEYDOWN:
	  switch (event.key.keysym.sym)
	    {
	    case SDLK_t:
	      //set tile mode
	      if(p_game->tile_mode == TILE)p_game->tile_mode = LINE;
	      else p_game->tile_mode = TILE;
	      break;
	    case SDLK_q:
	      //quit
	      done=true;
	      break;
	    case SDLK_l:
	      //set screen resolution
	      if(event.key.keysym.mod & KMOD_LSHIFT){
		SCREEN_WIDTH += cam_speed;
		SCREEN_HEIGHT += cam_speed;
	      }
	      else{
		SCREEN_WIDTH -= cam_speed;
		SCREEN_HEIGHT -= cam_speed;
	      }
	      
	      SDL_RenderSetLogicalSize(renderer, SCREEN_WIDTH, SCREEN_HEIGHT);
	      break;	      
	    case SDLK_j:
	      //join mode (Z-Draw index = current depth layer)
	      p_game->join_mode = !p_game->join_mode;
	      if(p_game->join_mode)
		p_map->draw_enable_z = p_map->map_tile_z_index;
	      break;	      
	    case SDLK_z:
	      //set the Z-Draw index
	      if(event.key.keysym.mod & KMOD_LSHIFT){
		if(p_map->draw_enable_z < p_map->depth-1)
		  p_map->draw_enable_z++;
	      }
	      else if(p_map->draw_enable_z > 0)
		p_map->draw_enable_z--;

	      if(p_game->join_mode)
		p_map->map_tile_z_index = p_map->draw_enable_z;
	      break;
	      //save
	    case SDLK_s:
	      map_save(p_map, p_game->map_save_path);
	    break;
	    //set the depth layer to edit
	    case SDLK_d:
	      if(event.key.keysym.mod & KMOD_LSHIFT){
		if(p_map->map_tile_z_index < p_map->depth-1){
		  p_map->map_tile_z_index++;
		}
	      }
	      else if(p_map->map_tile_z_index > 0)
		p_map->map_tile_z_index--;

	      if(p_game->join_mode)
		p_map->draw_enable_z = p_map->map_tile_z_index;
	    break;
	    //resize the map
	    case SDLK_r:
	      state_resize_menu(renderer, p_game);
	      break;
	    //camera movement
	    case SDLK_p:
	      p_map->o_camera.z += cam_speed;
	      break;
	    case SDLK_m:
	       p_map->o_camera.z -= cam_speed;
	      break;	      
	      case SDLK_LEFT:
		p_map->o_camera.x -= cam_speed;
	      break;
	    case SDLK_RIGHT:
		p_map->o_camera.x += cam_speed;
	      break;
	    case SDLK_UP:
		p_map->o_camera.y -= cam_speed;
	      break;
	    case SDLK_DOWN:
		p_map->o_camera.y += cam_speed;
	      break;	      
	    default:
	      break;
	    }
	  break;
	case SDL_MOUSEBUTTONDOWN:
	  game_tile_click(p_game,
			  event.button.x,
			  event.button.y,
			  event.button.button);	  
	  break;
	case SDL_MOUSEMOTION:
	  map_mouse_move(p_map,
			 renderer,
			 event.button.x,
			 event.button.y);
	  break;	  
	case SDL_MOUSEWHEEL:
	  if(event.button.x < 0)
	    p_map->o_camera.y--;
	  else if(event.button.x > 0)
	    p_map->o_camera.y++;
	  break;
	default:
	  break;
	}
    }

    //update display
    SDL_RenderPresent(renderer);
  }
    
  return ret_code;
}
示例#7
0
文件: main.c 项目: odrevet/GE2
game_status state_in_game(SDL_Renderer *renderer, game* p_game)
{
  bool done=false;

  game_status ret_code = QUIT;
  map *p_map = p_game->p_map;
  
  while (!done){
    //update display
    //clear
    SDL_SetRenderDrawColor(renderer, 0x0, 0x0, 0x0, 0xFF);
    SDL_RenderClear(renderer);

    //draw the map
    map_draw(p_map, renderer);

    //draw the chipset
    image_draw(p_map->p_chipset, renderer, 0, 0);
    
    //input
    SDL_Event event;
    while (SDL_PollEvent(&event)){

      if(event.type ==  SDL_QUIT){
	done=true;
	break;
      }

      const int cam_speed = 8;
    
    switch ( event.type )
      {
      case SDL_KEYDOWN:
	switch (event.key.keysym.sym)
	  {
	  case SDLK_q:
	    done=true;
	    break;
	  case SDLK_s:
	    map_save(p_map, p_game->map_save_path);
	    break;
	  case SDLK_LEFT:
	    p_map->o_camera.x -= cam_speed;
	    break;
	  case SDLK_RIGHT:
	    p_map->o_camera.x += cam_speed;
	    break;
	  case SDLK_UP:
	    p_map->o_camera.y -= cam_speed;
	    break;
	  case SDLK_DOWN:
	    p_map->o_camera.y += cam_speed;
	    break;
	  default:
	    break;
	  }
	break;
      case SDL_MOUSEBUTTONDOWN:
	map_tile_click(p_map,
		       event.button.x,
		       event.button.y,
		       event.button.button);	  
	break;
      case SDL_MOUSEMOTION:
	map_mouse_move(p_map,
		       renderer,
		       event.button.x,
		       event.button.y);
	break;	  
      case SDL_MOUSEWHEEL:
	if(event.button.x < 0)
	  p_map->o_camera.y--;
	else if(event.button.x > 0)
	  p_map->o_camera.y++;
	break;
      default:
	break;
      }
    }

    //render
    SDL_RenderPresent(renderer);
  }
    
  return ret_code;
}
示例#8
0
文件: ex1.c 项目: yeaslism/gittest
int main()
{
	int bLoop = 1;

	MapObject.m_header.m_nSkima = 1;
	MapObject.m_pBuf = NULL;
	char TilePalette[] = {'.','#','@','%'};

	while(bLoop)
	{
		char szCmd[32];
		gets(szCmd);
		char *pTemp = strtok(szCmd," ");
		if(!strcmp(pTemp,"exit")) {
			bLoop = 0;
			if ( MapObject.m_pBuf ) {
				free(MapObject.m_pBuf);
			}
		}

		else if(!strcmp(pTemp,"dump")) {
			map_dump( &MapObject,TilePalette);
		}
		else if(!strcmp(pTemp,"new")) {
			// new 8 4
			int nWidth = atoi(strtok(NULL," "));
			int nHeight = atoi(strtok(NULL," "));
			map_new( &MapObject,nWidth,nHeight);
		}
		else if(!strcmp(pTemp,"put")) {
			//put 1 2 1 (x y tile_index)
			int x,y,tile_index;
			x = atoi(strtok(NULL," "));
			y = atoi(strtok(NULL," "));
			tile_index = atoi(strtok(NULL," "));
			//MapObject.m_pBuf[ y*MapObject.m_header.m_nWidth + x ] = tile_index;
			map_PutTile(&MapObject,x,y,tile_index);
		}
		else if(!strcmp(pTemp,"hline")) {
			//hline 1 1 (x tile_index)
			int xpos, tile_index;
			xpos = atoi(strtok(NULL," "));
			tile_index = atoi(strtok(NULL," "));

			for(int iy=0;iy<MapObject.m_header.m_nHeight;iy++){
				MapObject.m_pBuf[ iy*MapObject.m_header.m_nWidth + xpos ] = tile_index;
			}
		}
		else if(!strcmp(pTemp,"vline")) {
			int ypos, tile_index;
			ypos = atoi(strtok(NULL," "));
			tile_index = atoi(strtok(NULL," "));

			for(int ix=0;ix<MapObject.m_header.m_nWidth;ix++) {
				MapObject.m_pBuf[ ix + ypos*MapObject.m_header.m_nWidth ] = tile_index;
			}
		}
		else if(!strcmp(pTemp,"save")) {
			//save filename
			char *pTemp = strtok(NULL," ");
			map_save(&MapObject,pTemp);
			puts("Save OK");
		}
		else if(!strcmp(pTemp,"load")) {
			//load filename
			char *pTemp = strtok(NULL," ");
			map_load(&MapObject,pTemp);
			puts("Load OK");	
		}
		else if(!strcmp(pTemp,"tridraw_1")) {
			// tridraw_1 1(tile index)
			
			int nTileIndex = atoi(strtok(NULL," "));
			int nHeight = MapObject.m_header.m_nHeight;
			int nWidth = MapObject.m_header.m_nWidth;
					
			for(int iy=0;iy<nHeight;iy++) {
				for(int ix=0;(ix<iy) && (ix<nWidth);ix++) {
					MapObject.m_pBuf[ iy*nWidth +ix ]=nTileIndex;
				}
			}

		}

		
		else if(!strcmp(pTemp,"draw_cross")) {
			//draw_cross 1 2 1
			int x,y,tile_index;
			x = atoi(strtok(NULL," "));
			y = atoi(strtok(NULL," "));
			tile_index = atoi(strtok(NULL," "));
			
			MapObject.m_pBuf[ y*MapObject.m_header.m_nWidth + x ] = tile_index;
			MapObject.m_pBuf[ y*MapObject.m_header.m_nWidth + (x+1) ] = tile_index;
			MapObject.m_pBuf[ y*MapObject.m_header.m_nWidth + (x-1) ] = tile_index;
			MapObject.m_pBuf[ (y-1)*MapObject.m_header.m_nWidth + x ] = tile_index;
			MapObject.m_pBuf[ (y+1)*MapObject.m_header.m_nWidth + x ] = tile_index;






		}



	}

	return 0;
}
示例#9
0
文件: ex1.c 项目: JuWonKuk/jtest
int main()
{
	int bLoop = 1;

	MapObject.m_header.m_nSkima = 1;
	MapObject.m_pBuf = NULL;
	char TilePalette[] = {'.','#','@','%'};

	while(bLoop)
	{
		char szCmd[32];
		gets(szCmd);
		char *pTemp = strtok(szCmd," ");
		if(!strcmp(pTemp,"exit")) {
			bLoop = 0;
			if( MapObject.m_pBuf ) {
				free(MapObject.m_pBuf);
			}
		}
		else if(!strcmp(pTemp,"dump")) {
			map_dump(&MapObject,TilePalette);
		}
		else if(!strcmp(pTemp,"new")) {
			int nWidth = atoi(strtok(NULL," "));
			int nHeight = atoi(strtok(NULL," "));
			map_new(&MapObject,nWidth,nHeight);
		}
		else if(!strcmp(pTemp,"put")) {
			//put 1 2 2 (x y tile_index)
			int x,y,tile_index;
			x = atoi(strtok(NULL," "));
			y = atoi(strtok(NULL," "));
			tile_index = atoi(strtok(NULL," "));
			
			//MapObject.m_pBuf[y*MapObject.m_header.m_nWidth + x] = tile_index ;
			map_PutTile(&MapObject,x,y,tile_index);
		}
		else if(!strcmp(pTemp,"hline")) {
			int xpos,tile_index;
			xpos = atoi(strtok(NULL," "));
			tile_index = atoi(strtok(NULL," "));
			
			for(int iy =0;iy <MapObject.m_header.m_nHeight;iy++) {
				MapObject.m_pBuf[iy*MapObject.m_header.m_nWidth +xpos] = tile_index;
			}
		}
		else if(!strcmp(pTemp,"vline")) {
			int ypos,tile_index;
			ypos = atoi(strtok(NULL," "));
			tile_index = atoi(strtok(NULL," "));

			for(int ix = 0;ix < MapObject.m_header.m_nWidth;ix++) {
				MapObject.m_pBuf[ix + ypos*MapObject.m_header.m_nWidth] = tile_index;
			}
		}
		else if( !strcmp(pTemp,"save")) {
			//save filename
			char *pTemp = strtok(NULL," ");
			map_save(&MapObject,pTemp);
			puts("save ok");
		}
		else if( !strcmp(pTemp,"load")) {
			//load filename
			char *pTemp = strtok(NULL," ");
			map_load(&MapObject,pTemp);
			puts("load ok");
		
		}
		else if(!strcmp(pTemp,"tridraw_1")) {
			//tridraw_1 1
			int tile_index = atoi(strtok(NULL," "));
			for(int y = 0;y < MapObject.m_header.m_nHeight;y++) {
				for(int x = 0;x < y+1 ;x++) {
					MapObject.m_pBuf[y*MapObject.m_header.m_nWidth + x] = tile_index;
				}
			}
		}
		else if(!strcmp(pTemp,"draw_cross")) {
			//draw_cross 1 2 1
			int x,y,tile_index;
			x = atoi(strtok(NULL," "));
			y = atoi(strtok(NULL," "));
			tile_index = atoi(strtok(NULL," "));
			for(int iy =-1;iy <2;iy++) {
				for(int ix=-1;ix < 2;ix++) {
					MapObject.m_pBuf[(iy+y)*MapObject.m_header.m_nHeight + x] = tile_index;
					MapObject.m_pBuf[y*MapObject.m_header.m_nWidth +(ix+x)] = tile_index;

				}
			}

		}

	}

	return 0;
}