예제 #1
0
bool TCOD_sys_init(int w,int h, char_t *buf, char_t *oldbuf, bool fullscreen) {
	consoleWidth=w;
	consoleHeight=h;
	
	if ( fullscreen ) {
		find_resolution();
		sfWindowSettings Settings = {0, 0, 0};
		sfVideoMode Mode = {actual_fullscreen_width, actual_fullscreen_height, 32};
		renderWindow=sfRenderWindow_Create(Mode,window_title,sfFullscreen,Settings);
		TCOD_mouse_show_cursor(false);
		actual_fullscreen_width=sfRenderWindow_GetWidth(renderWindow);
		actual_fullscreen_height=sfRenderWindow_GetHeight(renderWindow);
		fullscreen_offsetx=(actual_fullscreen_width-consoleWidth*fontWidth)/2;
		fullscreen_offsety=(actual_fullscreen_height-consoleHeight*fontHeight)/2;
	} else {
		sfWindowSettings Settings = {0, 0, 0};
		sfVideoMode Mode = {w*fontWidth, h*fontHeight, 32};
		renderWindow=sfRenderWindow_Create(Mode,window_title,sfClose,Settings);
		TCOD_mouse_show_cursor(true);
	}
	charmap=sfImage_CreateFromFile(font_file);
	if (charmap == NULL ) TCOD_fatal("SFML : cannot load %s",font_file);
	if ( sfImage_GetWidth(charmap) < fontNbCharHoriz * fontWidth 
		|| sfImage_GetHeight(charmap) < fontNbCharVertic * fontHeight ) TCOD_fatal("bitmap %s too small for %dx%d, %dx%d characters\n",
		font_file,fontWidth,fontHeight,fontNbCharHoriz,fontNbCharVertic);
	sfColor colorKey={fontKeyCol.r,fontKeyCol.g,fontKeyCol.b,255};
	sfImage_CreateMaskFromColor(charmap, colorKey, 0);
	sfImage_SetSmooth(charmap, sfFalse);
	sfImage_Bind(charmap);
	charmapSprite=sfSprite_Create();
	sfSprite_SetImage(charmapSprite,charmap);
	sfSprite_SetBlendMode(charmapSprite,sfBlendNone);
	consoleBuffer=buf;
	prevConsoleBuffer=oldbuf;
	fullscreen_on=fullscreen;
	memset(key_status,0,sizeof(bool)*(TCODK_CHAR+1));
	return true;
}
예제 #2
0
void TCOD_sys_set_fullscreen(bool fullscreen) {
	fullscreen_on=fullscreen;
	if ( fullscreen ) {
		find_resolution();
		sfWindowSettings Settings = {24, 8, 0};
		sfVideoMode Mode = {actual_fullscreen_width, actual_fullscreen_height, 32};
		renderWindow=sfRenderWindow_Create(Mode,window_title,sfFullscreen,Settings);
		TCOD_mouse_show_cursor(false);
		actual_fullscreen_width=sfRenderWindow_GetWidth(renderWindow);
		actual_fullscreen_height=sfRenderWindow_GetHeight(renderWindow);
		fullscreen_offsetx=(actual_fullscreen_width-consoleWidth*fontWidth)/2;
		fullscreen_offsety=(actual_fullscreen_height-consoleHeight*fontHeight)/2;
		/*
		printf ("actual resolution : %dx%d\n",actual_fullscreen_width,actual_fullscreen_height);
		printf ("offset : %dx%d\n",fullscreen_offsetx,fullscreen_offsety);
		printf ("flags : %x bpp : %d bitspp : %d\n",screen->flags, screen->format->BytesPerPixel, screen->format->BitsPerPixel);
		*/
	} else {
		sfWindowSettings Settings = {24, 8, 0};
		sfVideoMode Mode = {consoleWidth*fontWidth, consoleHeight*fontHeight, 32};
		renderWindow=sfRenderWindow_Create(Mode,window_title,sfClose|sfTitlebar,Settings);
		TCOD_mouse_show_cursor(true);
	}
}
예제 #3
0
파일: main.c 프로젝트: archive-/console_rpg
int main(void)
{
    int w, h;
    for (h = 0; h < 90; ++h) {
        for (w = 0; w < 120; ++w) {
            map_color_scalar[h][w] = 0.f;
        }
    }

    chat_index = 0;

    TCOD_console_init_root(160, 128, "console rpg v0.01", true);
    TCOD_console_t map_console = TCOD_console_new(122, 92);
    TCOD_console_t chat_console = TCOD_console_new(122, 30);
    TCOD_map_t map = TCOD_map_new(120, 90);
    TCOD_text_t chat = TCOD_text_init(1, 28, 120, 1, 255);
    TCOD_text_set_properties(chat, TCOD_CHAR_BLOCK1, 2, ">> ", 4);
    TCOD_mouse_show_cursor(true);
    TCOD_console_set_keyboard_repeat(0, 50); 
    TCOD_sys_set_fps(60);
    end_game = entering_text = false;
    x = y = 10.f;
    vx = vy = 10.f;
    w_key = a_key = s_key = d_key = false;

    /* TODO generate map properties differently -- load from file, etc. */
    for (h = 0; h < 90; ++h) {
        for (w = 0; w < 120; ++w) {
            if (h == 0 || h == 89 || w == 0 || w == 99 || (w == 24 && h != 14 && h != 15)) {
                TCOD_map_set_properties(map, w, h, false, false);
            }
            else {
                TCOD_map_set_properties(map, w, h, true, true);
            }
        }
    }

    /* TODO game loop */
    while (!end_game && !TCOD_console_is_window_closed()) {
        handle_input(chat);
        update_game(map);
        draw_game(map_console, map, chat_console, chat);
    }

    free_stuff();
    return EXIT_SUCCESS;
}
예제 #4
0
void TCODMouse::showCursor(bool visible) {
	TCOD_mouse_show_cursor(visible);
}
예제 #5
0
int main(int _argc, char **_argv) {
	run = true;
  argc = _argc;
  argv = _argv;
#if THREADS  
  InitializeCriticalSectionAndSpinCount(&log_crit, 4000);
#endif  
  AW_SetBinDir();
  fclose(fopen((bin_dir + "log.txt").c_str(), "w+"));
  log((str("Binary directory: ") + bin_dir + "\n").c_str());
  atexit(exit);
  
  TCOD_sys_get_current_resolution(&resx, &resy);
  #if FULLSCREEN
	  CON_RES_X = floor(resx/CHAR_SIZE);
	  CON_RES_Y = floor(resy/CHAR_SIZE);
	#else
	  CON_RES_X = 70;
	  CON_RES_Y = 40;
	#endif
	TCOD_console_set_custom_font("./data/terminal.png", TCOD_FONT_LAYOUT_ASCII_INROW, 16, 48);
  TCOD_console_init_root(CON_RES_X, CON_RES_Y, "ASCIIWar", false, TCOD_RENDERER_SDL);
  con = TCOD_console_new(CON_RES_X, CON_RES_Y);
  #if FULLSCREEN
    TCOD_sys_force_fullscreen_resolution(resx, resy);   
    TCOD_console_set_fullscreen(true);
  #endif
  TCOD_sys_get_current_resolution(&resx, &resy);
  TCOD_mouse_show_cursor(true);
  TCOD_sys_set_fps(1000/NORMAL_TIME_STEP);
  #if FULLSCREEN
	  int offx, offy;
	  TCOD_sys_get_fullscreen_offsets(&offx, &offy);
	  MINIMAP_START_X = offx+CHAR_SIZE*MINIMAP_CON_START_X;
	  LAGOMETER_START_X = resx-offx-LAGOMETER_SIZE;
 	#endif
	TCOD_console_set_keyboard_repeat(1, 0);
  trace("ASCIIWar has started.");

  trace("Parsing configs...");
	TCOD_parser_t game_parser = TCOD_parser_new();
	TCOD_parser_new_struct(game_parser, (char*)"game");
	TCOD_parser_run(game_parser,"game.cfg", &game_parser_listener);
	trace("Configs parsing done.");
	trace("Master server at: " + game_desc.master_server);

  client_gi.name = "asciiwar";

  #if RELEASE
  	TCOD_console_credits();
  #endif

  if(_argc >= 4) {
    game_desc.game_name             = (char*)argv[1];
    game_desc.player_count_per_team = atoi((char*)argv[2]);
    game_desc.team_count            = atoi((char*)argv[3]);
  } else {
    game_desc.game_name             = "bahla";
    game_desc.player_count_per_team = 1+1;
    game_desc.team_count            = 1;
  }

  // client game instance
	GI_Init(&client_gi, argc, argv);
  GI_ConnectToMasterServer(&client_gi);
	GI_AddState(&client_gi, AW_state_join);
	while(run && !TCOD_console_is_window_closed())
		GI_Update(&client_gi);

  trace("Deleting game instance...");
  GI_Close(&client_gi);

  trace(str("Execution time: " 
  	+ f2a(TCOD_sys_elapsed_seconds()/60) 
  	+ " minutes."));

	return 0;
}