void LStringBox::show_box( SDL_Surface *surface ) ////////////////////////////////////////////// { //get the blit offsets SDL_Rect temp = *this->offset; //and add the box offsets temp.x += x; temp.y += y; //apply the box apply_surface( this->x, this->y, this->backSurface, surface ); //apply the text apply_surface( temp.x, temp.y, this->textSurface, surface ); }
void render() { SDL_FillRect(screen,NULL,SDL_MapRGB(screen->format,0,0,0)); apply_surface((screen->w - text->w) /2 , 50, text, screen); SDL_BlitSurface(sprite,&frame,screen,&dest); SDL_Flip(screen); SDL_Delay(100); }
int printt( SDL_Surface * screen) { //Initialisation de SDL_ttf TTF_Init(); //on met en place la barre caption de la fenetre SDL_WM_SetCaption( "TTF Test", NULL ); //Ouverture du font font = TTF_OpenFont( "CaslonBold.ttf", 28 ); //application du texte message = TTF_RenderText_Solid( font, "test", textColor ); //Si il y a une erreur lors de l'application du texte if( message == NULL ) { return 1; } //Application des surfaces(images) sur l'ecran apply_surface(0, 10, message, screen ); return 0; }
void welcome_message() { SDL_Surface *message1=TTF_RenderText_Solid(font,"Welcome to Pixel World:Duel Mode! ",color2); apply_surface(280,160,message1,screen); SDL_FreeSurface(message1); SDL_Surface *message2=TTF_RenderText_Solid(font,"Code:Alex Cioltan and Stefan Enescu ",color2); apply_surface(280,200,message2,screen); SDL_Surface *message3=TTF_RenderText_Solid(font,"Graphics: Stefan Enescu,",color2); apply_surface(280,240,message3,screen); SDL_Surface *message4=TTF_RenderText_Solid(font,"Alex Cioltan, Victor Ionescu and",color2); apply_surface(280,280,message4,screen); message4=TTF_RenderText_Solid(font,"Duta Alexandru",color2); apply_surface(280,320,message4,screen); SDL_Flip(screen); while(getkey(VK_RETURN)==0); }
int main(int argc, char* args[]) { //make sure the program waits for a quit; bool quit = false; //initialize; if(init()==false) { return 1; } //load the files if(load_files()==false) { return 1; } //apply the surface to the screen apply_surface(0,0,image,screen); //update the screen if(SDL_Flip(screen)==-1) { return 1; } //while the user hasn't quit while(quit==false) { while(SDL_PollEvent(&event)) { //if the user has Xed out the window if(event.type == SDL_QUIT) { //quit the program quit = true; } } } //free the surface and quit SDL clean_up(); return 0; }
//Insert a block, according to the matrix void insert_block (int x, int y, lcBlockColor color) { if (color != NONE) { apply_surface ( (x * LC_BLOCK_SIZE + LC_GAME_X), (y * LC_BLOCK_SIZE + LC_GAME_Y), block_colors[(int)color], screen); } }//insert_block
//Insert a block in next box (with x,y relative to the interior of the box) void insert_next (int x, int y, lcBlockColor color) { if (color != NONE) { apply_surface ( (x + LC_NEXT_X), (y + LC_NEXT_Y), block_colors[(int)color], screen); } }//insert_next
int main( int argc, char* args[] ) { //wait for quit bool quit = false; //init if( init() == false ) return 1; //load if( load_files() == false ) return 1; //apply apply_surface( 0, 0, image, screen ); //update if( SDL_Flip( screen ) == -1 ) return 1; while( quit == false ) { //while event while( SDL_PollEvent( &event ) ) { if( event.type == SDL_QUIT ) quit = true; } } clean_up(); return 0; }
int RenderTextToSurface(std::string Text, int x, int y, SDL_Surface *Dest, SDL_Color *TXT_Color) { SDL_Color txt_Color; if(TXT_Color == NULL) { txt_Color.r = 0x00; txt_Color.g = 0x00; txt_Color.b = 0x00; }else{ txt_Color.r = TXT_Color->r; txt_Color.g = TXT_Color->g; txt_Color.b = TXT_Color->b; } SDL_Surface *TTF_Message; if (!TTF_WasInit()) { TTF_Init(); } TTF_Font *font = TTF_OpenFont(gFontName.c_str(), 24); if (font == NULL) { char* error = TTF_GetError(); std::cout << "TTF_Font: " << error << std::endl; return 1; } if (!(TTF_Message = TTF_RenderText_Solid(font, Text.c_str(), txt_Color))) { SDL_FreeSurface(TTF_Message); std::cout << "Error in function 'RenderTextToSurface': TTF_Message could not be blitted: returned 1" << std::endl; return 1; } TTF_CloseFont(font); apply_surface(x, y, TTF_Message, Dest); SDL_FreeSurface(TTF_Message); return 0; }
/*------------------------------------------------------------------------------------------------------------------ -- FUNCTION: showloaded -- -- DATE: April 15th, 2009 -- -- REVISIONS: None yet -- -- DESIGNER: Alin Albu -- -- PROGRAMMER: Alin Albu -- -- INTERFACE: bool POptMenu::showloaded() -- -- RETURNS: bool -- -- NOTES: -- Shows loaded background . ----------------------------------------------------------------------------------------------------------------------*/ bool POptMenu::showloaded() { TTF_Font *font; SDL_Surface *name; SDL_Color text_color = { pNameColourRed_, pNameColourGreen_, pNameColourBlue_ }; printf("Loading backgrounds\n"); bool result = false; result = move(0, 0); if (result) { if ((font = TTF_OpenFont("resources/fonts/igloo.ttf", 50)) == NULL) { printf("Couldn't open desired font type: %s\n", SDL_GetError()); exit(4); } printf("Background Loaded\n"); result = showModels(); if (name_exists) { if ((name = TTF_RenderText_Solid(font, pName_.c_str(), text_color)) == NULL) printf("Could not update text"); apply_surface((350 - (name->w / 2)), 120, name, screen_); SDL_Flip(screen_); printf("TESTING"); } } return result; }
void Game_Object::renderObj(SDL_Surface* screen) { int xCenter, yCenter; xCenter = (int)floor(x - width/2 + 0.5); yCenter = (int)floor(y - height/2 + 0.5); apply_surface(xCenter, yCenter, img_graphic, screen, NULL); }
void draw(){ static int i = 210; SDL_Rect tmp2; tmp2.x = 210; if(i == (210 + 90)) i = 210; if(i == (180 - 90)) i = 180; if( rightdown ){ tmp2.x = (i + 30); i = tmp2.x; } if( leftdown ){ tmp2.x = (i - 30); i = tmp2.x; } if( updown ) tmp2.x = 210 + 150; tmp2.y = 0; tmp2.w = 16; tmp2.h = 16; apply_surface( 100, 100, sprite_image2, screen, &tmp2 ); }
int main(){ SDL_Surface *message = NULL; SDL_Surface *screen = NULL; SDL_Init(SDL_INIT_EVERYTHING); TTF_Font *font = NULL; SDL_Color textColor = { 255, 255, 255 }; SDL_Window* window; SDL_Renderer* Surf_Display; #define WWIDTH 640 #define WHEIGHT 480 window = SDL_CreateWindow("Open Multiplayer RPG", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, WWIDTH, WHEIGHT, SDL_WINDOW_RESIZABLE ); Surf_Display = SDL_CreateRenderer(window, -1, SDL_RENDERER_TARGETTEXTURE|SDL_RENDERER_PRESENTVSYNC ); SDL_Surface *bmp = SDL_LoadBMP("b.bmp"); SDL_Texture * texture = SDL_CreateTextureFromSurface(Surf_Display,bmp); SDL_RenderClear(Surf_Display); SDL_RenderCopy(Surf_Display,texture, NULL,NULL); SDL_RenderPresent(Surf_Display); font = TTF_OpenFont( "./lazy.ttf", 28 ); message = TTF_RenderText_Solid( font, "The quick brown fox jumps over the lazy dog", textColor ); apply_surface( 0, 150, message, screen ); SDL_RenderCopy(Surf_Display,screen, NULL,NULL); SDL_RenderPresent(Surf_Display); bool running = true; while (running){ }; };
void Engine::start( ) { if( engineState != initializing ) return; apply_surface( 0, 0, background, screen ); for( int i=0; i<4; i++ ) { for( int j=0; j<6; j++ ) { square[i][j].SetPosition( ( j*170 ) +28, ( i*170 )+150 ); } } square[3][0].Undead = true; square[0][5].Undead = true; square[3][0].Load( true ); square[0][5].Load( true ); square[3][0].setClip( 0 ); square[0][5].setClip( 0 ); engineState = Engine::showingSplash; while( !isExiting( ) ) { EngineLoop(); } SDL_Quit(); }
void print_xp(int a,int lin,int col) { SDL_Surface *clear,*message; SDL_Color color2={174,0,0}; int i=0,i1,j; if(a<0) a=0; char v[10]={0,0,0,0,0,0,0,0,0,0},v1[10]={0,0,0,0,0,0,0,0,0,0}; while(a!=0) { i++; v[i]=a%10+'0'; a/=10; } for(i1=1,j=i;i1<=i;i1++,j--) v1[i1]=v[j]; if(i==0) { i++; v1[i]='0'; } v1[i+1]=' '; v1[i+2]='X'; v1[i+3]='P'; v1[i+4]=NULL; message=TTF_RenderText_Solid(font,v1+1,color2); apply_surface(col*40,lin*40,message,screen); }
/*converting the board given in the 2nd paramter into graphical form. the 3rd paramter is for internal use*/ int fromStateToGui(SDL_Surface* screen, board_t board, PAGE page_name){ SDL_Surface* turnButton = NULL; int i, j; SDL_Surface* guiPlayer = NULL; piece player; pixle pix; location loc; char* buttonName; if (page_name == GAME){ if (state->turn == BLACK) buttonName = "Images/black.bmp"; else buttonName = "Images/white.bmp"; turnButton = SDL_LoadBMP(buttonName); if (turnButton == NULL) return 1; SDL_SetColorKey(turnButton, SDL_SRCCOLORKEY, SDL_MapRGB(screen->format, 255, 0, 255)); apply_surface(638, 12, turnButton, screen); SDL_FreeSurface(turnButton); } //now, for every piece- we get the proper image for him and we present it on the graphical board according the game board and state for (i = 0; i < BOARD_SIZE; i++){ for (j = 0; j < BOARD_SIZE; j++){ player = board[i][j]; loc.column = i; loc.row = j; if (player.color != BLACK && player.color != WHITE){ continue; } pix = location_to_pixel(loc); guiPlayer = SDL_LoadBMP(getProperGuiPlayer(player)); if (guiPlayer == NULL){ SDL_FreeSurface(guiPlayer); return 1; } SDL_SetColorKey(guiPlayer, SDL_SRCCOLORKEY, SDL_MapRGB(screen->format, 255, 0, 255)); apply_surface(pix.x, pix.y, guiPlayer, screen); SDL_FreeSurface(guiPlayer); } } // if the game arrived to check/mate sitation present this to the user! if (isCheck_var && game_over == FALSE){ add_situation_sign(screen, CHECK,getEnemyColor(state->turn)); } if (isCheck_var && game_over == TRUE){ add_situation_sign(screen, MATE, getEnemyColor(state->turn)); } return 0; //returns 0 }
void paddle::render(SDL_Surface* screen) { if(position.y!=10){ std::cout<<position.x<<","<<position.y<<"\n"; } apply_surface(position.x,position.y,paddle_surface,screen); //apply_surface(game->get_p1_pos().x,game->get_p1_pos().y,paddle_surface,screen); }
void UI::Render() { // Free the surfaces to the blitted anew SDL_FreeSurface(m_CollectedCoinsLabel); SDL_FreeSurface(m_RequiredCoinsLabel); SDL_FreeSurface(m_TotalCoinsLabel); // Set all the text labels to their new (or unchanged) values m_CollectedCoinsLabel = TTF_RenderText_Solid(g_resources->GetFont(), m_CollectedCoins.c_str(), machineTextColor); m_RequiredCoinsLabel = TTF_RenderText_Solid(g_resources->GetFont(), m_RequiredCoins.c_str(), machineTextColor); m_TotalCoinsLabel = TTF_RenderText_Solid(g_resources->GetFont(), m_TotalCoins.c_str(), textColor); // Blit the new fonts onto the label apply_surface(collectedX, collectedY, m_CollectedCoinsLabel, screen); apply_surface(requiredX, requiredY, m_RequiredCoinsLabel, screen); apply_surface(totalX, totalY, m_TotalCoinsLabel, screen); }
void Dot::show() { //Show the dot apply_surface( x, y, dot, screen ); //Show the particles show_particles(); }
/** * \fn void afficherContourMap(OptionDAffichage *optAffichage, SDL_Surface *ecran, Jeu *game) * \brief affiche le contour de la carte * * \param optAffichage Les options d'affichage * \param ecran La surface sur laquelle on veut l'afficher * \param game Le jeu qu'on veut afficher */ void afficherContourMap(OptionDAffichage *optAffichage, SDL_Surface *ecran, Jeu *game){ SDL_Surface *textures = IMG_Load("Tiny32-Complete-Spritesheet-Repack3.png"); //load le tileset char y = game->nbCaseY-1,x; for (x=0;x<game->nbCaseX;x++){ apply_surface((x+optAffichage->origineMapX)*SPRITE_WIDTH, (y+optAffichage->origineMapY +1)*SPRITE_HEIGHT, textures, ecran, &contourMap); //0->(SCREEN_WIDTH/SPRITE_WIDTH)-1 } SDL_FreeSurface(textures); // On libère la surface }
/*adding tiles on the locations prestings the best move*/ int add_tiles_to_best_move(SDL_Surface* screen, itemMove* best_moves){ SDL_Surface* tileSelection = NULL; pixle pix; move best_move = best_moves->move; tileSelection = SDL_LoadBMP("Images/tileselection.bmp"); if (tileSelection == NULL) return 1; SDL_SetColorKey(tileSelection, SDL_SRCCOLORKEY, SDL_MapRGB(screen->format, 255, 0, 255)); if (best_moves!=NULL){ pix = location_to_pixel(best_move.locStart); apply_surface(pix.x, pix.y, tileSelection, screen); pix = location_to_pixel(best_move.locEnd); apply_surface(pix.x, pix.y, tileSelection, screen); } SDL_FreeSurface(tileSelection); return 0; }
//return 1 if build, 0 if something wrong happend int build_page_loadORsave_generic(SDL_Surface* screen){ SDL_Surface* background = NULL; SDL_Surface* slot = NULL; int i; pixle pix; //load page: background= SDL_LoadBMP("Images/slotback.bmp"); apply_surface(0,0,background,screen); for (i = 0; i < NUMBER_OF_SLOTS; i++){ slot= SDL_LoadBMP(get_name_of_button(i+1)); pix= get_pixel_for_slot_button(i+1); apply_surface(pix.x, pix.y, slot,screen); SDL_FreeSurface(slot); } SDL_FreeSurface(background); return 1; }
void MainMenuScreen::Draw(CGameEngine* game) { //Fill the screen white //SDL_FillRect( game->GetScreen(), &game->GetScreen()->clip_rect, SDL_MapRGB(game->GetScreen()->format, 0xFF, 0x00, 0x00 )); switch(state) { case MAIN: apply_surface(Vector2D(0,0), sprite_bg, game->GetScreen()); apply_surface(Vector2D(300,100), sprite_play, game->GetScreen()); apply_surface(Vector2D(300,130), sprite_instr, game->GetScreen()); apply_surface(Vector2D(300,160), sprite_credit, game->GetScreen()); apply_surface(Vector2D(300,190), sprite_quit, game->GetScreen()); break; case INSTR: apply_surface(Vector2D(0,0), sprite_bg_instr, game->GetScreen()); break; case CREDIT: apply_surface(Vector2D(0,0), sprite_bg_credit, game->GetScreen()); break; } if( SDL_Flip( game->GetScreen() ) == -1 ) { /*output to debug file */} }
void Button::render() { switch (current_state) { case NORMAL: apply_surface(mask.x,mask.y,normal,screen); break; case ACTIVE: apply_surface(mask.x,mask.y,active,screen); break; case PRESSED: apply_surface(mask.x,mask.y,pressed,screen); break; } tPoint text_position; text_position.x = mask.x + ((mask.w - text->w) / 2); text_position.y = mask.y + ((mask.h - text->h) / 2); if (current_state == PRESSED) text_position.y += 5; apply_surface(text_position.x,text_position.y,text,screen); }
int shw_map_pce(int mapnum, int xx,int yy) { apply_surface( xx, yy, maze[mapnum], screen,NULL ); return 0; }
void Tela::showScreen() { //Mostra a tela do jogo for(int i = 0; i < linhasMatriz; i++) for(int j = 0; j < colunasMatriz; j++) { apply_surface(i, j, gems, screen); if( SDL_Flip( screen ) == -1 ) return; } }
void cDangerousGame::print( std::string text, int x, int y ){ if( message != NULL ){ SDL_FreeSurface( message ); } message = TTF_RenderText_Solid( font, text.c_str(), textColor ); if( message == NULL ) { return; } apply_surface( x, y, message, screen, NULL ); }
/*present the options of selecting piece for adding to the board and return the chosen piece to add selected by the user*/ piece select_piece(SDL_Surface* screen){ int x, y; piece player; int move_next_page = FALSE; SDL_Surface* selectPiece_Menu = NULL; SDL_Event event; char type = EMPTY; char color = EMPTY; selectPiece_Menu = SDL_LoadBMP("Images/piecechoose.bmp"); apply_surface(0, 0, selectPiece_Menu, screen); //Update Screen SDL_Flip(screen); while (quit == FALSE && move_next_page == FALSE){ if (SDL_PollEvent(&event)){ if (event.type == SDL_MOUSEBUTTONUP){ //Get the mouse offsets x = event.button.x; y = event.button.y; //whiteColors: //knight: if ((x > 56) && (x < 56 + 75) && (y > 174) && (y < 174 + 75)){ type = KNIGHT; color = WHITE; break; } // queen: if ((x > 177) && (x < 177 + 75) && (y > 174) && (y < 174 + 75)){ type = QUEEN; color = WHITE; break; } //bishop: if ((x > 310) && (x < 310 + 75) && (y > 174) && (y < 174 + 75)){ type = BISHOP; color = WHITE; break; } //pawn: if ((x > 423) && (x < 423 + 75) && (y > 174) && (y < 174 + 75)){ type = PAWN; color = WHITE; break; } //rook: if ((x > 546) && (x < 546 + 75) && (y > 174) && (y < 174 + 75)){ type = ROOK; color = WHITE; break; } //king: if ((x > 660) && (x < 660 + 75) && (y > 174) && (y < 174 + 75)){ type = KING; color = WHITE; break; } //blackColors: //knight: if ((x > 56) && (x < 56 + 75) && (y > 350) && (y < 350 + 75)){ type = KNIGHT; color = BLACK; break; } // queen: if ((x > 177) && (x < 177 + 75) && (y > 350) && (y < 350 + 75)){ type = QUEEN; color = BLACK; break; } //bishop: if ((x > 310) && (x < 310 + 75) && (y > 350) && (y < 350 + 75)){ type = BISHOP; color = BLACK; break; } //pawn: if ((x > 423) && (x < 423 + 75) && (y > 350) && (y < 350 + 75)){ type = PAWN; color = BLACK; break; } //rook: if ((x > 546) && (x < 546 + 75) && (y > 350) && (y < 350 + 75)){ type = ROOK; color = BLACK; break; } //king: if ((x > 660) && (x < 660 + 75) && (y > 350) && (y < 350 + 75)){ type = KING; color = BLACK; break; } //cancel: if ((x > 324) && (x < 324 + 155) && (y > 469) && (y < 469 + 70)){ break; } } //If the user has Xed out the window if (event.type == SDL_QUIT){ quit = TRUE; break; } } } //Free the loaded image SDL_FreeSurface(selectPiece_Menu); player.color = color; player.type = type; return player; }
void Tile::show() { //If the tile is on screen if( check_collision( camera, box ) == true ) { //Show the tile apply_surface( box.x - camera.x, box.y - camera.y, tileSheet, screen, &clips[ type ] ); } }
void show_timer_text() { SDL_FreeSurface(timer_text); char time[128]; sprintf(time, "%d", timer_get_seconds()); timer_text = TTF_RenderText_Blended(input_font, time, font_color); apply_surface( screen_width - timer_text->w, 0, timer_text, screen ); }