Beispiel #1
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;
}
Beispiel #2
0
Datei: map.c Projekt: jdp/psionrl
/* Generates the fov settings from map tiles */
void map_fov_build(map_t *map) {
    int x, y;
    for (y = 0; y < map->height; y++) {
        for (x = 0; x < map->width; x++) {
            tile_t *tile = tile_at(map, x, y);
            TCOD_map_set_properties(map->fov, x, y, tile->transparent,
                                    tile->walkable);
        }
    }
}
Beispiel #3
0
void itemFunc_Door(int iAction, int iX, int iY, void *vUserData) {
	if (iAction == ACT_OPEN || iAction == ACT_WALK_INTO) {
		if (g_iWorld[iX][iY] == ITEM_DOOR_CLOSED)
			g_iWorld[iX][iY] = ITEM_DOOR_OPEN;
		else if (g_iWorld[iX][iY] == ITEM_DOOR_OPEN)
			g_iWorld[iX][iY] = ITEM_DOOR_CLOSED;
		TCOD_map_set_properties(g_tcodMap, iX, iY, g_itemData[g_iWorld[iX][iY]].m_stats.m_bTransparent, g_itemData[g_iWorld[iX][iY]].m_stats.m_bWalkable);
	}
	return;
}
Beispiel #4
0
void TCODMap::setProperties(int x, int y, bool isTransparent, bool isWalkable) {
	TCOD_map_set_properties(data,x,y,isTransparent,isWalkable);
}
Beispiel #5
0
void _drawDynamicLight(light *lght) {
	int x, y, penalty, r_tint, g_tint, b_tint;
	float distMod, alpha;
	character *player = getPlayer();
	TCOD_map_t levelMap = getLevelMap();
	
	if (!lght->lightMap) {
		return;
	}
	
	TCOD_map_clear(lght->lightMap, 0, 0);
	
	if (!lght->fuel) {
		return;
	}
	
	for (y = lght->y - 32; y < lght->y + 32; y++) {
		for (x = lght->x - 32; x < lght->x + 32; x++) {
			if (x < 0 || x >= WINDOW_WIDTH || y < 0 || y >= WINDOW_HEIGHT) {
				continue;
			}
			
			if (TCOD_map_is_in_fov(lght->fov, x, y)) {
				if (lght->fuel < lght->size) {
					penalty = lght->size - lght->fuel;
				} else {
					penalty = 0;
				}
				
				distMod = lght->size - (distanceFloat(lght->x, lght->y, x, y) + penalty);
				
				if (distMod <= 0) {
					TCOD_map_set_properties(lght->lightMap, x, y, 0, 0);
				} else {
					TCOD_map_set_properties(lght->lightMap, x, y, 1, 1);
				}

				if (isPositionWalkable(x, y)) {
					distMod -= getRandomFloat(0, lght->flickerRate);
				}
				
				if (distMod < 0) {
					distMod = 0;
				} else if (distMod > lght->size / 2) {
					distMod = lght->size / 2;
				}
				
				alpha = (distMod / (float) lght->size);
				alpha *= lght->sizeMod;

				if (lght->noTint) {
					r_tint = 1;
					g_tint = 1;
					b_tint = 1;
				} else {
					if (!TCOD_map_is_walkable(levelMap, x, y)) {
						r_tint = 55 + RED_SHIFT;
						g_tint = 55;
						b_tint = 55;

						if (alpha > .45) {
							alpha = .45;
						}
					} else {
						r_tint = lght->r_tint + RED_SHIFT;
						g_tint = lght->g_tint;
						b_tint = lght->b_tint;

						alpha = clipFloat(alpha, 0, lght->brightness);
					}
				}
				
				if (!player || TCOD_map_is_in_fov(player->fov, x, y)) {
					drawCharBackEx(DYNAMIC_LIGHT_CONSOLE, x, y, TCOD_color_RGB(r_tint, g_tint, b_tint), TCOD_BKGND_ADDALPHA(alpha));
				}
			}
		}
	}
}
Beispiel #6
0
void drawLights() {
	int x, y, x1, y1, highest, distMod, changed = 1;
	light *ptr = LIGHTS;
	TCOD_console_t lightConsole = getLightConsole();
	lightMap = malloc(sizeof(double[255][255]));
	
	for (y = 0; y <= WINDOW_HEIGHT; y++) {
		for (x = 0; x <= WINDOW_WIDTH; x++) {
			lightMap[x][y] = 0;
		}
	}

	while (ptr != NULL) {
		_drawLight(ptr);

		ptr = ptr->next;
	}
	
	while (changed) {
		changed = 0;
		
		for (y = 0; y <= WINDOW_HEIGHT; y++) {
			for (x = 0; x <= WINDOW_WIDTH; x++) {
				if (!isPositionWalkable(x, y)) {
					continue;
				}
				
				highest = -1;
				
				if (lightMap[x][y]) {
					continue;
				}
				
				for (y1 = -1; y1 <= 1; y1++) {
					for (x1 = -1; x1 <= 1; x1++) {
						if (!isPositionWalkable(x + x1, y + y1)) {
							continue;
						}
						
						distMod = lightMap[x + x1][y + y1];
						
						if (lightMap[x + x1][y + y1] > highest) {
							highest = lightMap[x + x1][y + y1];
						}
						
						//drawCharBackEx(lightConsole, x + x1, y + y1, TCOD_color_RGB(250 - distMod, 200 - distMod, 0), TCOD_BKGND_ALPHA(1.f));
					}
				}
				
				
				if (highest > 14) {
					highest -= 14;
					
					if (highest < 0) {
						continue;
					}
					
					lightMap[x][y] = highest;
					changed = 1;
				}
			}
		}
	}
	
	for (y = 0; y <= WINDOW_HEIGHT; y++) {
		for (x = 0; x <= WINDOW_WIDTH; x++) {
			if (lightMap[x][y]) {
				distMod = lightMap[x][y];
				drawCharBackEx(lightConsole, x, y, TCOD_color_RGB(65, 65, 65), TCOD_BKGND_ALPHA(distMod / 64.f));
				TCOD_map_set_properties(LIGHT_MAP, x, y, 1, 1);
			}
			
		}
	}
}
int main(int argc, char **argv) {
	int iItemToPlace = ITEM_ORE_STONE;
	int iInventoryOffset = 0;
	int iInventoryPointer = 0;
	int iInventorySelection = -1;
	int iLookX = 0;
	int iLookY = 0;
	int iNewX = 0;
	int iNewY = 0;
	int iSelect = 0;
	TCOD_key_t tKey;
	char cCharCode;

	bool bTurnOver = false;

	globalsInit();

	TCOD_console_set_custom_font("terminal8x8_gs_ro.png", TCOD_FONT_TYPE_GREYSCALE | TCOD_FONT_LAYOUT_ASCII_INROW, 16, 16);
	TCOD_console_init_root(100, 75, "RogueCraft", false);
	TCOD_console_set_background_color(NULL, TCOD_black);
	TCOD_console_set_foreground_color(NULL, TCOD_light_grey);

	g_tcodMap = TCOD_map_new(DEF_WORLD_X, DEF_WORLD_Y);

	mapClear();
	generateBSPtoMap(true);
	itemPopulate(ITEM_ORE_IRON, 0, 45, 100);
	itemPopulate(ITEM_ORE_COPPER, 0, 35, 100);
	itemPopulate(ITEM_ORE_STONE_WEAK, 0, 25, 100);

	/* Populate a torch ... or three. */
	itemPopulate(25, 1, 35, 100);
	mapRemapLight(25);

	playerInit();

	TCOD_map_compute_fov(g_tcodMap, g_ego.m_stats.m_iWorldX, g_ego.m_stats.m_iWorldY, (int)g_ego.m_fFOVDistance, true, FOV_SHADOW);
	iNewX = g_ego.m_stats.m_iWorldX;
	iNewY = g_ego.m_stats.m_iWorldY;

	/* Debug code for inventory management */
	inventoryAdd(&g_ego.m_inventory, 30, 1);
	inventoryAdd(&g_ego.m_inventory, 31, 1);

	g_iGameMode = MODE_INTRO;

	npcPopulate(1, 1, 55, 100);

	while (!TCOD_console_is_window_closed()) {
		tKey = TCOD_console_check_for_keypress(TCOD_KEY_PRESSED);
		cCharCode = tolower(tKey.c);

		/* Global inputs */
		switch (tKey.vk) {
			case TCODK_ESCAPE:
				if (g_iGameMode != MODE_GAME && g_iGameMode != MODE_INTRO) {
					if (g_iGameMode == MODE_LOOK) {
						iNewX = g_ego.m_stats.m_iWorldX;
						iNewY = g_ego.m_stats.m_iWorldY;
						TCOD_console_put_char(NULL, iLookX, iLookY, 0, TCOD_BKGND_NONE);
					}
					g_iGameMode = MODE_GAME;
					inventoryClear();
				}
				else {
					TCOD_console_delete(NULL);
					SDL_Quit();
					return 1;
				}
				break;
			case TCODK_PRINTSCREEN:
				TCOD_sys_save_screenshot(NULL);
				break;
			case TCODK_KP1:
				iNewX--;
				iNewY++;
				break;
			case TCODK_KP2:
				iNewY++;
				break;
			case TCODK_KP3:
				iNewX++;
				iNewY++;
				break;
			case TCODK_KP4:
				iNewX--;
				break;
			case TCODK_KP6:
				iNewX++;
				break;
			case TCODK_KP7:
				iNewX--;
				iNewY--;
				break;
			case TCODK_KP8:
				iNewY--;
				break;
			case TCODK_KP9:
				iNewX++;
				iNewY--;
				break;
			default:
				break;
		}

		/* Mode inputs */
		switch (g_iGameMode) {
			case MODE_INTRO:
				TCOD_console_clear(NULL);
				scene_intro();
				scene_intro_input(tKey, cCharCode);
				break;
			case MODE_GAME:
				mapDraw();
				inventoryDrawBorder();
				playerStatsList();
				consoleDraw();
				consoleInputDraw();

				TCOD_console_put_char(NULL, 76, 33 + iInventoryPointer, 16, TCOD_BKGND_NONE);
				TCOD_console_put_char(NULL, g_ego.m_stats.m_iWorldX, g_ego.m_stats.m_iWorldY, '@', TCOD_BKGND_NONE);
				iInventorySelection = inventoryList(&g_ego.m_inventory, iInventoryPointer, iInventoryOffset);
				TCOD_console_print_left(NULL, 78, 31, TCOD_BKGND_NONE, "Inventory");

				if (tKey.vk >= TCODK_KP1 && tKey.vk <= TCODK_KP9) {
					if (iNewX >= 0 && iNewX < DEF_WORLD_X && iNewY >= 0 && iNewY < DEF_WORLD_Y) {
						if (g_npcMap[iNewX][iNewY] == NULL) {
							if (g_itemData[g_iWorld[iNewX][iNewY]].m_stats.m_bWalkable) {
								g_ego.m_stats.m_iWorldX = iNewX;
								g_ego.m_stats.m_iWorldY = iNewY;
								TCOD_console_put_char(NULL, g_ego.m_stats.m_iWorldX, g_ego.m_stats.m_iWorldY, ' ', TCOD_BKGND_NONE);
								g_itemData[g_iWorld[iNewX][iNewY]].m_vFunc(ACT_WALK_ONTO, iNewX, iNewY, NULL);
							}
							else {
								g_itemData[g_iWorld[iNewX][iNewY]].m_vFunc(ACT_WALK_INTO, iNewX, iNewY, NULL);
								iNewX = g_ego.m_stats.m_iWorldX;
								iNewY = g_ego.m_stats.m_iWorldY;
								mapMakeFOV();
								inventoryClear();
							}
						}
						else {
							/* We've bumped into an NPC. */
							g_npcMap[iNewX][iNewY]->m_vFunc(ACT_WALK_INTO, iNewX, iNewY, g_npcMap[iNewX][iNewY]);
							iNewX = g_ego.m_stats.m_iWorldX;
							iNewY = g_ego.m_stats.m_iWorldY;
						}
						TCOD_map_compute_fov(g_tcodMap, g_ego.m_stats.m_iWorldX, g_ego.m_stats.m_iWorldY, (int)g_ego.m_fFOVDistance, true, FOV_SHADOW);
						TCOD_map_set_properties(g_tcodMap, iNewX, iNewY, g_itemData[g_iWorld[iNewX][iNewY]].m_stats.m_bTransparent, g_itemData[g_iWorld[iNewX][iNewY]].m_stats.m_bWalkable);
						TCOD_map_copy(g_tcodMap, g_tcodLightmap);
						mapRemapLight(25);
						playerCalcVisibility();
						bTurnOver = true;
					}
				}

				switch (cCharCode) {
					case 'q': /* Place block (why q?) */
						g_iGameMode = MODE_BLOCK;
						consoleAdd("Place where?");
						break;
					case 'o': /* Open something */
						g_iGameMode = MODE_OPEN;
						consoleAdd("Open where?");
						break;
					case 'l': /* Look around */
						g_iGameMode = MODE_LOOK;
						iLookX = g_ego.m_stats.m_iWorldX;
						iLookY = g_ego.m_stats.m_iWorldY;
						iNewX = iLookX;
						iNewY = iLookY;
						playerLook(iLookX, iLookY);
						inventoryClear();
						iInventoryOffset = 0;
						iInventoryPointer = 0;
						consoleAdd("Looking around...");
						break;
					case 'e': /* Equip selected item in inventory */
						g_itemData[iInventorySelection].m_vFunc(ACT_EQUIP, 0, 0,(void *)(iInventorySelection));
						break;
					case 'd': /* Dequip an item */
						g_iGameMode = MODE_DEQUIP;
						consoleAdd("Remove what?");
						break;
					case 14: /* Up arrow (move inventory pointer) */
						if (iInventoryPointer > 0) {
							TCOD_console_put_char(NULL, 76, 33 + iInventoryPointer, 32, TCOD_BKGND_NONE);
							iInventoryPointer--;
						}
						else
							iInventoryOffset--;
						break;
					case 17: /* Down arrow (move inventory pointer) */
						if (iInventoryPointer < 9) {
							TCOD_console_put_char(NULL, 76, 33 + iInventoryPointer, 32, TCOD_BKGND_NONE);
							iInventoryPointer++;
						}
						else
							iInventoryOffset++;
						break;
					case 64: /* Space */
						g_iGameMode = MODE_CONSOLE_INPUT;
						break;
					default:
						break;
				}
				break;
			case MODE_BLOCK:
				if (tKey.vk >= TCODK_KP1 && tKey.vk <= TCODK_KP9) {
					if (iNewX >= 0 && iNewX < DEF_WORLD_X && iNewY >= 0 && iNewY < DEF_WORLD_Y) {
						g_itemData[iItemToPlace].m_vFunc(ACT_PLACE_ONTO, iNewX, iNewY, (void *)iItemToPlace);
						mapMakeFOV();
						g_iGameMode = MODE_GAME;
						TCOD_map_compute_fov(g_tcodMap, g_ego.m_stats.m_iWorldX, g_ego.m_stats.m_iWorldY, (int)g_ego.m_fFOVDistance, true, FOV_SHADOW);
						TCOD_map_set_properties(g_tcodMap, iNewX, iNewY, g_itemData[g_iWorld[iNewX][iNewY]].m_stats.m_bTransparent, g_itemData[g_iWorld[iNewX][iNewY]].m_stats.m_bWalkable);
						TCOD_map_copy(g_tcodMap, g_tcodLightmap);
						mapRemapLight(25);
						playerCalcVisibility();
						bTurnOver = true;
					}
				}
				else {
					if (cCharCode == '1')
						iItemToPlace = ITEM_ORE_STONE;
					if (cCharCode == '2')
						iItemToPlace = ITEM_ORE_IRON;
					if (cCharCode == '3')
						iItemToPlace = ITEM_ORE_COPPER;
					if (cCharCode == '4')
						iItemToPlace = ITEM_ORE_SILVER;
					if (cCharCode == '5')
						iItemToPlace = ITEM_ORE_GOLD;
				}
				break;
			case MODE_OPEN:
				if (tKey.vk >= TCODK_KP1 && tKey.vk <= TCODK_KP9) {
					if (iNewX >= 0 && iNewX < DEF_WORLD_X && iNewY >= 0 && iNewY < DEF_WORLD_Y) {
						g_itemData[g_iWorld[iNewX][iNewY]].m_vFunc(ACT_OPEN, iNewX, iNewY, NULL);
						mapMakeFOV();
						g_iGameMode = MODE_GAME;
						TCOD_map_compute_fov(g_tcodMap, g_ego.m_stats.m_iWorldX, g_ego.m_stats.m_iWorldY, (int)g_ego.m_fFOVDistance, true, FOV_SHADOW);
						TCOD_map_set_properties(g_tcodMap, iNewX, iNewY, g_itemData[g_iWorld[iNewX][iNewY]].m_stats.m_bTransparent, g_itemData[g_iWorld[iNewX][iNewY]].m_stats.m_bWalkable);
						TCOD_map_copy(g_tcodMap, g_tcodLightmap);
						mapRemapLight(25);
						playerCalcVisibility();
						bTurnOver = true;
					}
				}
				break;
			case MODE_DEQUIP:
				switch (cCharCode) {
					case '1':
						iSelect = g_ego.m_equipment.m_iHand_L;
						g_ego.m_equipment.m_iHand_L = ITEM_NOTHING;
						break;
					case '2':
						iSelect = g_ego.m_equipment.m_iHand_R;
						g_ego.m_equipment.m_iHand_R = ITEM_NOTHING;
						break;
					case '3':
						iSelect = g_ego.m_equipment.m_iHead;
						g_ego.m_equipment.m_iHead = ITEM_NOTHING;
						break;
					case '4':
						iSelect = g_ego.m_equipment.m_iEar_L;
						g_ego.m_equipment.m_iEar_L = ITEM_NOTHING;
						break;
					case '5':
						iSelect = g_ego.m_equipment.m_iEar_R;
						g_ego.m_equipment.m_iEar_R = ITEM_NOTHING;
						break;
					case '6':
						iSelect = g_ego.m_equipment.m_iFace;
						g_ego.m_equipment.m_iFace = ITEM_NOTHING;
						break;
					case '7':
						iSelect = g_ego.m_equipment.m_iNeck;
						g_ego.m_equipment.m_iNeck = ITEM_NOTHING;
						break;
					case '8':
						iSelect = g_ego.m_equipment.m_iBack;
						g_ego.m_equipment.m_iBack = ITEM_NOTHING;
						break;
					case '9':
						iSelect = g_ego.m_equipment.m_iChest;
						g_ego.m_equipment.m_iChest = ITEM_NOTHING;
						break;
					case '0':
						iSelect = g_ego.m_equipment.m_iHands;
						g_ego.m_equipment.m_iHands = ITEM_NOTHING;
						break;
					case 'a':
						iSelect = g_ego.m_equipment.m_iWaist;
						g_ego.m_equipment.m_iWaist = ITEM_NOTHING;
						break;
					case 'b':
						iSelect = g_ego.m_equipment.m_iLegs;
						g_ego.m_equipment.m_iLegs = ITEM_NOTHING;
						break;
					case 'c':
						iSelect = g_ego.m_equipment.m_iFeet;
						g_ego.m_equipment.m_iFeet = ITEM_NOTHING;
						break;
					default:
						break;
				}
				if (iSelect != 0) {
					g_itemData[iSelect].m_vFunc(ACT_DEQUIP, 0, 0,(void *)(iSelect));
					g_iGameMode = MODE_GAME;
				}
				break;
			case MODE_LOOK:
				if (tKey.vk >= TCODK_KP1 && tKey.vk <= TCODK_KP9) {
					if (iNewX >= 0 && iNewX < DEF_WORLD_X && iNewY >= 0 && iNewY < DEF_WORLD_Y) {
						TCOD_console_put_char(NULL, iLookX, iLookY, 0, TCOD_BKGND_NONE);
						iLookX = iNewX;
						iLookY = iNewY;
						playerLook(iLookX, iLookY);
						inventoryClear();
						iInventoryOffset = 0;
						iInventoryPointer = 0;
					}
				}
				TCOD_console_put_char(NULL, iLookX, iLookY, 4, TCOD_BKGND_NONE);
				iInventorySelection = inventoryList(&g_itemLook, iInventoryPointer, iInventoryOffset);
				playerLook(iLookX, iLookY);
				break;
			case MODE_CONSOLE_INPUT:
				switch (tKey.vk) {
					case TCODK_ENTER:
						consoleAdd(g_cConsoleInput);
						consoleInputClear();
						g_iGameMode = MODE_GAME;
						break;
					case TCODK_BACKSPACE:
						consoleInputDel();
						break;
					default:
						if (cCharCode >= 32 && cCharCode <= 126)
							consoleInputAdd(cCharCode);
						break;
				}
				break;
			default:
				break;
		}

		if (bTurnOver) {
			npcExecute(&g_npcList);
			bTurnOver = false;
		}

		TCOD_console_flush();
	}
	return 1;
}
Beispiel #8
0
void map_set_walkable(int x, int y, bool is_walkable)
{
	// fourth argument is is_transparent
	TCOD_map_set_properties(tcod_map, x, y, true, is_walkable);
}