Exemplo n.º 1
0
TCOD_text_t TCOD_text_init2(int w, int h, int max_chars) {
    text_t * data = (text_t*)calloc(sizeof(text_t),1);
	TCOD_IFNOT(w> 0 && h > 0) return data;
    data->x = 0;
    data->y = 0;
    data->w = w;
    data->h = h;
    data->multiline = (h > 1);
    data->max = (max_chars > 0 ? max_chars + 1 : MAX_INT);
    data->interval = 800;
    data->halfinterval = 400;
    data->ascii_cursor = 0;
    data->prompt = NULL;
    data->textx = data->texty = 0;
    data->con = TCOD_console_new(w,h);
	data->sel_start = MAX_INT;
	data->sel_end = -1;
	/*
	if (! data->multiline ) {
		data->max = MIN(w - data->textx,data->max);
	} else {
		data->max = MIN(w*(h-data->texty) - data->textx,data->max);
	}
	*/
    if (max_chars && max_chars > 0) data->max = max_chars;
    else data->max = data->w * data->h;
    data->input_continue = true;
    data->len = MIN(64,data->max);
    data->text = (char*)calloc(data->len,sizeof(char));
    data->back.r = data->back.g = data->back.b = 0;
    data->fore.r = data->fore.g = data->fore.b = 255;
    data->transparency = 1.0f;
    return (TCOD_text_t)data;
}
Exemplo n.º 2
0
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;
}
Exemplo n.º 3
0
Arquivo: gui.c Projeto: pasoev/innfin
struct gui *mkgui(int w, int h)
{
    struct gui *gui = malloc(sizeof *gui);
    if (gui) {
        gui->con = TCOD_console_new(w, h);
        gui->inventory_con =
                   TCOD_console_new(INVENTORY_WIDTH, INVENTORY_HEIGHT);
        gui->render_bar = render_bar;
        gui->render_log = render_log;
        gui->render_mouse_look = render_mouse_look;
        gui->render = gui_render;
        gui->message = message;
        gui->log = TCOD_list_new();
    }

