Ejemplo n.º 1
0
int CmdFullscreen::execute()
{
  TCODConsole* console = Engine::instance().getConsole();

  if ( console )
    console->setFullscreen( !console->isFullscreen() );

  return 0;
}
Ejemplo n.º 2
0
void Actor::render() const
{
	TCODConsole *offscrn = new TCODConsole(1,1);
	offscrn->setChar(0, 0, ch);
	offscrn->setCharForeground(0,0,col); 
	//offscrn->setKeyColor(TCODColor::black);
	TCODConsole::blit(offscrn,0,0,0,0,engine.mapcon,x,y,1.0,0.0);
	delete offscrn;
}
Ejemplo n.º 3
0
void ALabel::render(TCODConsole &console)
{
  console.setDefaultForeground(_color);
  console.setDefaultBackground(_bgcolor);
  console.printEx(getX(), getY(),
                  TCOD_BKGND_SET,
                  TCOD_LEFT, "%s", _value.c_str());

  if ( _autosize ) setWidth(_value.size());
}
Ejemplo n.º 4
0
void g_debugmsg(const char *mes, ...)
{
    int x = 0;
    int y = 3;
    va_list ap;
    va_start(ap, mes);
    char buff[2048];
    vsprintf(buff, mes, ap);
    va_end(ap);
    x = strlen(buff)+8; // +7 because of added DEBUG: tag
    if (x < 29) x = 29;
    TCODConsole *bugger = new TCODConsole(x, y); // should this stay preserved in GAME object?
    bugger->setAlignment(TCOD_LEFT);
    TCODConsole::setColorControl(TCOD_COLCTRL_1,TCODColor::red,TCODColor::black);
    TCODConsole::setColorControl(TCOD_COLCTRL_2,TCODColor::yellow,TCODColor::black);
    std::cout << "DEBUG: " << buff << std::endl;
    bugger->print(0,0, "%cDEBUG: %c%c%s%c", TCOD_COLCTRL_1,TCOD_COLCTRL_STOP,TCOD_COLCTRL_2, buff, TCOD_COLCTRL_STOP);
    bugger->print(0,2, "<Press a key to continue...>");
    TCODConsole::blit(bugger,0,0,x,3,TCODConsole::root, 5, 5);
    TCODConsole::flush();
    TCODConsole::waitForKeypress(true);
    delete bugger;
}
Ejemplo n.º 5
0
void PlayerAi::PrintAttributeOnCharacterSheet(TCODConsole &con, Attribute *currAttr, int32_t baseRow, int32_t baseColumn)
{
	con.setDefaultForeground(TCODColor::white);
	con.print(baseColumn, baseRow, "%s:", currAttr->GetName());
	if (currAttr->GetCurrValue() > currAttr->GetBaseValue()) {
		con.setDefaultForeground(TCODColor::green);
	} else if (currAttr->GetCurrValue() < currAttr->GetBaseValue()) {
		con.setDefaultForeground(TCODColor::red);
	}
	con.print(baseColumn + 15, baseRow, "%3d", currAttr->GetCurrValue());
	con.setDefaultForeground(TCODColor::white);
}
Ejemplo n.º 6
0
int main() {
    srand((int)time(NULL));
    cPlayer *mainPlayer = new cPlayer;

    TCODConsole::initRoot(SCREEN_WIDTH, SCREEN_HEIGHT+5, "LEVIATHAN", false, TCOD_RENDERER_SDL);

    mapData *mpShort = mainPlayer->mapDataHandle;
    if (mpShort->loaded != true) {
        if(mpShort->fileHandler->readMapData(mpShort) == 1) {
            cout<<"Failed to load map data."<<endl;
            mpShort->genNewMap();
            mpShort->fileHandler->writeMapData(mpShort);
            cout<<"Map generated and written."<<endl;
        } else {
            cout<<"Map loaded."<<endl;
        }
    }
    mpShort->genNewMap();

    TCODConsole *messages = new TCODConsole(SCREEN_WIDTH, 5);
    messages->setForegroundColor(TCODColor::red);
    messages->clear();
    int i,j;
    for (i=0;i<5;i++) {
        for (j=0;j<SCREEN_WIDTH;j++) {
            if (i==0) {
                messages->setFore(j, i, TCODColor::white);
                messages->setChar(j, i, '-');
            }
            if (i==4) {
                messages->setFore(j, i, TCODColor::white);
                messages->setChar(j, i, '-');
            }
            if (j==0) {
                messages->setFore(j, i, TCODColor::white);
                messages->setChar(j, i, '|');
            }
            if (j==SCREEN_WIDTH-1) {
                messages->setFore(j, i, TCODColor::white);
                messages->setChar(j, i, '|');
            }
            if (i==0 && (j==0 || j==SCREEN_WIDTH-1)) {
                messages->setFore(j, i, TCODColor::white);
                messages->setChar(j, i, '0');
            }
            if (i==4 && (j==0 || j==SCREEN_WIDTH-1)) {
                messages->setFore(j, i, TCODColor::white);
                messages->setChar(j, i, '0');
            }
        }
    }

    // Render once before everything, because we handle
    // keypresses first
    render(mainPlayer, messages);

    // Main loop
    while(1) {
        // See if we should be closed
        if (TCODConsole::isWindowClosed())
            break;

        if (mainPlayer->health <= 0) {
            // Losing condition:
            TCODConsole::root->setForegroundColor(TCODColor::white);
            TCODConsole::root->clear();
            /*for (int fade=255;fade >= 0;fade--) {
                TCODConsole::setFade(fade,TCODColor::black);
                TCODConsole::flush();
                Sleep(200);
            }*/
            string end = "You are dead.";
            TCODConsole::root->printEx(SCREEN_WIDTH/2-(sizeof("You are dead.")/2),
                SCREEN_HEIGHT/2, TCOD_BKGND_NONE, TCOD_LEFT, end.c_str());
            TCODConsole::flush();

            TCODConsole::waitForKeypress(true);
            break;
        } else if (keyHandler(mainPlayer) == -1) {
            break;
        }

        // Render everything
        render(mainPlayer, messages);
    }

    delete mainPlayer;
    delete messages;
    return 0;
}
Ejemplo n.º 7
0
void render(cPlayer *mainPlayer, TCODConsole *messages) {
    int i, j;
    // Shorten this shit up a bit:
    mapData *mpShort = mainPlayer->mapDataHandle;

    TCODConsole *offscreenConsole = new TCODConsole(SCREEN_WIDTH,SCREEN_HEIGHT);
    offscreenConsole->setForegroundColor(TCODColor::blue);
    offscreenConsole->clear(); // Flush the new changes to the offscreen console

    // Check if we have loaded the current cell yet:
    if (mpShort->loaded != true) {
        //if(mpShort->fileHandler->readMapData(mpShort) == 1) {
        //    cout<<"Failed to load map data."<<endl;
            mpShort->clearMap();
            mpShort->genNewMap();
        //    mpShort->fileHandler->writeMapData(mpShort);
        //    cout<<"Map generated and written."<<endl;
        //} else {
        //    cout<<"Map loaded."<<endl;
        //}
    }

    mainPlayer->updateFOV();
    // Map renderer:
    for (i=0;i<SCREEN_WIDTH;i++) {
        for (j=0;j<SCREEN_HEIGHT;j++) {
            if (mainPlayer->myFOV->isInFov(i, j)) {
                // If it is in the Field of View, make sure it has been explored now:
                mpShort->mapHandlerMaster[i][j].isExplored = true;

                float distance = (float)((i - mainPlayer->pos[0]) * (i - mainPlayer->pos[0]) + 
                    (j - mainPlayer->pos[1]) * (j - mainPlayer->pos[1]));
                float squaredTorchRadius = (float)(mainPlayer->lightRadius * mainPlayer->lightRadius);

				if(distance < squaredTorchRadius) {
                    float lerpVal = (squaredTorchRadius - distance) / squaredTorchRadius;
                    lerpVal = CLAMP(0.1f, 1.0f, lerpVal);
                    TCODColor foreColor = mpShort->mapHandlerMaster[i][j].foreColor * mainPlayer->lightColor * lerpVal;
					TCODColor backColor = mpShort->mapHandlerMaster[i][j].backColor * mainPlayer->lightColor * lerpVal;
                    offscreenConsole->setFore(i, j, foreColor);
                    offscreenConsole->setBack(i, j, backColor);
                    offscreenConsole->setChar(i, j, mpShort->mapHandlerMaster[i][j].graphic);
                }
            } else if(mpShort->mapHandlerMaster[i][j].isExplored) {	// If the tile is not in fov, but has been seen before...
				offscreenConsole->setFore(i, j, mpShort->mapHandlerMaster[i][j].foreColor * 0.1f);
                offscreenConsole->setBack(i, j, mpShort->mapHandlerMaster[i][j].backColor * 0.1f);
                offscreenConsole->setChar(i, j, mpShort->mapHandlerMaster[i][j].graphic);
			} else {	// And if the tile has never been seen, we just black it out.
				offscreenConsole->putCharEx(i, j, ' ', TCODColor::black, TCODColor::black);
            }
        }
    }

    // Entity renderer:
    entity *loop = mainPlayer->mapDataHandle->masterList->head;
    while (loop != NULL) {
        // We have entities to render:
        if (mainPlayer->myFOV->isInFov(loop->pos[0], loop->pos[1])) {
            float distance = (float)((loop->pos[0] - mainPlayer->pos[0]) * (loop->pos[0] - mainPlayer->pos[0]) + 
                    (loop->pos[1] - mainPlayer->pos[1]) * (loop->pos[1] - mainPlayer->pos[1]));
            float squaredTorchRadius = (float)(mainPlayer->lightRadius * mainPlayer->lightRadius);

			if(distance < squaredTorchRadius) {
                float lerpVal = (squaredTorchRadius - distance) / squaredTorchRadius;
                lerpVal = CLAMP(0.1f, 1.0f, lerpVal);
                TCODColor foreColor = loop->myColor * mainPlayer->lightColor * lerpVal;
                offscreenConsole->setFore(loop->pos[0], loop->pos[1], foreColor);
                offscreenConsole->setChar(loop->pos[0], loop->pos[1], loop->myChar);

                // Compute the path stuff for the entity:
                loop->myPath->compute(loop->pos[0], loop->pos[1], mainPlayer->pos[0], mainPlayer->pos[1]);
                // See if we are one space away from the player, and attack him if we are:
                int qX=0, qY=0;
                loop->myPath->walk(&qX, &qY, true);
                if (qX == mainPlayer->pos[0] && qY == mainPlayer->pos[1]) {
                    loop->attack(mainPlayer);
                } else {
                    loop->pos[0] = qX;
                    loop->pos[1] = qY;
                }
            }
        }
        
        loop = loop->next;
    }

    // Some random event stuff:
    if (mainPlayer->turns == mainPlayer->nextRand) {
        mainPlayer->mapDataHandle->randChanges(mainPlayer);
        mainPlayer->nextRand = mainPlayer->turns+=rand() % 300;
    }

    // Noise stuff:
    if (mainPlayer->isSnowing)
        mpShort->noise(snow, offscreenConsole, mainPlayer);
    
    // Render the player last
    offscreenConsole->setFore(mainPlayer->pos[0], mainPlayer->pos[1], mainPlayer->myColor);
    offscreenConsole->setChar(mainPlayer->pos[0], mainPlayer->pos[1], '@');

    // Blit all that crap on-screen
    TCODConsole::blit(offscreenConsole,0,0,SCREEN_WIDTH,SCREEN_HEIGHT,TCODConsole::root,0,0, 1.0f, 1.0f);

    // Messages:
    // clear and remake the window:
    for (i=1;i<4;i++) {
        for (j=1;j<(SCREEN_WIDTH-1);j++) {
            messages->setChar(j, i, ' ');
        }
    }

    for (i=0;i<3;i++) {
        std::ostringstream temp;
        temp <<"%c"<<mainPlayer->messagesHandle[i]<<"%c";
        TCODConsole::setColorControl(TCOD_COLCTRL_1,mainPlayer->messageColors[i],TCODColor::black);
        messages->printEx(1, (i+1), TCOD_BKGND_NONE, TCOD_LEFT, temp.str().c_str(),TCOD_COLCTRL_1,TCOD_COLCTRL_STOP);
    }
    TCODConsole::blit(messages, 0, 0, SCREEN_WIDTH, 5, TCODConsole::root, 0, SCREEN_HEIGHT);
    
    // Flip it
    TCODConsole::root->flush();

    delete offscreenConsole;
}