void editorLoad(const char* fn, SDL_Surface* screen) { //Set filename editorFileName(fn); //Init cursor initCursor(&cur); //Read info's for level. pf.levelInfo = mkLevelInfo( fn ); //Load field loadField(&pf, fileName); initDraw(pf.levelInfo, screen); SDL_FreeSurface(stealGfxPtr()->boardImg); stealGfxPtr()->boardImg = loadImg( DATADIR"data/editbg.png" ); selBrickBG = loadImg( DATADIR"data/editselbrick.png" ); saveBtnBG = loadImg( DATADIR"data/edit-save.png" ); saveBtnSprite = cutSprite( saveBtnBG, 0,0, saveBtnBG->w, saveBtnBG->h ); changed=0; selBrick=BRICKSBEGIN; teleState=0; fieldRect.x = HSCREENW - 74; fieldRect.y = HSCREENH - 114; fieldRect.w = HSCREENW + 154; fieldRect.h = HSCREENH + 114; }
void selectionUpdate(const string &title, const string &first, const string &second){ if(selectionIdxTexture[0] == 0) selectionIdxTexture[0] = loadImg("res/selection0.png"); if(selectionIdxTexture[1] == 0) selectionIdxTexture[1] = loadImg("res/selection1.png"); SDL_Surface *selectionSurface = IMG_Load("res/selection.png"); SDL_Color white, black; white.r = white.g = white.b = 0xFF; black.r = black.g = black.b = 0x00; SDL_Surface *titleText = TTF_RenderUTF8_Blended(font, title.c_str(), white); SDL_Rect rTitle = {6,5,0,0}; SDL_BlitSurface(titleText, NULL, selectionSurface, &rTitle); SDL_FreeSurface(titleText); SDL_Surface *firstText = TTF_RenderUTF8_Blended(font, first.c_str(), black); SDL_Rect rFirst = {60,67,0,0}; rFirst.x -= firstText->w/2; SDL_BlitSurface(firstText, NULL, selectionSurface, &rFirst); SDL_FreeSurface(firstText); SDL_Surface *secondText = TTF_RenderUTF8_Blended(font, second.c_str(), black); SDL_Rect rSecond = {195,67,0,0}; rSecond.x -= secondText->w/2; SDL_BlitSurface(secondText, NULL, selectionSurface, &rSecond); SDL_FreeSurface(secondText); selectionTexture = genTexture(selectionSurface, selectionTexture); SDL_FreeSurface(selectionSurface); }
void loginWindowUpdate(const string &username, int pwdLen){ if(loginSelectTexture[0] == 0) loginSelectTexture[0] = loadImg("res/loginsel0.png"); if(loginSelectTexture[1] == 0) loginSelectTexture[1] = loadImg("res/loginsel1.png"); if(loginSelectTexture[2] == 0) loginSelectTexture[2] = loadImg("res/loginsel2.png"); if(loginSurface == NULL){ loginSurface = IMG_Load("res/login.png"); SDL_Color white, black; white.r = white.g = white.b = 0xFF; black.r = black.g = black.b = 0x00; SDL_Surface *titleText = TTF_RenderUTF8_Blended(font, "Login", white); SDL_Rect rTitle = {6,5,0,0}; SDL_BlitSurface(titleText, NULL, loginSurface, &rTitle); SDL_FreeSurface(titleText); SDL_Surface *userLblText = TTF_RenderUTF8_Blended(font, "Usuario:", black); SDL_Rect rUserLbl = {8,35,0,0}; SDL_BlitSurface(userLblText, NULL, loginSurface, &rUserLbl); SDL_FreeSurface(userLblText); SDL_Surface *passLblText = TTF_RenderUTF8_Blended(font, "Password:"******"Aceptar", black); SDL_Rect rButton = {128,107,0,0}; rButton.x -= buttonText->w/2; rButton.y -= buttonText->h/2; SDL_BlitSurface(buttonText, NULL, loginSurface, &rButton); SDL_FreeSurface(buttonText); loginTexture = genTexture(loginSurface, loginTexture); } SDL_Color black; black.r = black.g = black.b = 0x00; SDL_Surface *tempSurface = SDL_ConvertSurface(loginSurface, loginSurface->format, loginSurface->flags); SDL_Surface *userNameText = TTF_RenderUTF8_Blended(font, username.c_str(), black); SDL_Rect rUserName = {91,35,0,0}; SDL_BlitSurface(userNameText, NULL, tempSurface, &rUserName); SDL_FreeSurface(userNameText); string tempPass; for(int i=0;i<pwdLen;i++) tempPass += '*'; SDL_Surface *passWordText = TTF_RenderUTF8_Blended(font, tempPass.c_str(), black); SDL_Rect rPassWord = {91,67,0,0}; SDL_BlitSurface(passWordText, NULL, tempSurface, &rPassWord); SDL_FreeSurface(passWordText); loginTexture = genTexture(tempSurface, loginTexture); SDL_FreeSurface(tempSurface); }
void alertShow(char *text, char *title){ if(alertSelectTexture == 0) alertSelectTexture = loadImg("res/alertsel0.png"); gameStatePrev = gameState; gameState = gameStates::alert; SDL_Surface *alertSurface = IMG_Load("res/alert.png"); SDL_Color white, black; white.r = white.g = white.b = 0xFF; black.r = black.g = black.b = 0x00; SDL_Surface *titleText = TTF_RenderUTF8_Blended(font, title, white); SDL_Rect rTitle = {6,5,0,0}; SDL_BlitSurface(titleText, NULL, alertSurface, &rTitle); SDL_FreeSurface(titleText); SDL_Surface *bodyText = TTF_RenderUTF8_Blended(font, text, black); SDL_Rect rBody = {8,30,0,0}; SDL_BlitSurface(bodyText, NULL, alertSurface, &rBody); SDL_FreeSurface(bodyText); SDL_Surface *buttonText = TTF_RenderUTF8_Blended(font, "Aceptar", black); SDL_Rect rButton = {128,106,0,0}; rButton.x -= buttonText->w/2; rButton.y -= buttonText->h/2; SDL_BlitSurface(buttonText, NULL, alertSurface, &rButton); SDL_FreeSurface(buttonText); alertTexture = genTexture(alertSurface, alertTexture); SDL_FreeSurface(alertSurface); }
void Assets::init() { if(bInited) return; loadImg(PARTICLE); bInited = true; }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); this->setWindowTitle("Barcode Decoder"); this->timer = new QTimer(this); //QPainter *painter = new QPainter(this); Camera *camera = new Camera(); Process *process = new Process(); process->moveToThread(&decodeThread); decodeThread.start(); camera->moveToThread(&cameraThread); cameraThread.start(); connect(timer , SIGNAL(timeout()) , camera , SLOT(imgRequest()) ); connect(camera, SIGNAL(sendImg(cv::Mat)) , ui->play , SLOT(loadImg(cv::Mat)) ); connect(camera, SIGNAL(sendImg(cv::Mat)) , process , SLOT(getImgAndProcess(cv::Mat)) ); connect(process, SIGNAL(sendIsBarcaode(bool)) , ui->play , SLOT(slotIsBarcodeLocated(bool)) ); connect(process, SIGNAL(sendLoc(cv::Rect)) , ui->play , SLOT(slotGetBarcodeLocation(cv::Rect)) ); connect(process, SIGNAL(sendBarcodeImg(cv::Mat)) , this , SLOT(updateBarcodeImg(cv::Mat)) ); connect(process, SIGNAL(sendBarcode(QString)) , this , SLOT(updateBarcode(QString)) ); connect(ui->close, SIGNAL(pressed()) , ui->play, SLOT(cleanScrean()) ); connect(ui->start, SIGNAL(pressed()) , ui->play, SLOT(startDisplay()) ); //connect(ui->checkBox, SIGNAL(stateChanged(int)) , camera , SLOT(autofocus(int)) ); connect(ui->focusValue, SIGNAL(sliderReleased()) , this , SLOT(getSliderValue()) ); //connect(this , SIGNAL(focusNum(int)) , camera , SLOT(focusValue(int)) ); connect(ui->checkBox , SIGNAL(clicked(bool)) , ui->focusValue, SLOT(setEnabled(bool)) ); //connect(camera , SIGNAL(cameraCheck(bool)) , this , SLOT(slotCameraCheck(bool)) ); //connect(ui->start, SIGNAL(pressed()) , camera , SLOT(autoFocusCheck()) ); connect(ui->start, SIGNAL(pressed()) , camera , SLOT(sendID()) ); connect(camera, SIGNAL(cameraID(int)) , this, SLOT(checkCamera(int)) ); connect(this , SIGNAL(focusNum(int)) , this, SLOT(setCameraFocusValue(int)) ); connect(ui->checkBox , SIGNAL(stateChanged(int)) , this , SLOT(setFocusStatus(int)) ); //camera->autoFocusCheck(); ui->close->setEnabled(false); ui->checkBox->setEnabled(false); ui->focusValue->setEnabled(false); this->cameraFocus = false; //this->timer->start(33);//using timer to trigger update }
WindowGUI::WindowGUI( QWidget *parent ) : QMainWindow( parent ){ //@TODO //try to consider better GUI for showing and manipulating img //e.g put image into scrollbar or sth, add window QMenu + QActions //thanks to c++11 new feature - default initialization by member ( by new ) //create objects in declaration, so no need to do that - simpler construcor //quitBut = new QPushButton( tr( "Quit" ) ); //openBut = new QPushButton( tr("Open" ) ); //binarizeBut = new QPushButton( tr("Binarize") ); //clusterBut = new QPushButton( tr("Cluster") ); //imgLab = new QLabel( tr("Your Image to Process") ); //mainWid = new QWidget; //mainLay = new QVBoxLayout; qDebug() << "Conctructor WindowGUI \n"; clusterBut->setEnabled( false ); binarizeBut->setEnabled( false ); connect( quitBut, SIGNAL( clicked() ), this, SLOT( close() ) ); connect( openBut, SIGNAL( clicked() ), this, SLOT( loadImg() ) ); connect( binarizeBut, SIGNAL( clicked() ), this, SLOT( toBinImg() )); connect( clusterBut, SIGNAL( clicked() ), this, SLOT( toClusterImg() )); imgLab->setSizePolicy( QSizePolicy::Ignored, QSizePolicy::Ignored ); imgLab->setScaledContents( true ); mainLay->addWidget( imgLab ); mainLay->addWidget( openBut ); mainLay->addWidget( binarizeBut ); mainLay->addWidget( clusterBut ); mainLay->addWidget( quitBut ); mainWid->setLayout( mainLay ); this->setCentralWidget( mainWid ); resize( 600, 500 ); setWindowTitle( tr("Projective Clustering" ) ); }
void initPointer(SDL_Surface* screen) { //Load the "escape" overlay image ptrBackImg = loadImg(DATADIR"data/ptr-back.png"); if( !ptrBackImg ) printf("Couldn't open %s\n",DATADIR"data/ptr-back.png"); ptrBackRect.x=HSCREENW-160;; ptrBackRect.y=HSCREENH-120;; ptrBackRect.w=ptrBackRect.x+ptrBackImg->w; ptrBackRect.h=ptrBackRect.y+ptrBackImg->h; backBtnDstRect.x = HSCREENW-160; backBtnDstRect.y = HSCREENH-120; memset( &inpPointer, 0, sizeof(inpPointerState_t) ); inpPointer.timeSinceMoved=POINTER_SHOW_TIMEOUT; //The color white inpPointer.colWhite = SDL_MapRGBA( screen->format, 255,255,255,255 ); }
int initDraw(levelInfo_t* li, SDL_Surface* screen) { char tempStr[512]; int i,x,y; //Background image graphics.boardImg = loadImg( packGetFile("themes",li->bgFile) ); if(!graphics.boardImg) { printf("Couldn't load board file:'%s'\n", packGetFile("themes",li->bgFile) ); cleanUpDraw(); return(0); } //Tileset sprintf(tempStr, "%s.png", li->tileBase); graphics.tileImg = loadImg( packGetFile("themes",tempStr) ); if(!graphics.tileImg) { printf("Couldn't load tile file:'%s'\n", packGetFile("themes",tempStr) ); cleanUpDraw(); return(0); } //Cut tiles into sprites for(i=0; i < NUMTILES; i++) { graphics.tiles[i] = cutSprite(graphics.tileImg, i*20, 0, 20,20); } //Single wall (Override tile15 in graphics.tiles) sprintf(tempStr, "%s.png", li->wallBase); graphics.wallImg = loadImg( packGetFile("themes",tempStr) ); if(!graphics.wallImg) { printf("Couldn't load wall file:'%s'\n", packGetFile("themes",tempStr) ); cleanUpDraw(); return(0); } //Override wall tile free(graphics.tiles[15]); graphics.tiles[15] = cutSprite(graphics.wallImg,0,0,20,20); //Extra walls, if they exist, if they don't, default to tile 6 (from 0) in tiles. sprintf(tempStr, "%s-extra.png", li->wallBase); graphics.wallsImg = loadImg( packGetFile("themes",tempStr) ); if(!graphics.wallsImg) printf("Optional GFX missing: '%s'\n", packGetFile("themes",tempStr) ); int r,c; //rows, column, sprite index i=0; for(r=0; r < 5; r++) { for(c=0; c < 3; c++) { if(graphics.wallsImg) { //Cut out from sheet x=c*20; y=r*20; graphics.walls[i] = cutSprite(graphics.wallsImg, x,y, 20, 20); } else { //Default to the freestanding wall graphics.walls[i] = cutSprite(graphics.wallImg, 0, 0, 20, 20); } i++; } } //Above loop leaves when i==15. //Middle-free is 15 = default tile index in image is 15 (starting from 0). graphics.walls[15] = cutSprite(graphics.wallImg, 0, 0, 20, 20); //Explosions, reuse R as frame number index for(i=0; i < BRICKSEND; i++) { //Open explosion sprintf(tempStr, "%s%02i.png", li->explBase, i); graphics.explImg[i] = loadImg( packGetFile("themes",tempStr) ); if(!graphics.explImg[i] && i==0) printf("Couldn't open '%s'\n",packGetFile("themes",tempStr) ); if(graphics.explImg[i]) graphics.brickExpl[i] = mkAni(graphics.explImg[i], 30,30, 0); else graphics.brickExpl[i] = mkAni(graphics.explImg[0], 30,30, 0); } //Per-Tile animations for(i=0; i < NUMTILES; i++) { sprintf(tempStr, "%s-tile%02i.png", li->tileBase, i); graphics.aniImg[i] = loadImg( packGetFile("themes",tempStr) ); graphics.tileAni[i] = mkAni(graphics.aniImg[i], 30,30, 80); } //Cursor graphics.curImg = loadImg( packGetFile( "themes/cursors",li->cursorFile) ); if( !graphics.curImg ) { printf("Warning: Couldn't find cursor '%s'\n", packGetFile( "themes/cursors",li->cursorFile)); } graphics.curSpr[0] = cutSprite(graphics.curImg, 0, 0, 28,28); graphics.curSpr[1] = cutSprite(graphics.curImg, 28, 0, 28,28); //Load countdown graphics.countDownImg = loadImg( packGetFile(".","countdown.png") ); if(!graphics.countDownImg) { printf("Error(5): couldn't load '%s'\n",packGetFile(".","countdown.png")); return(0); } //Cut countdown for(i=0; i < 4; i++) { graphics.countDownSpr[i] = cutSprite(graphics.countDownImg, 0,i*60, 140,60); } //Teleport path animation color gradient graphics.teleColorIndex=0; float f=255/TELEPATHNUMCOL; for(i=0; i < TELEPATHNUMCOL; i++) { graphics.teleColorTable[i] = SDL_MapRGB( screen->format, 0,(int)(255.0-(float)i*f),0 ); } return(1); }
int initGame(SDL_Surface* screen) { if(player()->gameStarted) { printf("ERROR: Called init when a game was running\n"); return(0); } //Only load the back-image once. if( !ptrRestart ) { ptrRestart = loadImg( DATADIR"data/ptr-restart.png" ); ptrRestartRect.x=HSCREENW-160; ptrRestartRect.w=ptrRestartRect.x+ptrRestart->w; ptrRestartRect.y=HSCREENH+120-ptrRestart->h; ptrRestartRect.h=ptrRestartRect.y+ptrRestart->h; } debugNumInit++; initCursor(&cur); restartConfirm=0; //Read info's for level. (this is done instead of using the one in packInfo so it don't need resetting) pf.levelInfo = mkLevelInfo( player()->levelFile ); if(!loadField(&pf, player()->levelFile )) { printf("Error: Couldn't init playfield.\n"); return(0); } if(!initDraw(pf.levelInfo,screen)) { printf("Error: Couldn't init graphics.\n"); return(0); } char* buf = malloc(sizeof(char)*128); sprintf(buf, "themes/%s",pf.levelInfo->soundDir); loadSamples( buf, levelInfo( player()->level)->musicFile ); //Load samples from sounddir, note we use the levelInfo from packInfo for the music since the playlist is hacked onto that. free(buf); txtLoadGameCharSet( pf.levelInfo->fontName ); pf.levelInfo->time *= 1000; //Convert seconds to ms countdown=500; countdownSeconds=3; gameState=GAMESTATECOUNTDOWN; player()->gameStarted=1; //Clear player stats memset( &player()->hsEntry, 0, sizeof( hsEntry_t ) ); //Set the levelNum player()->hsEntry.levelNum = player()->level; startStopImg=0; if(pf.levelInfo->startImg) { gameState=GAMESTATESTARTIMAGE; } //We also simulate the first switch tick here so all looks right at the countdown. switchUpdateAll( &pf ); justWon=0; return(1); }
int runGame(SDL_Surface* screen) { if(gameState==GAMESTATEPLAYING) { getInpPointerState()->escEnable=1; //Handle input int lim=1; //Limit cursor travel... int goUp=0, goDown=0, goLeft=0, goRight=0; if( getButton( C_UP ) ) { restartConfirm=0; if( getBtnTime( C_UP ) > REPEATDELAY ) { goUp=1; } else if(getBtnTime(C_UP)==0) { goUp=1; lim=0; } } if( getButton( C_DOWN ) ) { restartConfirm=0; if( getBtnTime( C_DOWN ) > REPEATDELAY ) { goDown=1; } else if(getBtnTime(C_DOWN)==0) { goDown=1; lim=0; } } if( getButton( C_LEFT ) ) { restartConfirm=0; if( getBtnTime( C_LEFT ) > REPEATDELAY ) { goLeft=1; } else if(getBtnTime(C_LEFT)==0) { goLeft=1; lim=0; } } if( getButton( C_RIGHT ) ) { restartConfirm=0; if( getBtnTime( C_RIGHT ) > REPEATDELAY ) { goRight=1; } else if(getBtnTime(C_RIGHT)==0) { goRight=1; lim=0; } } //Pause ? if( getButton( C_BTNMENU ) || isPointerEscapeClicked() ) { resetBtn( C_BTNMENU ); gamePause(screen); return(STATEMENU); } //Retry if( getButton( C_BTNSELECT ) || (getInpPointerState()->timeSinceMoved<POINTER_SHOW_TIMEOUT && isBoxClicked(&ptrRestartRect)) ) { resetBtn( C_BTNSELECT ); resetMouseBtn(); if(!restartConfirm) { restartConfirm=1; } else if(restartConfirm) { gameRestart(screen); } } //Handle mouse input if( getInpPointerState()->timeSinceMoved==0 && !cur.lock ) { setCursor(&cur, getInpPointerState()->curX,getInpPointerState()->curY ); } if(!getInpPointerState()->isDown) { mouseGrab=0; //Allow moving the cursor around with the input device when no brick is below, just for effect } else { brickType* b=brickUnderCursor(&pf, cur.x,cur.y); //We're over a brick, tell curser it's position, it will be locked later because we grab it now if( b ) { getInpPointerState()->startX=b->dx; getInpPointerState()->startY=b->dy; if( !cur.lock ) { mouseGrab=1; getInpPointerState()->startX=getInpPointerState()->curX; getInpPointerState()->startY=getInpPointerState()->curY; } else { if( b->dx > getInpPointerState()->curX ) { //Drag Left if( b->dx == b->sx && getInpPointerState()->startX != getInpPointerState()->curX ) { goLeft=1; } } else if( b->dx < getInpPointerState()->curX ) { //Drag Right if( b->dx == b->sx && getInpPointerState()->startX != getInpPointerState()->curX ) { goRight=1; } } } } else { mouseGrab=0; } } // printf("x:%i\n", getInpPointerState()->curX ); //Drag if( getButton( C_BTNX ) || getButton( C_BTNB ) || mouseGrab || isPointerClicked() ) { //Remove "Restart" question restartConfirm=0; //Magnet to brick if it's moving brickType* b=brickUnderCursor(&pf, cur.dx, cur.dy); if( !cur.lock && b ) { //Attach cursor cur.lock=1; b->curLock=1; cur.x=cur.dx; cur.y=cur.dy; cur.px = b->pxx-4; cur.py = b->pxy-4; sndPlay( SND_BRICKGRAB, cur.px ); } int movedBrick=0; //We're holding a brick, and it's not falling if( b ) { if( (goRight && curMoveBrick(&pf,b, DIRRIGHT)) || (goLeft && curMoveBrick(&pf,b, DIRLEFT)) ) { movedBrick=1; b->curLock=1; cur.lock=1; } } //Moved brick if(movedBrick) { player()->hsEntry.moves++; sndPlay(SND_BRICKMOVE, cur.px); ps.layer=PSYS_LAYER_TOP; ps.x=b->pxx; ps.y=b->pxy+18; ps.vel=50; ps.life=500; ps.lifeVar=250; ps.gravity=1; ps.srcImg=stealGfxPtr()->tiles[b->type-1]->img; ps.srcRect=stealGfxPtr()->tiles[b->type-1]->clip; ps.srcRect.y += 18; ps.srcRect.h = 2; spawnParticleSystem(&ps); } } else { cur.lock=0; } if(!cur.lock) { if( goLeft ) moveCursor(&cur, DIRLEFT, 0, lim); if( goRight ) moveCursor(&cur, DIRRIGHT, 0, lim); if( goUp ) moveCursor(&cur, 0, DIRUP, lim); if( goDown ) moveCursor(&cur, 0, DIRDOWN, lim); } //Sim first, so moving blocks get evaluated before getting moved again simField(&pf, &cur); //Do rules int ret=doRules(&pf); //Draw scene draw(&cur,&pf, screen); //Draw a path to show where we are pulling the brick if( mouseGrab ) drawPath( screen, getInpPointerState()->startX,getInpPointerState()->startY,getInpPointerState()->curX,getInpPointerState()->startY,1 ); //If no more bricks, countdown time left. if(ret == NOBRICKSLEFT) { if( !justWon ) { sndPlay(SND_WINNER,160); } justWon++; pf.levelInfo->time -= 1000; player()->hsEntry.score +=1; if(getButton(C_BTNX) || getButton(C_BTNB) || isPointerClicked() ) { resetBtn(C_BTNX); resetBtn(C_BTNB); resetMouseBtn(); while(pf.levelInfo->time > 0) { player()->hsEntry.score +=1; pf.levelInfo->time -= 1000; } } if(justWon > 50) { sndPlayOnce(SND_SCORECOUNT, 160); } if(pf.levelInfo->time < 1) { //Completed level player()->timeouts=0; pf.levelInfo->time=0; sndPlay(SND_VICTORY, 160); if(!player()->inEditor) { //Don't submit if it was from the leveleditor statsSubmitBest(); setMenu(menuStateFinishedLevel); if(pf.levelInfo->stopImg) { gameState=GAMESTATESTOPIMAGE; return(STATEPLAY); } } else { setLevelCompletable(pf.levelInfo->file, 1); } cleanUpGame(); startTransition(screen, TRANSITION_TYPE_ROLL_IN, 700); return(STATEMENU); } } else if(ret > 0) //Player destroyed bricks. { if(ret > 2) //Check for combo's { ///TODO: Some nice text effect? How about dissolving an image into a particle system? printf("%i Combo!\n",ret); player()->hsEntry.combos++; } player()->hsEntry.score += ret*ret*11*(player()->level+1); } //if ret > -1 then ret == number of bricks destroyed if(ret>-1) { //Update time: pf.levelInfo->time -= getTicks(); player()->hsEntry.time += getTicks(); if(pf.levelInfo->time < 1 && ret!=NOBRICKSLEFT ) { countdown=4000; gameState=GAMESTATEOUTOFTIME; if( !player()->inEditor ) { player()->timeouts++; } sndPlay(SND_TIMEOUT, 160); } } //Check if level is unsolvable. if(ret==UNSOLVABLE) { countdown=2000; gameState=GAMESTATEUNSOLVABLE; if( !player()->inEditor ) { player()->timeouts++; } sndPlay(SND_LOSER, 160); } else if(ret==LIFELOST) { countdown=2000; gameState=GAMESTATELIFELOST; if( !player()->inEditor ) { player()->timeouts++; } sndPlay(SND_LOSER, 160); } //Draw question if(restartConfirm) { sprintf(buf,STR_GAME_RESTARTWARNING); txtWriteCenter(screen, GAMEFONTMEDIUM, buf, HSCREENW, HSCREENH-20); sprintf(buf,STR_GAME_RESTARTCONFIRM); txtWriteCenter(screen, GAMEFONTSMALL, buf, HSCREENW, HSCREENH); } else { //Draw text drawUi(screen); } //Show the restart icon if(getInpPointerState()->timeSinceMoved<POINTER_SHOW_TIMEOUT && getInpPointerState()->escEnable) { SDL_Rect ptrRestartRectC = ptrRestartRect; SDL_BlitSurface( ptrRestart,NULL, screen, &ptrRestartRectC ); } } else if(gameState==GAMESTATECOUNTDOWN) { draw(&cur,&pf, screen); countdown -=getTicks(); if( getButton( C_BTNMENU ) ) { resetBtn( C_BTNMENU ); countdownSeconds=0; countdown=0; } if( (getButton( C_BTNX ) || getButton( C_BTNB ) || getInpPointerState()->isDown ) && countdownSeconds ) { countdownSeconds=0; countdown=500; } drawShowCountDown(screen, countdownSeconds); drawUi(screen); if(countdown < 1) { countdown=1000; countdownSeconds--; if(countdownSeconds == -1) { gameState=GAMESTATEPLAYING; return(STATEPLAY); } if(countdownSeconds==0) { countdown=500; sndPlay(SND_START, 160); } else { sndPlay(SND_COUNTDOWNTOSTART, 160); } } } else if(gameState==GAMESTATEOUTOFTIME) //Menu was last in "Entering level" so it will return to that if timeout { draw(&cur,&pf, screen); //drawUi(screen); countdown-=getTicks(); //Offer to skip after dying twice on same level, but only if it is not the last level in the pack. if( player()->timeouts > 1 && player()->level+1 < getNumLevels() ) { int skipLevel = skipLevelDialog(screen); if( skipLevel==1 ) { gameState=GAMESTATESKIPLEVEL; countdown=500; } txtWriteCenter(screen, GAMEFONTMEDIUM, STR_GAME_OUTOFTIME, HSCREENW,HSCREENH-24-31); } else { if( lostLifeMsg(&cur, &pf, screen, STR_GAME_OUTOFTIME, "lostlife-timeout" ) ) { return(STATEMENU); } } } else if(gameState==GAMESTATEUNSOLVABLE) //The same as out-of-time, but with another graphics. { draw(&cur,&pf, screen); //drawUi(screen); countdown-=getTicks(); //Offer to skip after dying twice on same level, but only if it is not the last level in the pack. if( player()->timeouts > 1 && player()->level+1 < getNumLevels() ) { int skipLevel = skipLevelDialog(screen); if( skipLevel==1 ) { gameState=GAMESTATESKIPLEVEL; countdown=500; } txtWriteCenter(screen, GAMEFONTMEDIUM, buf, HSCREENW,HSCREENH-24-31); } else { if( lostLifeMsg(&cur, &pf, screen, STR_GAME_UNSOLVABLE, "lostlife-unsolvable" ) ) { return(STATEMENU); } } } else if(gameState==GAMESTATELIFELOST) { if( lostLifeMsg(&cur, &pf, screen, STR_GAME_LOSTLIFE, "lostlife-evilbrick" ) ) { return(STATEMENU); } } else if(gameState==GAMESTATESTARTIMAGE) { if(!startStopImg) { startStopImgCounter=0; startStopImg = loadImg( packGetFile("themes/", pf.levelInfo->startImg) ); if(!startStopImg) { printf("Couldn't load '%s'\n",packGetFile("themes/", pf.levelInfo->startImg)); } } startStopImgCounter+=getTicks(); if((startStopImgCounter > 500 && ( getButton(C_BTNB) || isPointerClicked() ) ) || !startStopImg) { if(startStopImg) SDL_FreeSurface(startStopImg); startStopImg=0; resetBtn(C_BTNB); resetMouseBtn(); gameState=GAMESTATECOUNTDOWN; } SDL_BlitSurface( startStopImg, 0, screen, &(setting()->bgPos) ); if(startStopImgCounter>4000) txtWriteCenter(screen, GAMEFONTSMALL, STR_GAME_PRESSB, HSCREENW,HSCREENH+80); } else if(gameState==GAMESTATESTOPIMAGE) { if(!startStopImg) { startStopImgCounter=0; startStopImg = loadImg( packGetFile("themes/", pf.levelInfo->stopImg) ); if(!startStopImg) { printf("Couldn't load '%s'\n",packGetFile("themes/", pf.levelInfo->stopImg)); } } startStopImgCounter+=getTicks(); if((startStopImgCounter > 500 && (getButton(C_BTNB) || isPointerClicked() ) ) || !startStopImg) { if(startStopImg) SDL_FreeSurface(startStopImg); startStopImg=0; resetBtn(C_BTNB); resetMouseBtn(); cleanUpGame(); startTransition(screen, TRANSITION_TYPE_ROLL_IN, 700); return(STATEMENU); } SDL_BlitSurface( startStopImg, 0, screen, &(setting()->bgPos) ); if(countdownSeconds>4000) txtWriteCenter(screen, GAMEFONTSMALL, STR_GAME_PRESSB, HSCREENW,HSCREENH+80); } else if(gameState==GAMESTATESKIPLEVEL) { doRules(&pf); simField(&pf, &cur); draw(&cur,&pf, screen); countdown-=getTicks(); if( countdown < 1 ) { countdown=500; if( boardDestroyNextBrick(&pf) == 0 ) { //Tell that we chose to skip level statsUpload(player()->level, player()->hsEntry.time, player()->hsEntry.moves,player()->hsEntry.combos,player()->hsEntry.score, "skip-level",0, NULL); pf.levelInfo->time=0; player()->hsEntry.score=0; cleanUpGame(); startTransition(screen, TRANSITION_TYPE_ROLL_IN, 700); clearParticles(); setMenu(menuStatePrepareNextLevel); return(STATEMENU); } } drawUi(screen); } return(STATEPLAY); }
Color UrlValue::getImageBackground() const { UrlValue_Img img; loadImg(img); return img.background; }
int packAdd(const char* packDir, int isDLC) { char* buf = malloc(sizeof(char)*2048); char* buf2= malloc(sizeof(char)*1024); char* val = malloc(sizeof(char)*1024); char* set = malloc(sizeof(char)*1024); //This block is for playlists list_t* playList=0; listItem* li=0; playListItem* pli=0; int i; //Counter FILE* f=0; packInfoType* ti = malloc(sizeof(packInfoType)); ti->lives=3; //Default 3 lives, if pack do not define another number. ti->isDLC=isDLC; //Any levels? (Packs are invalid without a levels folder and atleast one level) sprintf(buf, "%s/levels/level000.wzp", packDir); //Initialize list for playlist playList = listInit(_freePlaylistItem); //Open packs/packname/info.ini sprintf(buf, "%s/info.ini", packDir); f = android_fopen(buf, "r"); if(f) { while( fgets(buf, 128, f) ) { stripNewLine(buf); if(splitVals('=',buf,set,val)) { if(strcmp("author", set)==0) { ti->author = malloc( sizeof(char)*(strlen(val)+1+3) ); sprintf(ti->author, "By %s", val); } else if(strcmp("packname", set)==0) { ti->name = malloc( sizeof(char)*(strlen(val)+1) ); strcpy(ti->name,val); } else if(strcmp("comment", set)==0) { ti->comment = malloc( sizeof(char)*(strlen(val)+1+1) ); sprintf(ti->comment, "-%s", val); } else if(strcmp("mus", set)==0) { //mus=00,song if( splitVals(',',val, buf,set ) && splitVals('-',buf,val,buf2) ) { //val= from buf2=to set=song name pli = malloc( sizeof( playListItem ) ); pli->from=atoi(val); pli->to=atoi(buf2); pli->song=malloc(sizeof(char)*strlen(set)+1); strcpy( pli->song, set ); listAppendData( playList, (void*)pli ); } else { SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, " Playlist entry format is mus=XX-XX,song name.ogg where XX-XX is a level range.\n"); } } else if(strcmp("lives", set)==0) { ti->lives = atoi(val); } } //Found = } //reading file //Close the info file. fclose(f); } else { //Fall back if no file was found. SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Warning: '%s' not found, using defaults.\n",buf); ti->author = malloc( sizeof(char)* 20 ); strcpy(ti->author, "info.ini not found"); ti->comment=ti->author; ti->name = malloc( sizeof(char)*(strlen(packDir)+1) ); strcpy(ti->name, packDir); } //Set path ti->path = malloc( sizeof(char)*(strlen(packDir)+1) ); strcpy(ti->path,packDir); //Set pack icon sprintf(buf, "%s/icon.png", packDir); ti->icon = loadImg(buf); if(!ti->icon) { ti->icon = loadImg( "data/noicon.png" ); } //Check if pack have a "finished" icon. sprintf(buf, "%s/finished.png", packDir); //Set ps.cp before entering makeLevelist, it makes use of packGetFile ps.cp = ti; //Add levels. ti->levels=0; ti->levels=makeLevelList(packDir); //makeLevelList looks in packDir/levels/ //set number of levels in pack ti->numLevels = ti->levels->count - 1 ; //The last level does not count (because it is just a "completed" screen). //Add to list of packages listAppendData( ps.packs, (void*)ti ); //Increase number of available packages ps.numPacks++; //Put playlist songs into levelfiles. li=&playList->begin; while( LISTFWD(playList,li) ) { pli=(playListItem*)li->data; for(i=0; i<ti->numLevels;i++) { if(i >= pli->from && i <= pli->to) { levelInfo(i)->musicFile = malloc( sizeof(char)*strlen(pli->song)+1 ); strcpy(levelInfo(i)->musicFile, pli->song); } } } //Clear playlist data listFree( playList ); free(buf); free(buf2); free(val); free(set); return(ps.numPacks-1); }
int main(int argc, char *argv[]) { int doScale=0; // 0=Undefined, 1=320x240, -1=OpenGL, >1=SwScale char* dumpPack=NULL; int state=1; //Game, Menu, Editor, Quit int sdlVideoModeFlags = SDL_SWSURFACE; #ifdef PSP //Note to PSP porter, please test if HW is actually faster, Wizznic does a lot of memory-manipulation in the screen-surface, each call might initiate a full copy back/forth from video memory. Remove comment when read. :) sdlVideoModeFlags = (SDL_HWSURFACE | SDL_DOUBLEBUF |SDL_HWACCEL); SetupCallbacks();//Callbacks actifs scePowerSetClockFrequency(333,333,166); #endif // #ifdef WIN32 //Redirect stdout to console on windows, so we can see what's going in. // FILE *stream; // stream = freopen("CON", "w", stdout); // #endif //Print welcome message printf( "Wizznic "VERSION_STRING". GPLv3 or newer Copyleft 2010-2013\n\n"); //initialize path strings initUserPaths(); //Tell where stuff's at. printf("Directories:\n Settings: %s\n DLC: %s\n Highscores: %s\n Editorlevels: %s\n Datafiles: %s\n\n", \ getConfigDir(), getUsrPackDir(), getHighscoreDir(), getUserLevelDir(), (!strlen(DATADIR))?".":DATADIR); //Print the command line parameters printf("Command-line parameters:\n"STR_VID_OPTIONS); //Quit if user wants help if( argc > 1 && ( strcmp(argv[1], "-h")==0 || strcmp(argv[1], "--help")==0 || strcmp(argv[1], "-help")==0 )) { printf("Please see readme.txt or http://wizznic.org/ for more help.\n"); return(0); } //Read settings printf("Loading settings...\n"); initSettings(); #if defined(WITH_OPENGL) //We start by enabling glScaling if it was enabled in settings, it can then be overwritten by command line options. if( setting()->glEnable && doScale==0 ) doScale=-1; #endif //Set scaling setting()->scaleFactor=1.0; atexit(SDL_Quit); //Init SDL if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK | SDL_INIT_TIMER ) <0 ) { printf("SDL_Init failed: %s\n",SDL_GetError()); return(-1); } //Setup display #if defined (GP2X) || defined (PSP) || defined (WIZ) SDL_Surface* screen = SDL_SetVideoMode(SCREENW,SCREENH,16, sdlVideoModeFlags); #else SDL_Surface* screen=NULL; int i; for( i=0; i < argc; i++ ) { if( strcmp( argv[i], "-sw" ) == 0 ) { setting()->glEnable=0; doScale=0; saveSettings(); } else if( strcmp( argv[i], "-gl" ) == 0 ) { setting()->glEnable=1; doScale=-1; saveSettings(); } else if( strcmp( argv[i], "-z" ) == 0 ) { if( i+1 < argc ) { doScale = atoi( argv[i+1] ); setting()->glEnable=0; i++; saveSettings(); } else { printf(" -z requires zoom level ( -z 2 for example ).\n"); return(1); } } else if( strcmp( argv[i], "-f" ) == 0 ) { setting()->fullScreen=1; saveSettings(); } else if( strcmp( argv[i], "-w" ) == 0 ) { setting()->fullScreen=0; saveSettings(); } else if( strcmp( argv[i], "-glheight" ) == 0 ) { if( i+1 < argc ) { setting()->glHeight = atoi( argv[i+1] ); setting()->glEnable=1; doScale=-1; i++; printf("Setting OpenGL window height to %i.\n", setting()->glHeight); saveSettings(); } else { printf(" -glheight requires an argument (-1 or size in pixels).\n"); return(1); } } else if( strcmp( argv[i], "-glwidth" ) == 0 ) { if( i+1 < argc ) { setting()->glWidth = atoi( argv[i+1] ); setting()->glEnable=1; doScale=-1; i++; printf("Setting OpenGL window width to %i.\n", setting()->glWidth); saveSettings(); } else { printf(" -glwidth requires an argument (-1 or size in pixels).\n"); return(1); } } else if( strcmp( argv[i], "-glfilter" ) == 0 ) { if( i+1 < argc ) { setting()->glFilter=atoi(argv[i+1]); printf("OpenGL texture filtering set to %s.\n", (setting()->glFilter)?"Smooth":"Off"); i++; saveSettings(); } else { printf("-glfilter requires 0 or 1 as argument.\n"); return(1); } } else if( strcmp( argv[i] , "-d" ) == 0 ) { if( argc == 3 && i < argc+1 ) { dumpPack = malloc( sizeof(char)*strlen(argv[i+1])+1 ); strcpy( dumpPack, argv[i+1] ); doScale=0; setting()->glEnable=0; i++; } else { printf("-d requires a packname, and must not be used with other parameters.\n"); return(1); } } else if( strcmp( argv[i], "-rift") == 0 ) { setting()->glWidth = 1280; setting()->glHeight = 800; setting()->glEnable=1; setting()->rift=1; doScale=-1; } else if( i > 0 ) { printf("\nError: Invalid argument '%s', quitting.\n", argv[i]); return(1); } } if( setting()->fullScreen ) { sdlVideoModeFlags |= SDL_FULLSCREEN; } if(doScale) { //Hardware accelerated scaling if( doScale == -1 ) { #ifdef HAVE_ACCELERATION printf("Enabling platform specific accelerated scaling.\n"); screen = platformInitAccel(sdlVideoModeFlags); if( !screen ) { printf("Failed to set platform accelerated scaling, falling back to software window.\n"); screen=swScreen(SDL_SWSURFACE); doScale=0; } #else printf("\nError:\n Not compiled with hardware-scaling support, don't give me -z -1\n Exiting...\n"); return(-1); #endif } else if( doScale > 0 ) { #ifdef WANT_SWSCALE //Set up software scaling printf("Enabling slow software-based scaling to %ix%i.\n",320*doScale, 240*doScale); screen = swScaleInit(sdlVideoModeFlags,doScale); #else printf("\nError:\n I don't support software scaling, don't give me any -z options\n Exiting...\n"); return(-1); #endif } } else { screen=swScreen(sdlVideoModeFlags); doScale=0; } printf("Scaling factor: %f\n", setting()->scaleFactor); if( screen == NULL ) { printf("ERROR: Couldn't init video.\n"); return(-1); } //Set window title SDL_WM_SetCaption("Wizznic!", "Wizznic!"); //Set window icon SDL_Surface* icon = IMG_Load( DATADIR"data/wmicon.png"); SDL_WM_SetIcon(icon, NULL); SDL_FreeSurface(icon); #endif setting()->bpp = screen->format->BytesPerPixel; setAlphaCol( setting()->bpp ); printf("Screen surface using %i bytes per pixel.\n",setting()->bpp); //Open Joysticks (for wiz) if (SDL_NumJoysticks() > 0) SDL_JoystickOpen(0); //Hide mouse cursor SDL_ShowCursor(SDL_DISABLE); //Load fonts txtInit(); //Load sounds if(!initSound()) { printf("Couldn't init sound.\n"); return(-1); } //Menu Graphics if(!initMenu(screen)) { printf("Couldn't load menu graphics.\n"); return(-1); } //Init controls initControls(); //Init stats statsInit(); //Init packs packInit(); //Scan userlevels dir makeUserLevelList(screen); //Init particles initParticles(screen); //Seed the pseudo random number generator (for particles 'n' stuff) srand( (int)time(NULL) ); #if defined(PC) //Need to dump level-screenshots? if(dumpPack) { printf("Dumping level-images for pack: %s\n", dumpPack); dumplevelimages(screen, dumpPack, 0); return(0); } #endif //init starfield initStars(screen); //Init pointer initPointer(screen); printf("Applying settings..\n"); //Apply settings (has to be done after packs are inited) applySettings(); //Set Pack packSetByPath( setting()->packDir ); #if defined( PLATFORM_SUPPORTS_STATSUPLOAD ) if( (setting()->uploadStats) && !(setting()->firstRun) ) { statsUpload(0,0,0,0,0,"check",1, &(setting()->session) ); statsUpload(0,0,0,0,0,"q_solved",1, &(setting()->solvedWorldWide) ); //DLC only works when stats-uploading is enabled so we can use the same nag-screen. dlcCheckOnline(); } #endif printf("Setting Music...\n"); //Start playing music (has to be done after readong settings) soundSetMusic(); //Initialize credits initCredits(screen); initTransition(); #if SCREENW != 320 || SCREENH != 240 SDL_Rect *borderSrcRect = malloc(sizeof(SDL_Rect)); SDL_Surface* border = loadImg( BORDER_IMAGE ); if( border ) { printf("Border image loaded.\n"); borderSrcRect->x=(border->w-SCREENW)/2; borderSrcRect->y=(border->h-SCREENH)/2; borderSrcRect->w=SCREENW; borderSrcRect->h=SCREENH; SDL_BlitSurface( border, borderSrcRect, screen, NULL ); SDL_FreeSurface(border); } else { printf("Could not load border image: %s\n", BORDER_IMAGE); SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0,0,0)); } free(borderSrcRect); borderSrcRect=NULL; #endif int lastTick; while(state!=STATEQUIT) { lastTick=SDL_GetTicks(); frameStart(); if(runControls()) state=STATEQUIT; switch(state) { case STATEPLAY: state = runGame(screen); break; case STATEMENU: state = runMenu(screen); break; case STATEEDIT: state=runEditor(screen); break; } drawPointer(screen); soundRun(screen,state); runTransition(screen); if(setting()->showFps) drawFPS(screen); switch( doScale ) { #if defined(HAVE_ACCELERATION) case -1: platformDrawScaled(screen); break; #endif case 0: SDL_Flip(screen); break; #if defined(WANT_SWSCALE) default: swScale(screen,doScale); break; #else default: state=STATEQUIT; break; #endif } #if defined(CRUDE_TIMING) //Oh how I loathe this, is there no better way? while(SDL_GetTicks()-lastTick <= PLATFORM_CRUDE_TIMING_TICKS) { //Burn, burn baby burn! } #else int t=SDL_GetTicks()-lastTick; if(t < 20) { SDL_Delay( 20 -t); } #endif } #if defined(PLATFORM_NEEDS_EXIT) platformExit(); #endif SDL_Quit(); return(0); }
void GraphicsEngine::loadGraphicsFiles(const std::string& path, bool& error){ //FIXME: loadImg can be null! configLoader config(path); std::string fileName; config.loadData(); config.getPawnFile(fileName); pawnSrf_b = loadImg (fileName); pawnSrf = loadImg (fileName); config.getRookFile(fileName); rookSrf_b = loadImg (fileName); rookSrf = loadImg (fileName); config.getKnightFile(fileName); knightSrf_b = loadImg (fileName); knightSrf = loadImg (fileName); config.getBishopFile(fileName); bishopSrf_b = loadImg (fileName); bishopSrf = loadImg (fileName); config.getQueenFile(fileName); queenSrf_b = loadImg (fileName); queenSrf = loadImg (fileName); config.getKingFile(fileName); kingSrf_b = loadImg (fileName); kingSrf = loadImg (fileName); config.getWSquareFile(fileName); squareSrfW = loadImg(fileName); config.getBSquareFile(fileName); squareSrfB = loadImg (fileName); config.getBackgroundFile(fileName); background = loadImg (fileName); //TODO: Check if the files were loaded correctly at this point! makeWhite(pawnSrf); makeWhite(rookSrf); makeWhite(knightSrf); makeWhite(bishopSrf); makeWhite(kingSrf); makeWhite(queenSrf); }
void drawPackBox(SDL_Surface* screen,int posx, int posy,int packNum) { char buf[128]; SDL_Rect r; r.x=posx+5; r.y=posy+5; //We do this so the menu can unload the images when not used. if(!ps.packBoxImg) { //Load graphics ps.packBoxImg = loadImg( "data/pack-box-small.png" ); ps.packBoxSpr[PCKLISTIMG_SELECTED] = cutSprite(ps.packBoxImg, 0,0,260,42); ps.packBoxSpr[PCKLISTIMG_DEFAULT] = cutSprite(ps.packBoxImg, 0,42,260,42); ps.packBoxSpr[PCKLISTIMG_IS_DLC] = cutSprite(ps.packBoxImg, 0,42+42,260,42); ps.packBoxSpr[PCKLISTIMG_DLC_ENTER] = cutSprite(ps.packBoxImg, 0,42+42+42,260,42); ps.packBoxSpr[PCKLISTIMG_DLC_OFFLINE] = cutSprite(ps.packBoxImg, 0,42+42+42+42,260,42); } SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "==== 10"); //PackInfo is now in pi. packInfoType* pi; if( packNum == ps.numPacks ) { pi = ps.dlc; } else { pi = (packInfoType*)( listGetItemAt(ps.packs,packNum) )->data; } //Blit the box if(pi == ps.dlc ) { #if defined( PLATFORM_SUPPORTS_STATSUPLOAD ) if( setting()->online && dlcGetState()==DLC_READY ) { drawSprite(screen, ps.packBoxSpr[PCKLISTIMG_DLC_ENTER], posx, posy); txtWrite(screen, FONTSMALL, STR_MENU_PACKLIST_DLC_ENTER, posx+40, posy+4); } else { drawSprite(screen, ps.packBoxSpr[PCKLISTIMG_DLC_OFFLINE], posx, posy); txtWrite(screen, FONTSMALL, STR_MENU_PACKLIST_DLC_OFFLINE, posx+12, posy+4); } #else drawSprite(screen, ps.packBoxSpr[PCKLISTIMG_DLC_OFFLINE], posx, posy); txtWrite(screen, FONTSMALL, STR_MENU_PACKLIST_DLC_OFFLINE, posx+12, posy+4); #endif return; //We don't want to write any info on that special box. } else if(ps.selected==packNum) { drawSprite(screen, ps.packBoxSpr[PCKLISTIMG_SELECTED], posx, posy); } else { if(pi->isDLC == PACK_IS_DLC) { drawSprite(screen, ps.packBoxSpr[PCKLISTIMG_IS_DLC], posx, posy); } else { drawSprite(screen, ps.packBoxSpr[PCKLISTIMG_DEFAULT], posx, posy); } } SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "==== 20"); //Blit the icon image SDL_BlitSurface(pi->icon,0,screen, &r); //PackName txtWrite(screen, FONTSMALL, pi->name, posx+40, posy+4); //Author txtWrite(screen, FONTSMALL, pi->author, posx+258-9*(strlen(pi->author)), posy+4); //Comment txtWrite(screen, FONTSMALL, pi->comment, posx+40, posy+4+12); //Number of levels sprintf(buf, "%i levels", pi->numLevels); txtWrite(screen, FONTSMALL, buf, posx+258-9*(strlen(buf)), posy+4+24); //Number of lives if( pi->lives > 0 ) { sprintf(buf, "%i lives", pi->lives); } else { sprintf(buf, "Infinite lives!"); } txtWrite(screen, FONTSMALL, buf, posx+40, posy+4+24); SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "==== 200"); }
unsigned int UrlValue::getImageWidth() const { UrlValue_Img img; return (loadImg(img) ? img.width : 0); }
unsigned int UrlValue::getImageHeight() const { UrlValue_Img img; return (loadImg(img) ? img.height : 0); }
void registerUpdate(const string &field1, const string &field2, const string &field3, const string &field4, const string &button, const string &title){ if(regSelectTexture[0] == 0) regSelectTexture[0] = loadImg("res/regsel0.png"); if(regSelectTexture[1] == 0) regSelectTexture[1] = loadImg("res/regsel1.png"); if(regSelectTexture[2] == 0) regSelectTexture[2] = loadImg("res/regsel2.png"); if(regSelectTexture[3] == 0) regSelectTexture[3] = loadImg("res/regsel3.png"); if(regSelectTexture[4] == 0) regSelectTexture[4] = loadImg("res/regsel4.png"); if(registerSurface == NULL){ registerSurface = IMG_Load("res/register.png"); SDL_Color white, black; white.r = white.g = white.b = 0xFF; black.r = black.g = black.b = 0x00; SDL_Surface *titleText = TTF_RenderUTF8_Blended(font, title.c_str(), white); SDL_Rect rTitle = {6,5,0,0}; SDL_BlitSurface(titleText, NULL, registerSurface, &rTitle); SDL_FreeSurface(titleText); SDL_Surface *userLblText = TTF_RenderUTF8_Blended(font, "Usuario:", black); SDL_Rect rUserLbl = {8,48,0,0}; SDL_BlitSurface(userLblText, NULL, registerSurface, &rUserLbl); SDL_FreeSurface(userLblText); SDL_Surface *passLblText = TTF_RenderUTF8_Blended(font, "Password:"******"Mail:", black); SDL_Rect rMailLbl = {8,134,0,0}; SDL_BlitSurface(mailLblText, NULL, registerSurface, &rMailLbl); SDL_FreeSurface(mailLblText); SDL_Surface *nameLblText = TTF_RenderUTF8_Blended(font, "Nombre:", black); SDL_Rect rNameLbl = {8,177,0,0}; SDL_BlitSurface(nameLblText, NULL, registerSurface, &rNameLbl); SDL_FreeSurface(nameLblText); SDL_Surface *buttonText = TTF_RenderUTF8_Blended(font, button.c_str(), black); SDL_Rect rButton = {128,234,0,0}; rButton.x -= buttonText->w/2; rButton.y -= buttonText->h/2; SDL_BlitSurface(buttonText, NULL, registerSurface, &rButton); SDL_FreeSurface(buttonText); registerTexture = genTexture(registerSurface, registerTexture); } SDL_Color black; black.r = black.g = black.b = 0x00; SDL_Surface *tempSurface = SDL_ConvertSurface(registerSurface, registerSurface->format, registerSurface->flags); SDL_Surface *f1Text = TTF_RenderUTF8_Blended(font, field1.c_str(), black); SDL_Rect rF1 = {88,48,0,0}; SDL_BlitSurface(f1Text, NULL, tempSurface, &rF1); SDL_FreeSurface(f1Text); SDL_Surface *f2Text = TTF_RenderUTF8_Blended(font, field2.c_str(), black); SDL_Rect rF2 = {88,91,0,0}; SDL_BlitSurface(f2Text, NULL, tempSurface, &rF2); SDL_FreeSurface(f2Text); SDL_Surface *f3Text = TTF_RenderUTF8_Blended(font, field3.c_str(), black); SDL_Rect rF3 = {88,134,0,0}; SDL_BlitSurface(f3Text, NULL, tempSurface, &rF3); SDL_FreeSurface(f3Text); SDL_Surface *f4Text = TTF_RenderUTF8_Blended(font, field4.c_str(), black); SDL_Rect rF4 = {88,177,0,0}; SDL_BlitSurface(f4Text, NULL, tempSurface, &rF4); SDL_FreeSurface(f4Text); registerTexture = genTexture(tempSurface, registerTexture); SDL_FreeSurface(tempSurface); }