    return gui;
}
Exemplo n.º 4
0
void startLights() {
	LIGHT_MAP = TCOD_map_new(WINDOW_WIDTH, WINDOW_HEIGHT);
	DYNAMIC_LIGHT_CONSOLE = TCOD_console_new(WINDOW_WIDTH, WINDOW_HEIGHT);

	printf("Starting up lights...\n");

	TCOD_console_set_default_background(DYNAMIC_LIGHT_CONSOLE, TCOD_color_RGB(0, 0, 0));
	TCOD_console_set_key_color(DYNAMIC_LIGHT_CONSOLE, TCOD_color_RGB(255, 0, 255));
	TCOD_console_clear(DYNAMIC_LIGHT_CONSOLE);
}
Exemplo n.º 5
0
Arquivo: ui.c Projeto: witheld9/Torch
void setupUi() {
    UI_CONSOLE = TCOD_console_new(WINDOW_WIDTH, WINDOW_HEIGHT);

    TCOD_console_set_color_control(TCOD_COLCTRL_1, TCOD_color_RGB(200, 200, 200), TCOD_color_RGB(25, 25, 25));
    TCOD_console_set_default_background(UI_CONSOLE, TCOD_color_RGB(0, 0, 0));
    TCOD_console_set_key_color(UI_CONSOLE, TCOD_color_RGB(0, 0, 0));
    TCOD_console_clear(UI_CONSOLE);

    DISPLAY_TEXT = calloc(WINDOW_WIDTH, sizeof(char));
    DISPLAY_TEXT[0] = '\0';
}
Exemplo n.º 6
0
TCODConsole::TCODConsole(int w, int h) {
	data = TCOD_console_new(w,h);
}
Exemplo n.º 7
0
Arquivo: game.c Projeto: jdp/psionrl
/* The main game loop */
void play(void) {
	int playing = 1;
	int x, y, vpx, vpy;
	
	/* A messy way to do the map, works for now */
	map_t *map = map_new(50, 50);
	generate_cave(map);
	map_fov_build(map);
	
	/* Set up the offscreen consoles */
	map_layer = TCOD_console_new(ui_viewport_width, ui_viewport_height);
	psion_layer = TCOD_console_new(ui_viewport_width, ui_viewport_height);
	TCOD_console_set_key_color(psion_layer, C_KEY);
	bgcolor(psion_layer, C_KEY);
	
	/* Set up the player */
	init_player();
	rename_player("Gu the Cabeboy");
	blink_player(map);
	
	/* Initialize the inventory */
	
	
	/* Enter the main game loop! */
	while (playing) {
	
		/* Prepare the screen for drawing */
		clear(NULL);
		
		/* Calculate the position of the viewport */
		vpx = player->x - ui_viewport_width/2 > 0 ?
			  player->x - ui_viewport_width/2 : 0;
		vpy = player->y - ui_viewport_height/2 > 0 ?
			  player->y - ui_viewport_height/2 : 0;
		if ((vpx + ui_viewport_width) > map->width) {
			vpx = map->width - ui_viewport_width;
		}
		if ((vpy + ui_viewport_height) > map->height) {
			vpy = map->height - ui_viewport_height;
		}
		if (ui_viewport_width > map->width) {
			vpx = 0;
		}
		if (ui_viewport_height > map->height) {
			vpy = 0;
		}
			
		/* Calculate the field of view */
		map_fov_do(map, player->x, player->y);
		
		/* Only display the part of the map inside the viewport */
		for (y = 0; y < ui_viewport_height; y++) {
			for (x = 0; x < ui_viewport_width; x++) {
				if (((vpy+y) < map->height) && ((vpx+x) < map->width)) {
					tile_t *tile = tile_at(map, vpx+x, vpy+y);
					if (TCOD_map_is_in_fov(map->fov, vpx+x, vpy+y)) {
						fgcolor(map_layer, tile->fg_lit);
					}
					else {
						fgcolor(map_layer, tile->fg_dark);
					}
					putch(map_layer, x, y, tile->glyph);
				}
			}
		}
		
		TCOD_console_blit(map_layer, 0, 0, ui_viewport_width,
		                  ui_viewport_height, NULL, ui_viewport_x,
		                  ui_viewport_y, 255);
		
		/* Draw the player and status */
		fgcolor(NULL, C_WHITE);
		putch(NULL, ui_viewport_x+player->x-vpx, ui_viewport_y+player->y-vpy, '@');
		fgcolor(NULL, C_MSG);
		putstr(NULL, 1, 23, player->name);
		
		/* Redraw the screen */
		update();
		
		/* Handle keypress */
		TCOD_key_t k = getkey();
		if (k.c == 0) {
			switch (k.vk) {
				/* Move around */
				case TCODK_KP7: /* up left */
					attempt_move(map, player->x-1, player->y-1);
					break;
					
				case TCODK_KP8: /* up */
				case TCODK_UP:
					attempt_move(map, player->x, player->y-1);
					break;
					
				case TCODK_KP9: /* up right */
					attempt_move(map, player->x+1, player->y-1);
					break;
					
				case TCODK_KP1: /* down left */
					attempt_move(map, player->x-1, player->y+1);
					break;
				
				case TCODK_KP2: /* down */
				case TCODK_DOWN:
					attempt_move(map, player->x, player->y+1);
					break;
					
				case TCODK_KP3: /* down right */
					attempt_move(map, player->x+1, player->y+1);
					break;
				
				case TCODK_KP4: /* left */
				case TCODK_LEFT:
					attempt_move(map, player->x-1, player->y);
					break;
				
				case TCODK_KP6: /* right */
				case TCODK_RIGHT:
					attempt_move(map, player->x+1, player->y);
					break;
				
				/* View character summary */
				case TCODK_TAB:
					character();
					break;
				
				default:
					printf("%d %d\n", TCODK_TAB, k.vk);
					break;
			}
		}
		else {
			switch (k.c) {
				
				/* Quit the game */
				case 'Q':
					playing = quit();
					break;
				
				/* Open up the inventory */
				case 'i':
					inventory();
					break;
				
				/* View character summary */
				case 'c':
					character();
					break;
					
				/* Use scan ability */
				case 's':
					psion_scan(map);
					break;
				
				default:
					break;
			}
		}
	}
	
	/* Clean up, the game is over */
	map_destroy(map);
}
Exemplo n.º 8
0
void actorSetup() {
	ACTOR_CONSOLE = TCOD_console_new(WINDOW_WIDTH, WINDOW_HEIGHT);
}
Exemplo n.º 9
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;
}