Esempio n. 1
0
void Tile::blitDeadUnits(int xPos, int yPos) {
    if(!isFogged(pLocalHouse->getHouseID())) {
        for(std::vector<DEADUNITTYPE>::const_iterator iter = deadUnits.begin(); iter != deadUnits.end(); ++iter) {
            SDL_Rect source = { 0, 0, world2zoomedWorld(TILESIZE), world2zoomedWorld(TILESIZE)};
            SDL_Surface** pSurface = NULL;
            switch(iter->type) {
            case DeadUnit_Infantry: {
                pSurface = pGFXManager->getObjPic(ObjPic_DeadInfantry, iter->house);
                source.x = (iter->timer < 1000 && iter->onSand) ? world2zoomedWorld(TILESIZE) : 0;
            }
            break;

            case DeadUnit_Infantry_Squashed1: {
                pSurface = pGFXManager->getObjPic(ObjPic_DeadInfantry, iter->house);
                source.x = 4 * world2zoomedWorld(TILESIZE);
            }
            break;

            case DeadUnit_Infantry_Squashed2: {
                pSurface = pGFXManager->getObjPic(ObjPic_DeadInfantry, iter->house);
                source.x = 5 * world2zoomedWorld(TILESIZE);
            }
            break;

            case DeadUnit_Carrall: {
                pSurface = pGFXManager->getObjPic(ObjPic_DeadAirUnit, iter->house);
                if(iter->onSand) {
                    source.x = (iter->timer < 1000) ? 5*world2zoomedWorld(TILESIZE) : 4*world2zoomedWorld(TILESIZE);
                } else {
                    source.x = 3*world2zoomedWorld(TILESIZE);
                }
            }
            break;

            case DeadUnit_Ornithopter: {
                pSurface = pGFXManager->getObjPic(ObjPic_DeadAirUnit, iter->house);
                if(iter->onSand) {
                    source.x = (iter->timer < 1000) ? 2*world2zoomedWorld(TILESIZE) : world2zoomedWorld(TILESIZE);
                } else {
                    source.x = 0;
                }
            }
            break;

            default: {
                pSurface = NULL;
            }
            break;
            }

            if(pSurface != NULL) {
                SDL_Rect dest = {   screenborder->world2screenX(iter->realPos.x) - world2zoomedWorld(TILESIZE)/2,
                                    screenborder->world2screenY(iter->realPos.y) - world2zoomedWorld(TILESIZE)/2,
                                    pSurface[currentZoomlevel]->w,
                                    pSurface[currentZoomlevel]->h
                                };
                SDL_BlitSurface(pSurface[currentZoomlevel], &source, screen, &dest);
            }
        }
    }
}
Esempio n. 2
0
CFighterStatsDemo::CFighterStatsDemo( FighterEnum a_iFighter )
{
	m_iTimeLeft = 500;
	m_poStaff = NULL;
	
	m_poBackground = LoadBackground( "FighterStats.jpg", 64 );
	DrawGradientText( "Fighter Stats", titleFont, 10, m_poBackground );

	SDL_BlitSurface( m_poBackground, NULL, gamescreen, NULL );
	SDL_Flip( gamescreen );
	
	if ( mg_iLastFighter < 0 )
	{
		// First run; create shuffled array of fighters.
		mg_iLastFighter = 0;
		
		int i, j;
		FighterEnum k;
		for ( i=0; i<LASTFIGHTER-1; ++i )
		{
			mg_aenFighterOrder[i] = (FighterEnum)(i+1);
		}
		for ( i=0; i<LASTFIGHTER-1; ++i )
		{
			j = rand() % (LASTFIGHTER-1);
			k = mg_aenFighterOrder[i]; 
			mg_aenFighterOrder[i] = mg_aenFighterOrder[j]; 
			mg_aenFighterOrder[j] = k;
		}
	}
	
	if ( a_iFighter <= UNKNOWN )
	{
		mg_iLastFighter = (mg_iLastFighter+1) % (LASTFIGHTER-1);
		m_enFighter = mg_aenFighterOrder[mg_iLastFighter];
	}
	else
	{
		m_enFighter = a_iFighter;
	}

	if ( g_oPlayerSelect.IsFighterAvailable( m_enFighter ) )
	{
		g_oPlayerSelect.SetPlayer( 0, m_enFighter );
		g_oBackend.PerlEvalF( "SelectStart(%d);", 2 );
	}
	else
	{
		std::string sStaffFilename = DATADIR;
		sStaffFilename += "/characters/STAFF.DAT";
		m_poStaff = new CRlePack( sStaffFilename.c_str(), 255 );
	}

	g_oBackend.PerlEvalF("GetFighterStats(%d);", m_enFighter );
	_sge_TTFont* font = impactFont;
	int y = TOPMARGIN;


	AV *StatTags = get_av( "StatTags", FALSE );

	char *s, *sTag;

	s = SvPV_nolen(get_sv("Name", FALSE));
	DrawTextMSZ( s, inkFont, (LEFTMARGIN + RIGHTMARGIN)/2, y, AlignHCenter, C_WHITE, m_poBackground );
	y+= 10;

	s = SvPV_nolen(get_sv("Team", FALSE ));
	sTag = SvPV_nolen( *av_fetch( StatTags, 1, false ) );
	int i = DrawTextMSZ( sTag, font, LEFTMARGIN, y+=LINEHEIGHT, 0, C_YELLOW, m_poBackground );
	DrawTextMSZ( s, font, LEFTMARGIN+i, y, 0, C_ORANGE, m_poBackground, false );

	s = SvPV_nolen(get_sv("Style", FALSE ));
	sTag = SvPV_nolen( *av_fetch( StatTags, 2, false ) );
	i = DrawTextMSZ( sTag, font, LEFTMARGIN2, y, 0, C_YELLOW, m_poBackground );
	DrawTextMSZ( s, font, LEFTMARGIN2+i, y, 0, C_ORANGE, m_poBackground, false );

	s = SvPV_nolen(get_sv("Age", FALSE ));
	sTag = SvPV_nolen( *av_fetch( StatTags, 3, false ) );
	i = DrawTextMSZ( sTag, font, LEFTMARGIN, y+=LINEHEIGHT, 0, C_YELLOW, m_poBackground );
	DrawTextMSZ( s, font, LEFTMARGIN+i, y, 0, C_ORANGE, m_poBackground, false );

	s = SvPV_nolen(get_sv("Weight", FALSE ));
	sTag = SvPV_nolen( *av_fetch( StatTags, 4, false ) );
	i = DrawTextMSZ( sTag, font, LEFTMARGIN2, y, 0, C_YELLOW, m_poBackground );
	DrawTextMSZ( s, font, LEFTMARGIN2+i, y, 0, C_ORANGE, m_poBackground, false );

	s = SvPV_nolen(get_sv("Height", FALSE ));
	sTag = SvPV_nolen( *av_fetch( StatTags, 5, false ) );
	i = DrawTextMSZ( sTag, font, LEFTMARGIN, y+=LINEHEIGHT, 0, C_YELLOW, m_poBackground );
	DrawTextMSZ( s, font, LEFTMARGIN+i, y, 0, C_ORANGE, m_poBackground, false );

	s = SvPV_nolen(get_sv("Shoe", FALSE ));
	sTag = SvPV_nolen( *av_fetch( StatTags, 6, false ) );
	i = DrawTextMSZ( sTag, font, LEFTMARGIN2, y, 0, C_YELLOW, m_poBackground );
	DrawTextMSZ( s, font, LEFTMARGIN2+i, y, 0, C_ORANGE, m_poBackground, false );

	m_sStory = SvPV_nolen(get_sv("Story", FALSE ));
	SDL_Rect oFlyingRect;
	oFlyingRect.x = LEFTMARGIN; 
	oFlyingRect.y = y+DESCMARGIN;
	oFlyingRect.w = gamescreen->w - oFlyingRect.x - 20;
	oFlyingRect.h = gamescreen->h - oFlyingRect.y - 10;
	m_poFlyingChars = new CFlyingChars( creditsFont, oFlyingRect );
	m_poFlyingChars->AddText( m_sStory.c_str(), CFlyingChars::FC_AlignJustify, false );

	if ( g_oPlayerSelect.IsFighterAvailable( m_enFighter ) )
	{
		m_sKeys = SvPV_nolen(get_sv("Keys", TRUE ));
		m_poFlyingChars->AddText( "\n\nKEYS\n", CFlyingChars::FC_AlignCenter, true );
		m_poFlyingChars->AddText( m_sKeys.c_str(), CFlyingChars::FC_AlignCenter, true );
	}
	else
	{
		m_sKeys = Translate("Unfortunately this fighter is not yet playable.");
		m_poFlyingChars->AddText( m_sKeys.c_str(), CFlyingChars::FC_AlignLeft, true );
	}
}
Esempio n. 3
0
/* This code is deprecated, but available for speed comparisons */
void DrawLogoBlit(void)
{
    static int x = 0;
    static int y = 0;
    static int w, h;
    static int delta_x = 1;
    static int delta_y = 1;

    SDL_Rect dst;
    SDL_Surface *screen = SDL_GetVideoSurface();

    if ( global_image == NULL ) {
        SDL_Surface *temp;

        /* Load the image (could use SDL_image library here) */
        temp = SDL_LoadBMP(LOGO_FILE);
        if ( temp == NULL ) {
            return;
        }
        w = temp->w;
        h = temp->h;

        /* Convert the image into the screen format */
        global_image = SDL_CreateRGBSurface(
                           SDL_SWSURFACE,
                           w, h,
                           screen->format->BitsPerPixel,
                           screen->format->Rmask,
                           screen->format->Gmask,
                           screen->format->Bmask,
                           screen->format->Amask);
        if ( global_image ) {
            SDL_BlitSurface(temp, NULL, global_image, NULL);
        }
        SDL_FreeSurface(temp);

        /* Make sure that the texture conversion is okay */
        if ( ! global_image ) {
            return;
        }
    }

    /* Move the image around
           Note that we do not clear the old position.  This is because we
           perform a glClear() which clears the framebuffer and then only
           update the new area.
           Note that you can also achieve interesting effects by modifying
           the screen surface alpha channel.  It's set to 255 by default..
         */
    x += delta_x;
    if ( x < 0 ) {
        x = 0;
        delta_x = -delta_x;
    } else if ( (x+w) > screen->w ) {
        x = screen->w-w;
        delta_x = -delta_x;
    }
    y += delta_y;
    if ( y < 0 ) {
        y = 0;
        delta_y = -delta_y;
    } else if ( (y+h) > screen->h ) {
        y = screen->h-h;
        delta_y = -delta_y;
    }
    dst.x = x;
    dst.y = y;
    dst.w = w;
    dst.h = h;
    SDL_BlitSurface(global_image, NULL, screen, &dst);

    /* Show the image on the screen */
    SDL_UpdateRects(screen, 1, &dst);
}
Esempio n. 4
0
void move_cell(int place_x, int place_y, SDL_Surface * screen, SDL_Surface * sprite, t_tab tab, int theplacecursor, SDL_Rect totalplace[100], SDL_Surface * cell[100], int current_cell) {
    SDL_Event event;
    int keep = 1;
    int i;
    SDL_Rect place;
    place.x = place_x;
    place.y = place_y;
    while (keep) {
        SDL_WaitEvent(&event);
        switch (event.type) {
            case SDL_QUIT:
                SDL_Quit();
                break;
            case SDL_KEYDOWN:
                switch (event.key.keysym.sym) {

                    case SDLK_RIGHT:
                        if (place.x < 11 * SIZE_BLOC) {
                            //SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 255, 255, 255));
                            screen_editor(screen, theplacecursor);
                            place.x = place.x + SIZE_BLOC;

                            SDL_BlitSurface(sprite, NULL, screen, &place);
                            if (current_cell != 1) {
                                for (i = 1; i <= current_cell - 1; i++) {

                                    SDL_BlitSurface(cell[i], NULL, screen, &totalplace[i]);

                                }
                            }
                            SDL_Flip(screen);
                        }


                        break;
                    case SDLK_LEFT:
                        if (place.x > 0) {
                            //SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 255, 255, 255));
                            screen_editor(screen, theplacecursor);
                            place.x = place.x - SIZE_BLOC;
                            SDL_BlitSurface(sprite, NULL, screen, &place);
                            for (i = 1; i <= current_cell - 1; i++) {

                                SDL_BlitSurface(cell[i], NULL, screen, &totalplace[i]);

                            }
                            SDL_Flip(screen);
                        }

                        break;
                    case SDLK_UP:
                        if (place.y > 0) {
                            //SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 255, 255, 255));
                            screen_editor(screen, theplacecursor);
                            place.y = place.y - SIZE_BLOC;
                            SDL_BlitSurface(sprite, NULL, screen, &place);
                            for (i = 1; i <= current_cell - 1; i++) {

                                SDL_BlitSurface(cell[i], NULL, screen, &totalplace[i]);

                            }
                            SDL_Flip(screen);
                        }

                        break;
                    case SDLK_DOWN:
                        if (place.y < 10 * SIZE_BLOC) {
                            //SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 255, 255, 255));
                            screen_editor(screen, theplacecursor);
                            place.y = place.y + SIZE_BLOC;
                            SDL_BlitSurface(sprite, NULL, screen, &place);
                            for (i = 1; i <= current_cell - 1; i++) {

                                SDL_BlitSurface(cell[i], NULL, screen, &totalplace[i]);

                            }
                            SDL_Flip(screen);
                        }

                        break;
                    case SDLK_RETURN:

                        keep = 0;
                        break;
                    default:
                        break;
                }
        }
    }
    tab->x = place.x;
    tab->y = place.y;
}
Esempio n. 5
0
void bliterArrierePlan(SDL_Surface *ecran, Camera camera, int largeurFenetre, int hauteurFenetre, Portion_Map world[][PROFONDEUR_MONDE], int tempsJour)
{
    int chunkX(0), chunkY(0), blocX(0), blocY(0);

    SDL_Rect positionBloc;
    SDL_Rect positionSoleil;
    SDL_Surface *soleil(IMG_Load("textures/ciel/soleil.png"));
    SDL_Surface *lune(IMG_Load("textures/ciel/lune.png"));
    SDL_Surface *pierreBackGround(IMG_Load("textures/ciel/backGroundPierre.png"));
    SDL_Surface *terreBackGround(IMG_Load("textures/ciel/backGroundTerre.png"));

    positionSoleil.x = largeurFenetre / 4;
    positionSoleil.y = hauteurFenetre / 4;

    if (tempsJour >= 32400 && tempsJour <= 75600)
    {
        SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 119, 181, 254));
        SDL_BlitSurface(soleil, NULL, ecran, &positionSoleil);

        for (int x(0); x < LARGEUR_MONDE; x++)
        {
            for (int y(0); y < PROFONDEUR_MONDE; y++)
            {
                for (int a(0); a < LARGEUR_PARTIE_MAP; a++)
                {
                    for (int b(0); b < PROFONDEUR_PARTIE_MAP; b++)
                    {
                        world[x][y].blocs[a][b].luminosite = 15;
                    }
                }
            }
        }
    }
    else
    {
        SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 4, 7, 10));
        SDL_BlitSurface(lune, NULL, ecran, &positionSoleil);

        for (int x(0); x < LARGEUR_MONDE; x++)
        {
            for (int y(0); y < PROFONDEUR_MONDE; y++)
            {
                for (int a(0); a < LARGEUR_PARTIE_MAP; a++)
                {
                    for (int b(0); b < PROFONDEUR_PARTIE_MAP; b++)
                    {
                        world[x][y].blocs[a][b].luminosite = 3;
                    }
                }
            }
        }
    }

    for (int x(0); x < LARGEUR_MONDE * LARGEUR_PARTIE_MAP * TAILLE_BLOCK; x += TAILLE_BLOCK)
    {
        for (int y(0); y < LARGEUR_MONDE * LARGEUR_PARTIE_MAP * TAILLE_BLOCK; y += TAILLE_BLOCK)
        {
            positionBloc.x = x - camera.posCamX;
            positionBloc.y = y - camera.posCamY;

            chunkX = (x / TAILLE_BLOCK) / LARGEUR_PARTIE_MAP;
            chunkY = (y / TAILLE_BLOCK) / PROFONDEUR_PARTIE_MAP;
            blocX = (x / TAILLE_BLOCK) - (chunkX * LARGEUR_PARTIE_MAP);
            blocY = (y / TAILLE_BLOCK) - (chunkY * PROFONDEUR_PARTIE_MAP);

            if ((chunkY * PROFONDEUR_PARTIE_MAP) + blocY > 54 && (chunkY * PROFONDEUR_PARTIE_MAP) + blocY <= 64 && world[chunkX][chunkY].blocs[blocX][blocY].type == AIR)
            {
                if (x > camera.posCamX - TAILLE_BLOCK && x < (camera.posCamX + largeurFenetre) + TAILLE_BLOCK)
                {
                    if (y > camera.posCamY - TAILLE_BLOCK && y < (camera.posCamY + hauteurFenetre) + TAILLE_BLOCK)
                    {
                        SDL_BlitSurface(terreBackGround, NULL, ecran, &positionBloc);
                    }
                }
            }
            else if ((chunkY * PROFONDEUR_PARTIE_MAP) + blocY > 64 && world[chunkX][chunkY].blocs[blocX][blocY].type == AIR)
            {
                SDL_BlitSurface(pierreBackGround, NULL, ecran, &positionBloc);
            }
        }
    }

    SDL_FreeSurface(soleil);
    SDL_FreeSurface(lune);
    SDL_FreeSurface(pierreBackGround);
    SDL_FreeSurface(terreBackGround);
}
Esempio n. 6
0
int runEditor(SDL_Surface* screen)
{
  SDL_Rect selBrickRect;
  getInpPointerState()->escEnable=1;

  if( editorState == EDITOR_MAIN )
  {

    if(getButton(C_BTNMENU) || isPointerEscapeClicked() )
    {
      resetBtn( C_BTNMENU );
      resetMouseBtn();

      changed++; //If it was 0 then it will become 1 (saved) exit. If it was 1 it becomes 2 (not saved).
      if( changed != 2 )
      {
        editorCleanUp();
        startTransition(screen, TRANSITION_TYPE_ROLL_IN, 500 );
        return(STATEMENU);
      }
    }

    //We detect if the "preview" brick on the left is clicked, we do this now so we can reset the click so that it does not hit the board
    selBrickRect.x = HSCREENW-125;
    selBrickRect.y = HSCREENH-85;
    selBrickRect.w = selBrickRect.x+20;
    selBrickRect.h = selBrickRect.y+20;
    //Also, we can only click it if a teleport destination is not being placed.
    if( isBoxClicked(&selBrickRect) && teleState==0 )
    {
      editorState=EDITOR_BRICKS_SELECTION;
      resetMouseBtn();
    }

    //We detect mouse-save input here so it won't hit the board.
    selBrickRect.x = HSCREENW-145;
    selBrickRect.y = HSCREENH+42;
    selBrickRect.w = selBrickRect.x+59;
    selBrickRect.h = selBrickRect.y+24;
    if( isBoxClicked(&selBrickRect) && changed>0)
    {
      changed=EDITOR_SAVEBTN_CLICKED;
      resetMouseBtn();
    }

    //We check if the cursor is in the field (if it is not, brick-placement is blocked so we don't place bricks when clicking outside of the field).
    if( isPointerInBox(&fieldRect) || getInpPointerState()->timeSinceMoved > POINTER_SHOW_TIMEOUT )
    {
      allowBrickToBePlaced=1;
    } else {
      allowBrickToBePlaced=0;
    }

    //Handle movement
    if(getButton(C_UP))
    {
      resetBtn(C_UP);
      moveCursor(&cur, 0,DIRUP, 0);
    }

    if(getButton(C_DOWN))
    {
      resetBtn(C_DOWN);
      moveCursor(&cur, 0,DIRDOWN,0);
    }

    if(getButton(C_LEFT))
    {
      resetBtn(C_LEFT);
      moveCursor(&cur, DIRLEFT,0, 0);
    }

    if(getButton(C_RIGHT))
    {
      resetBtn(C_RIGHT);
      moveCursor(&cur, DIRRIGHT,0, 0);
    }

    //Handle mouse input
    if( getInpPointerState()->timeSinceMoved==0 && !cur.lock )
    {
      setCursor(&cur, getInpPointerState()->curX,getInpPointerState()->curY );
    }

    if(getButton(C_BTNB))
    {
      resetBtn(C_BTNB);
      selBrick++;

      if(selBrick==RESERVED)
        selBrick++;

      if(selBrick>NUMTILES)
        selBrick=1;
    }

    if(getButton(C_BTNA))
    {
      resetBtn(C_BTNA);

      selBrick--;
      if(selBrick==RESERVED)
        selBrick--;

      if(selBrick<1)
        selBrick=NUMTILES;
    }



    //Is place brick button being pressed, and if it is, are we allowed to place the brick?
    if( (getButton(C_BTNX) || getInpPointerState()->isDown ) && selBrick != RESERVED && allowBrickToBePlaced )
    {

      //We remove the brick before placing a new one if it's not a teleport or if it's a switch (not switch-target).
      if( selBrick!=TELESRC && !((editIsSwitch(selBrick)&&teleState==1)  ) )
      {
        editorRemoveBrickUnderCursor();
      }

      if(selBrick==TELESRC || editIsSwitch(selBrick) )
      {
        resetMouseBtn();
        resetBtn(C_BTNX);

        if(teleState==0)
        {
          //Save source pos
          teleSrcPos[0] = cur.x;
          teleSrcPos[1] = cur.y;
          teleState++;
        } else {
          //Add to list
          if(editIsSwitch(selBrick))
          {
            teleAddToList( pf.levelInfo->switchList, teleSrcPos[0], teleSrcPos[1], cur.x, cur.y );
            //printf("Number of members in switchList: %i\n", listSize(pf.levelInfo->switchList) );
            cur.x = teleSrcPos[0];
            cur.y = teleSrcPos[1];
            editAddToBoard(selBrick);
          } else {
            teleAddToList( pf.levelInfo->teleList, teleSrcPos[0], teleSrcPos[1], cur.x, cur.y );
          }
          //Reset state
          teleState=0;
        }
      } else {
        editAddToBoard(selBrick);
      } //Not a teleport

      changed=1;
    }

    if( getButton(C_BTNY) )
    {
      //If we are trying to remove an empty teleport
      if(telePresent(pf.levelInfo->teleList, cur.x, cur.y) && selBrick!=TELESRC)
      {
        resetBtn(C_BTNY);
        selBrick=TELESRC;
      } else {
        if(selBrick!=RESERVED)
        {
          editorPickBrickUnderCursor();
        }
        editorRemoveBrickUnderCursor();
      }
    }

    if( getInpPointerState()->isDown && selBrick==RESERVED )
    {
      editorRemoveBrickUnderCursor();
    }

    if(getButton(C_BTNSELECT) || changed==EDITOR_SAVEBTN_CLICKED)
    {
      resetBtn(C_BTNSELECT);
      FILE *f = fopen(fileName, "w");
      int x,y;
      sprintf(buf, "#Author of level\nauthor=%s\n\n", pf.levelInfo->author);
      fputs(buf,f);

      sprintf(buf, "#Name of the level\nlevelname=%s\n\n", pf.levelInfo->levelName);
      fputs(buf,f);

      sprintf(buf, "#Seconds to complete level\nseconds=%i\n\n", pf.levelInfo->time);
      fputs(buf,f);

      sprintf(buf, "bgfile=%s\n", pf.levelInfo->bgFile);
      fputs(buf,f);

      sprintf(buf, "tilebase=%s\n", pf.levelInfo->tileBase);
      fputs(buf,f);

      sprintf(buf, "explbase=%s\n", pf.levelInfo->explBase);
      fputs(buf,f);

      sprintf(buf, "wallbase=%s\n", pf.levelInfo->wallBase);
      fputs(buf,f);

      sprintf(buf, "sounddir=%s\n", pf.levelInfo->soundDir);
      fputs(buf,f);

      sprintf(buf, "charbase=%s\n", pf.levelInfo->fontName);
      fputs(buf,f);

      sprintf(buf, "cursorfile=%s\n", pf.levelInfo->cursorFile);
      fputs(buf,f);

      sprintf(buf, "startimage=%s\n", (pf.levelInfo->startImg)?pf.levelInfo->startImg:"none");
      fputs(buf,f);

      sprintf(buf, "stopimage=%s\n", (pf.levelInfo->stopImg)?pf.levelInfo->stopImg:"none");
      fputs(buf,f);

      sprintf(buf, "showtelepath=%i\n", (pf.levelInfo->showTelePath) );
      fputs(buf,f);

      sprintf(buf, "showswitchpath=%i\n", (pf.levelInfo->showSwitchPath) );
      fputs(buf,f);


      //Teleports
      char* str = teleMkStrings(pf.levelInfo->teleList, "teleport");
      if(str) //Returns 0 if there's no teleports
      {
        fputs("\n#Teleports\n",f);
        fputs(str,f);
        free(str);
      }

      //Switches
      str = teleMkStrings(pf.levelInfo->switchList, "switch");
      if(str) //Returns 0 if there's no teleports
      {
        fputs("\n#Switches\n",f);
        fputs(str,f);
        free(str);
      }



      fputs("\n#The level-data block\n[data]",f);

      if(f)
      {
        for(y=0; y < FIELDSIZE; y++)
        {
          fputc('\n',f);
          for(x=0; x < FIELDSIZE; x++)
          {
            if(pf.board[x][y])
            {
              fprintf(f,"%02i", pf.board[x][y]->type);
            } else {
              fprintf(f,"00");
            }
          }
        }
        fputc('\n',f);
        changed=0;
        fclose(f);

        //Refresh the list of userLevels.
        addUserLevel(fileName);
      }

    }

  } //Editor in main state, don't ignore input


  draw(&cur, &pf, screen);


  if(changed==2)
  {
    txtWriteCenter(screen, FONTMEDIUM, STR_EDIT_NOT_SAVED_WARNING, HSCREENW,HSCREENH-20);
    txtWriteCenter(screen, FONTSMALL, STR_EDIT_PRESS_EXIT_TO_EXIT, HSCREENW,HSCREENH);
    txtWriteCenter(screen, FONTSMALL, STR_EDIT_PRESS_SAVE_TO_SAVE, HSCREENW,HSCREENH+10);
  }


  txtWriteCenter(screen, FONTSMALL,STR_EDIT_STATUS, HSCREENW-115,HSCREENH+80);
  txtWriteCenter(screen, FONTSMALL, (changed)?STR_EDIT_UNSAVED:STR_EDIT_SAVED, HSCREENW-115,HSCREENH+89);

  txtWriteCenter(screen, FONTSMALL,fileName, HSCREENW,HSCREENH+110);

  txtWriteCenter(screen, FONTSMALL,STR_EDIT_CONTROLS, HSCREENW,HSCREENH-120);


  //Write which keys are used to cycle selected brick.
  txtWriteCenter(screen, FONTSMALL,STR_EDIT_PREVBRICK_KEY,HSCREENW-142,HSCREENH-80);
  txtWriteCenter(screen, FONTSMALL,STR_EDIT_NEXTBRICK_KEY,HSCREENW-88,HSCREENH-80);


  //Draw the currently selected brick.
  drawBrick(screen, selBrick,HSCREENW-125,HSCREENH-85);

  //Write brick name.
  txtWriteCenter(screen, FONTSMALL, str_brick_names[selBrick], HSCREENW-116,HSCREENH-56 );

  //Tell if we're placing teleport source or destination
  if(selBrick==TELESRC && teleState==0)
  {
    txtWriteCenter(screen, FONTSMALL, "(From)", HSCREENW-115,HSCREENH-41);
  } else if(teleState)
  {
    if(selBrick==TELESRC)
    {
      txtWriteCenter(screen, FONTSMALL, "(To)", HSCREENW-115,HSCREENH-41);
    } else {
      txtWriteCenter(screen, FONTSMALL, "(Target)", HSCREENW-115,HSCREENH-41);
    }
    drawPath(screen, teleSrcPos[0], teleSrcPos[1], cur.x, cur.y, 1);
  }

  //Draw all the telepaths.
  drawAllTelePaths(screen, pf.levelInfo->teleList);


  //Draw switchpath we hover above
  listItem* t = &pf.levelInfo->switchList->begin;
  while( LISTFWD(pf.levelInfo->switchList, t) )
  {
    telePort_t* tp=(telePort_t*)t->data;
    if(cur.x == tp->sx && cur.y == tp->sy)
    {
      drawTelePath( screen, tp, 1 );
    }
  }
  //Draw all switchpaths
  drawAllTelePaths(screen, pf.levelInfo->switchList);

  if( (getInpPointerState()->timeSinceMoved < POINTER_SHOW_TIMEOUT) && (changed > 0) )
  {
    drawSprite(screen, saveBtnSprite, HSCREENW-145, HSCREENH+42 );
  }

  //Draw brick-selection
  if( editorState == EDITOR_BRICKS_SELECTION )
  {
    SDL_BlitSurface(selBrickBG , NULL, screen, &(setting()->bgPos) );

    //Draw bricks in a 6*4 grid
    int px,py,bnum=BRICKSBEGIN;
    static int brickSelOfX = HSCREENW - 78 + 8;
    static int brickSelOfY = HSCREENH - 54 + 8;
    for(py=0;py < 4; py++)
    {
      for(px=0; px < 6; px++)
      {
        if( bnum > NUMTILES )
          break;
        selBrickRect.x = brickSelOfX+(24*px);
        selBrickRect.y = brickSelOfY+(24*py);
        selBrickRect.w = selBrickRect.x+20;
        selBrickRect.h = selBrickRect.y+20;


        //We set bricks on mouseover, this way we get the description too (maybe punch a hole in the dots where the text is?)
        if( isPointerInBox(&selBrickRect) )
        {
          selBrick=bnum;
        }

        //We continue back to the main editor
        if( isPointerClicked() )
        {
          resetMouseBtn();
          editorState=EDITOR_MAIN;
        }

        drawBrick(screen, bnum, selBrickRect.x, selBrickRect.y );
        bnum++;
      }
    }
  }

  return(STATEEDIT);
}
Esempio n. 7
0
int map_editor(SDL_Surface *screen) {
    int i, j;

    FILE* fichier = NULL;
    fichier = fopen("map/map_default.txt", "w+"); //opens the target file that will contain the custom map
    fprintf(fichier, "12:12\n");
    int placecursor = 5;
    int valuecursor = 1;
    int current_cell = 1;
    screen_editor(screen, placecursor);
    SDL_Event event;
    int keep = 1;
    t_tab tab = malloc(sizeof (struct s_tab));
    SDL_Rect place[100];
    SDL_Surface * cell[144] = {CELL_EMPTY}; //creates as much surfaces as possible
    t_cell_type grid[12][12];   //the grid will be used to write the cell types in the file
    for (i = 0; i <= 11; i++) {
        for (j = 0; j <= 11; j++) {
            grid[i][j] = 0;
        }
    }
    for (i = 0; i <= 100; i++) { //each surface will be firstly located in (0,0)
        place[i].x = 0;
        place[i].y = 0;
    }
    tab->x = 0;
    tab->y = 0;
    tab->sprite_type = NULL;
    tab->empty = 0;
    tab->player_set=0;

    int white_bloc = ((12 * SIZE_BLOC) - 6 * SIZE_BLOC) / 4;
    while (keep != 0) {
        tab->empty = 0;
        SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 255, 255, 255));
        screen_editor(screen, placecursor);

        if (current_cell > 1) { //Sticks all the cells the user has defined
            for (i = 1; i <= current_cell - 1; i++) {

                SDL_BlitSurface(cell[i], NULL, screen, &place[i]);

            }
        }
        SDL_Flip(screen);
        SDL_WaitEvent(&event);

        switch (event.type) {


            case SDL_QUIT:
                return 2;
                break;

            case SDL_KEYDOWN:

                switch (event.key.keysym.sym) {

                    case SDLK_RIGHT: //move the cursor that chooses which cell type to stick
                        if (placecursor < 10 * SIZE_BLOC) {
                            placecursor = placecursor + 0.25 * white_bloc + SIZE_BLOC;
                            valuecursor++;
                        }

                        break;
                    case SDLK_LEFT:
                        if (placecursor > 5) {
                            valuecursor--;
                            placecursor = placecursor - 0.25 * white_bloc - SIZE_BLOC;
                        }

                        break;
                    case SDLK_RETURN: //validates the choice of a cell type

                        if (valuecursor == 1) {
                            tab->sprite_type = IMG_Load(IMG_MAP_STONE);
                            tab->value_sprite = 21;
                        } else if (valuecursor == 2) {
                            tab->sprite_type = IMG_Load(IMG_MAP_TREE);
                            tab->value_sprite = 22;
                        } else if (valuecursor == 3) {
                            tab->sprite_type = IMG_Load(IMG_MAP_KEY);
                            tab->value_sprite = 8;
                        } else if (valuecursor == 4) {
                            tab->sprite_type = IMG_Load(IMG_MAP_CASE);
                            tab->value_sprite = 4;
                        } else if (valuecursor == 5) {
                            tab->sprite_type = IMG_Load(IMG_MAP_CLOSED_DOOR);
                            tab->value_sprite = 10;
                        } else if (valuecursor == 6) {
                            tab->sprite_type = IMG_Load(IMG_MONSTER_DOWN);
                            tab->value_sprite = 6;
                        } else if (valuecursor == 7) {
                            tab->sprite_type = IMG_Load(IMG_PLAYER_DOWN);
                            tab->value_sprite = 3;
                            if(tab->player_set==1){break;} //check if a player is already placed
                            tab->player_set=1;
                        } else if (valuecursor == 7) {
                            tab->sprite_type = IMG_Load(IMG_PLAYER_DOWN);
                            tab->value_sprite = 3;

                        } else if (valuecursor == 8) {
                            tab->sprite_type = IMG_Load(IMG_ERASER);
                            tab->value_sprite = 0;
                            tab->empty = 1;
                        }
                        SDL_BlitSurface(tab->sprite_type, NULL, screen, &place[current_cell]);
                        SDL_Flip(screen);

                        move_cell(tab->x, tab->y, screen, tab->sprite_type, tab, placecursor, place, cell, current_cell);
                        place[current_cell].x = tab->x;
                        place[current_cell].y = tab->y;

                        if (tab->empty == 1) { //if the user wants to correct something he did wrong
                            for (i = 1; i <= current_cell - 1; i++) {
                                if (place[i].x == tab->x && place[i].y == tab->y) {
                                    cell[i] = CELL_EMPTY;
                                }
                                if(grid[place[i].x/SIZE_BLOC][place[i].y/SIZE_BLOC]==3){tab->player_set=0;}
                            }
                        } else { //or he defines a currently empty case or replaces an existing case
                            for (i = 1; i <= current_cell - 1; i++) {
                                if (place[i].x == tab->x && place[i].y == tab->y && cell[i] != CELL_EMPTY) {
                                    cell[i] = CELL_EMPTY;
                                }
                            }
                            cell[current_cell] = tab->sprite_type;
                        }
                        grid[tab->x / SIZE_BLOC][tab->y / SIZE_BLOC] = tab->value_sprite; //sets the grid cell
                        current_cell++;
                        for (i = 1; i <= current_cell - 1; i++) {
                            SDL_BlitSurface(cell[i], NULL, screen, &place[i]);
                        }
                        tab->x = 0;
                        tab->y = 0;
                        SDL_Flip(screen);


                        break;
                    case SDLK_d: // the user is done

                        for (i = 0; i <= 11; i++) { //write it all in the file
                            for (j = 0; j <= 11; j++) {
                                fprintf(fichier, "%d", grid[j][i]);
                                if (j != 11) {
                                    fprintf(fichier, " ");
                                }
                            }
                            fprintf(fichier, "\n");
                        }
                        keep = 0;

                        break;


                    default:
                        screen_editor(screen, placecursor);
                        break;
                }

                break;


        }

    }
    fclose(fichier);
    return 0;
}
Esempio n. 8
0
int main()
{
    SDL_Surface *temp;
    SDL_Surface *background;
    SDL_Rect src, dest;
    int frames;

    /* Initialize SDL's video system and check for errors. */
    if (SDL_Init(SDL_INIT_VIDEO) != 0) {
	printf("Unable to initialize SDL: %s\n", SDL_GetError());
	return 1;
    }

    /* Make sure SDL_Quit gets called when the program exits! */
    atexit(SDL_Quit);

    /* Attempt to set a 640x480 hicolor (16-bit) video mode with
       a double buffer. Note that on some display targets you're actually
       better off without these options. */
    screen = SDL_SetVideoMode(640, 480, 16, SDL_DOUBLEBUF | SDL_HWSURFACE);
    if (screen == NULL) {
	printf("Unable to set video mode: %s\n", SDL_GetError());
	return 1;
    }

    /* Load the background image and convert it to the display's
       pixel format. This conversion will drastically improve the
       performance of SDL_BlitSurface, as it will not have to
       convert the surface on the fly. */
    temp = SDL_LoadBMP("background.bmp");
    background = SDL_DisplayFormat(temp);
    if (background == NULL) {
	printf("Unable to load bitmap.\n");
	return 1;
    }
    SDL_FreeSurface(temp);

    /* Load the penguin image. */
    temp = SDL_LoadBMP("smallpenguin.bmp");
    if (temp == NULL) {
	printf("Unable to load bitmap.\n");
	return 1;
    }

    /* Set the penguin's colorkey. Ask for RLE acceleration,
       a technique which can significantly speed up colorkey
       blits. */
    SDL_SetColorKey(temp,
		    SDL_SRCCOLORKEY | SDL_RLEACCEL,
		    (Uint16) SDL_MapRGB(temp->format, 0, 0, 255));

    /* Convert the penguin to the display's format. We do this after
       we set the colorkey, since colorkey blits can sometimes be
       optimized for a particular display. */
    penguin = SDL_DisplayFormat(temp);
    if (penguin == NULL) {
	printf("Unable to convert bitmap.\n");
	return 1;
    }
    SDL_FreeSurface(temp);

    /* Initialize the penguin position data. */
    init_penguins();

    /* Animate 300 frames (approximately 10 seconds). */
    for (frames = 0; frames < 300; frames++) {

	/* Draw the background image. */
	src.x = 0;
	src.y = 0;
	src.w = background->w;
	src.h = background->h;
	dest = src;

	SDL_BlitSurface(background, &src, screen, &dest);

	/* Put the penguins on the screen. */
	draw_penguins();

	/* Ask SDL to swap the back buffer to the screen. */
	SDL_Flip(screen);

	/* Move the penguins for the next frame. */
	move_penguins();
    }

    /* Free the memory that was allocated to the bitmap. */
    SDL_FreeSurface(background);
    SDL_FreeSurface(penguin);

    return 0;
}
/******************************************************************************
Description.: this is the main worker thread
              it loops forever, grabs a fresh frame, decompressed the JPEG
              and displays the decoded data using SDL
Input Value.:
Return Value:
******************************************************************************/
void *worker_thread(void *arg)
{
    int frame_size = 0, firstrun = 1;

    SDL_Surface *screen = NULL, *image = NULL;
    decompressed_image rgbimage;

    /* initialze the buffer for the decompressed image */
    rgbimage.buffersize = 0;
    rgbimage.buffer = NULL;

    /* initialze the SDL video subsystem */
    if(SDL_Init(SDL_INIT_VIDEO) < 0) {
        fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
        exit(EXIT_FAILURE);
    }

    /* just allocate a large buffer for the JPEGs */
    if((frame = malloc(4096 * 1024)) == NULL) {
        OPRINT("not enough memory for worker thread\n");
        exit(EXIT_FAILURE);
    }

    /* set cleanup handler to cleanup allocated ressources */
    pthread_cleanup_push(worker_cleanup, NULL);

    while(!pglobal->stop) {
        DBG("waiting for fresh frame\n");
        pthread_cond_wait(&pglobal->in[plugin_number].db_update, &pglobal->in[plugin_number].db);

        /* read buffer */
        frame_size = pglobal->in[plugin_number].size;
        memcpy(frame, pglobal->in[plugin_number].buf, frame_size);

        pthread_mutex_unlock(&pglobal->in[plugin_number].db);

        /* decompress the JPEG and store results in memory */
        if(decompress_jpeg(frame, frame_size, &rgbimage)) {
            DBG("could not properly decompress JPEG data\n");
            continue;
        }

        if(firstrun) {
            /* create the primary surface (the visible window) */
            screen = SDL_SetVideoMode(rgbimage.width, rgbimage.height, 0, SDL_ANYFORMAT | SDL_HWSURFACE);
            SDL_WM_SetCaption("MJPG-Streamer Viewer", NULL);

            /* create a SDL surface to display the data */
            image = SDL_AllocSurface(SDL_SWSURFACE, rgbimage.width, rgbimage.height, 24,
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
                                     0x0000FF, 0x00FF00, 0xFF0000,
#else
                                     0xFF0000, 0x00FF00, 0x0000FF,
#endif
                                     0);

            /* copy the decoded data across */
            memcpy(image->pixels, rgbimage.buffer, rgbimage.width * rgbimage.height * 3);
            free(rgbimage.buffer);

            /* now, that we know the dimensions, we can directly copy to the right surface */
            rgbimage.buffer = image->pixels;
            rgbimage.buffersize = rgbimage.width * rgbimage.height * 3;

            firstrun = 0;
        }

        /* copy the image to the primary surface */
        SDL_BlitSurface(image, NULL, screen, NULL);

        /* redraw the whole surface */
        SDL_Flip(screen);
    }

    pthread_cleanup_pop(1);

    /* get rid of the image */
    SDL_FreeSurface(image);

    return NULL;
}
Esempio n. 10
0
int doSDL(void) {
    SDL_Surface *screen = NULL;
    SDL_Surface *rot = NULL;
    const SDL_VideoInfo *videoInfo = NULL;
    double scale;
    int prevValue = 0;
    int rc = 0;

    pthread_t thread[7];
    void *status[7];

    pthread_mutex_init(&mutexVALUE, NULL); 
    pthread_mutex_init(&mutexIMAGE, NULL);

    pthread_create(&thread[0], NULL, take_screen, NULL);

    /*-----------------------------------------------------------------*/

    if (SDL_Init(SDL_INIT_VIDEO) < 0)
    {
        fprintf(stderr, "SDL_Init failed - %s\n", SDL_GetError());
        return 1;
    }

    /*-----------------------------------------------------------------*/

    videoInfo = SDL_GetVideoInfo();

    if (videoInfo == 0)
    {
        fprintf(stderr, "SDL_GetVideoInfo failed - %s\n", SDL_GetError());
        SDL_Quit();
        return 1;
    }

    /*-----------------------------------------------------------------*/

    rc = pthread_join(thread[0], &status[0]);

    pthread_create(&thread[1], NULL, get_screen, NULL);

    pthread_create(&thread[0], NULL, take_screen, NULL);

    rc = pthread_join(thread[1], &status[1]);

    pthread_create(&thread[2], NULL, load_image, NULL);
    
    rc = pthread_join(thread[0], &status[0]);

    /*-----------------------------------------------------------------*/
while(1){
    pthread_create(&thread[1], NULL, get_screen, NULL);

    pthread_create(&thread[0], NULL, take_screen, NULL);

    pthread_create(&thread[3], NULL, get_height, NULL);

    rc = pthread_join(thread[3], &status[3]);

    rc = pthread_join(thread[1], &status[1]);

    pthread_create(&thread[2], NULL, load_image, NULL);

    rc = pthread_join(thread[2], &status[2]);

    if (value != image->h) {
        //scale = (image->w)/(videoInfo->current_w);
        scale = 1;
	if (prevValue != image->h) {
	    screen = SDL_SetVideoMode((image->h)*scale,
		                      (image->w)*scale,
		                      videoInfo->vfmt->BitsPerPixel,
		                      SDL_SWSURFACE|SDL_DOUBLEBUF);
	}
        rot = rotozoomSurface( image, 90, scale, SMOOTHING_ON );
    }

    else if (value == image->h) {
	//scale = (image->h)/(videoInfo->current_h);
        scale = 0.5;
	if (prevValue != image->h) {
	    screen = SDL_SetVideoMode((image->w)*scale,
		                      (image->h)*scale,
		                      videoInfo->vfmt->BitsPerPixel,
		                      SDL_SWSURFACE|SDL_DOUBLEBUF);
	}
        rot = rotozoomSurface( image, 0, scale, SMOOTHING_ON );
    }

    SDL_FreeSurface(image);

    SDL_BlitSurface(rot, NULL, screen, 0);

    //SDL_Flip(screen);
    SDL_UpdateRect(screen, 0, 0, 0, 0);

    SDL_FreeSurface(rot);

    prevValue = value;

    rc = pthread_join(thread[0], &status[0]);
}

    SDL_Quit();

    return 0;
}
Esempio n. 11
0
int main(int argc, char *argv[])
{
	SDL_Surface *screen;
	TTF_Font *font;
	SDL_Surface *text;
	int ptsize;
	int done;
    SDL_Color mybackcolor = {0xff, 0, 0, 0};
    SDL_Color myforecolor = {0, 0, 0xff, 0};
	SDL_Color *forecol;
	SDL_Color *backcol;
	SDL_Rect dstrect;
	SDL_Event event;
	char *message;

	/* Default is black and white */
	forecol = &myforecolor;
	backcol = &mybackcolor;

	/* Initialize SDL */
	if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
		fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
		return(2);
	}

	/* Initialize the TTF library */
	if ( TTF_Init() < 0 ) {
		fprintf(stderr, "Couldn't initialize TTF: %s\n",SDL_GetError());
		SDL_Quit();
		return(2);
	}

	/* Open the font file with the requested point size */
    ptsize = DEFAULT_PTSIZE;
	font = TTF_OpenFont(DEFAULT_FONT, ptsize);
	if ( font == NULL ) {
		fprintf(stderr, "Couldn't load %d pt font from %s: %s\n",
					ptsize, DEFAULT_FONT, SDL_GetError());
		cleanup(2);
	}

	/* Set a 640x480x8 video mode */
	screen = SDL_SetVideoMode(640, 480, 8, SDL_SWSURFACE);
	if ( screen == NULL ) {
		fprintf(stderr, "Couldn't set 640x480x8 video mode: %s\n",
							SDL_GetError());
		cleanup(2);
	}

	/* Clear the background to background color */
	SDL_FillRect(screen, NULL,
			SDL_MapRGB(screen->format, backcol->r, backcol->g, backcol->b));
	SDL_UpdateRect(screen, 0, 0, 0, 0);

	/* Render and center the message */
    message = DEFAULT_TEXT;

	text = TTF_RenderText_Shaded(font,message,*forecol,*backcol);
	if ( text == NULL ) {
		fprintf(stderr, "Couldn't render text: %s\n", SDL_GetError());
		TTF_CloseFont(font);
		cleanup(2);
	}
	dstrect.x = (screen->w - text->w)/2;
	dstrect.y = (screen->h - text->h)/2;
	dstrect.w = text->w;
	dstrect.h = text->h;
	printf("Font is generally %d big, and string is %hd big\n",
						TTF_FontHeight(font), text->h);

	/* Blit the text surface */
	if ( SDL_BlitSurface(text, NULL, screen, &dstrect) < 0 ) {
		fprintf(stderr, "Couldn't blit text to display: %s\n", 
								SDL_GetError());
		TTF_CloseFont(font);
		cleanup(2);
	}
	SDL_UpdateRect(screen, 0, 0, 0, 0);

	/* Wait for a keystroke, and blit text on mouse press */
	done = 0;
	while ( ! done ) {
		if ( SDL_WaitEvent(&event) < 0 ) {
			fprintf(stderr, "SDL_PullEvent() error: %s\n",
								SDL_GetError());
			done = 1;
			continue;
		}
		switch (event.type) {
			case SDL_MOUSEBUTTONDOWN:
				dstrect.x = event.button.x - text->w/2;
				dstrect.y = event.button.y - text->h/2;
				dstrect.w = text->w;
				dstrect.h = text->h;
				if ( SDL_BlitSurface(text, NULL, screen,
							&dstrect) == 0 ) {
					SDL_UpdateRects(screen, 1, &dstrect);
				} else {
					fprintf(stderr,
					"Couldn't blit text to display: %s\n", 
								SDL_GetError());
				}
				break;
				
			case SDL_KEYDOWN:
			case SDL_QUIT:
				done = 1;
				break;
			default:
				break;
		}
	}
	SDL_FreeSurface(text);
	TTF_CloseFont(font);
	cleanup(0);

	/* Not reached, but fixes compiler warnings */
	return 0;
}
// This should be rewritten
void ScoreScrollNode::renderText()
{
	// Init variables
	SDL_Surface *name, *points, *place, *surface;
	surface = _screen->game()->buffer();

	Highscore *hs;
	std::stringstream str, str_place;

	// The texts position on text
	SDL_Rect position;
	position.x = 0;

	// Get scores
	highscore_list &scores = _screen->menu()->manager.get();

	// Create surface on which to draw stuff
	int num_scores = scores.size();
	int height = num_scores * 2 * _font_height;

	_height = height;

	// Kill old stuff
	for ( score_triplet_list::iterator iter = _scores.begin(); iter != _scores.end(); iter++ )
	{
		SDL_Surface **surfaces = (*iter);
		SDL_FreeSurface(surfaces[0]);
		SDL_FreeSurface(surfaces[1]);
		SDL_FreeSurface(surfaces[2]);
		delete [] surfaces;
	}

	_scores.erase(_scores.begin(), _scores.end());

	int i = 0;
	for ( highscore_list::iterator iter = scores.begin(); iter != scores.end(); iter++, i++ )
	{
		hs = *iter;
		str << hs->score << " points";
		str_place << (i + 1) << ". ";

		// Render texts
		place = TTF_RenderText_Blended(_font, str_place.str().c_str(), _name_color);
		name = TTF_RenderUNICODE_Blended(_font, hs->name, _name_color);
		points = TTF_RenderText_Blended(_font, str.str().c_str(), _score_color);

		SDL_Surface **surfaces = new SDL_Surface*[3];
		surfaces[0] = place;
		surfaces[1] = name;
		surfaces[2] = points;
		_scores.push_back(surfaces);

		str.str("");
		str_place.str("");
	}

	// draw()
	// the area on which we draw ourselves
	SDL_Rect rect = _screen->makeRect(_pos);

	SDL_FreeSurface(_image);
	_image = SDL_CreateRGBSurface(surface->flags, _pos.w, _pos.h, surface->format->BitsPerPixel, 0, 0, 0, 0);
	SDL_BlitSurface(_screen->menu()->overlay(), &rect, _image, NULL);

	// unit height is the height of one score element
	int unit_height = _font_height * 2;

	int start_score = _scroll_rect.y / unit_height;

	// Check bounds for end_score
	int end_score = _pos.h / unit_height + 2 + start_score;
	end_score = (end_score > _scores.size()) ? _scores.size() : end_score;

	SDL_Rect cp_position;
	position.x = 0;
	position.y = start_score * unit_height - _scroll_rect.y;

	score_triplet_list::iterator iter, to;
	iter = _scores.begin() + start_score;
	to = _scores.begin() + end_score;

	for (; iter != to; iter++)
	{
		SDL_Surface **surfaces = (*iter);

		// Place
		cp_position = position;
		SDL_BlitSurface(surfaces[0], NULL, _image, &cp_position);

		// Name
		position.x += surfaces[0]->clip_rect.w;
		cp_position = position;
		SDL_BlitSurface(surfaces[1], NULL, _image, &cp_position);

		// Points
		position.x -= surfaces[0]->clip_rect.w;
		position.y += _font_height;
		cp_position = position;
		SDL_BlitSurface(surfaces[2], NULL, _image, &cp_position);

		position.y += _font_height;
	}
}
Esempio n. 13
0
int IMG_SavePNG_RW(SDL_RWops *src, SDL_Surface *surf,int compression){
	png_structp png_ptr;
	png_infop info_ptr;
	SDL_PixelFormat *fmt=NULL;
	SDL_Surface *tempsurf=NULL;
	int ret,funky_format,used_alpha;
	unsigned int i,temp_alpha;
	png_colorp palette;
	Uint8 *palette_alpha=NULL;
	png_byte **row_pointers=NULL;
	png_ptr=NULL;info_ptr=NULL;palette=NULL;ret=-1;
	funky_format=0;
	
	if( !src || !surf) {
		goto savedone; /* Nothing to do. */
	}

	row_pointers=(png_byte **)malloc(surf->h * sizeof(png_byte*));
	if (!row_pointers) { 
		SDL_SetError("Couldn't allocate memory for rowpointers");
		goto savedone;
	}
	
	png_ptr=png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL,NULL,NULL);
	if (!png_ptr){
		SDL_SetError("Couldn't allocate memory for PNG file");
		goto savedone;
	}
	info_ptr= png_create_info_struct(png_ptr);
	if (!info_ptr){
		SDL_SetError("Couldn't allocate image information for PNG file");
		goto savedone;
	}
	/* setup custom writer functions */
	png_set_write_fn(png_ptr,(voidp)src,png_write_data,NULL);

	if (setjmp(png_jmpbuf(png_ptr))){
		SDL_SetError("Unknown error writing PNG");
		goto savedone;
	}

	if(compression>Z_BEST_COMPRESSION)
		compression=Z_BEST_COMPRESSION;

	if(compression == Z_NO_COMPRESSION) // No compression
	{
		png_set_filter(png_ptr,0,PNG_FILTER_NONE);
		png_set_compression_level(png_ptr,Z_NO_COMPRESSION);
	}
        else if(compression<0) // Default compression
		png_set_compression_level(png_ptr,Z_DEFAULT_COMPRESSION);
        else
		png_set_compression_level(png_ptr,compression);

	fmt=surf->format;
	if(fmt->BitsPerPixel==8){ /* Paletted */
		png_set_IHDR(png_ptr,info_ptr,
			surf->w,surf->h,8,PNG_COLOR_TYPE_PALETTE,
			PNG_INTERLACE_NONE,PNG_COMPRESSION_TYPE_DEFAULT,
			PNG_FILTER_TYPE_DEFAULT);
		palette=(png_colorp) malloc(fmt->palette->ncolors * sizeof(png_color));
		if (!palette) {
			SDL_SetError("Couldn't create memory for palette");
			goto savedone;
		}
		for (i=0;i<fmt->palette->ncolors;i++) {
			palette[i].red=fmt->palette->colors[i].r;
			palette[i].green=fmt->palette->colors[i].g;
			palette[i].blue=fmt->palette->colors[i].b;
		}
		png_set_PLTE(png_ptr,info_ptr,palette,fmt->palette->ncolors);
		if (surf->flags&SDL_SRCCOLORKEY) {
			palette_alpha=(Uint8 *)malloc((fmt->colorkey+1)*sizeof(Uint8));
			if (!palette_alpha) {
				SDL_SetError("Couldn't create memory for palette transparency");
				goto savedone;
			}
			/* FIXME: memset? */
			for (i=0;i<(fmt->colorkey+1);i++) {
				palette_alpha[i]=255;
			}
			palette_alpha[fmt->colorkey]=0;
			png_set_tRNS(png_ptr,info_ptr,palette_alpha,fmt->colorkey+1,NULL);
		}
	}else{ /* Truecolor */
		if (fmt->Amask) {
			png_set_IHDR(png_ptr,info_ptr,
				surf->w,surf->h,8,PNG_COLOR_TYPE_RGB_ALPHA,
				PNG_INTERLACE_NONE,PNG_COMPRESSION_TYPE_DEFAULT,
				PNG_FILTER_TYPE_DEFAULT);
		} else {
			png_set_IHDR(png_ptr,info_ptr,
				surf->w,surf->h,8,PNG_COLOR_TYPE_RGB,
				PNG_INTERLACE_NONE,PNG_COMPRESSION_TYPE_DEFAULT,
				PNG_FILTER_TYPE_DEFAULT);
		}
	}
	png_write_info(png_ptr, info_ptr);

	if (fmt->BitsPerPixel==8) { /* Paletted */
		for(i=0;i<surf->h;i++){
			row_pointers[i]= ((png_byte*)surf->pixels) + i*surf->pitch;
		}
		if(SDL_MUSTLOCK(surf)){
			SDL_LockSurface(surf);
		}
		png_write_image(png_ptr, row_pointers);
		if(SDL_MUSTLOCK(surf)){
			SDL_UnlockSurface(surf);
		}
	}else{ /* Truecolor */
		if(fmt->BytesPerPixel==3){
			if(fmt->Amask){ /* check for 24 bit with alpha */
				funky_format=1;
			}else{
				/* Check for RGB/BGR/GBR/RBG/etc surfaces.*/
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
				if(fmt->Rmask!=0xFF0000 
				|| fmt->Gmask!=0x00FF00
				|| fmt->Bmask!=0x0000FF){
#else
				if(fmt->Rmask!=0x0000FF 
				|| fmt->Gmask!=0x00FF00
				|| fmt->Bmask!=0xFF0000){
#endif
					funky_format=1;
				}
			}
		}else if (fmt->BytesPerPixel==4){
			if (!fmt->Amask) { /* check for 32bit but no alpha */
				funky_format=1; 
			}else{
				/* Check for ARGB/ABGR/GBAR/RABG/etc surfaces.*/
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
				if(fmt->Rmask!=0xFF000000
				|| fmt->Gmask!=0x00FF0000
				|| fmt->Bmask!=0x0000FF00
				|| fmt->Amask!=0x000000FF){
#else
				if(fmt->Rmask!=0x000000FF
				|| fmt->Gmask!=0x0000FF00
				|| fmt->Bmask!=0x00FF0000
				|| fmt->Amask!=0xFF000000){
#endif
					funky_format=1;
				}
			}
		}else{ /* 555 or 565 16 bit color */
			funky_format=1;
		}
		if (funky_format) {
			/* Allocate non-funky format, and copy pixeldata in*/
			if(fmt->Amask){
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
				tempsurf = SDL_CreateRGBSurface(SDL_SWSURFACE, surf->w, surf->h, 24,
										0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff);
#else
				tempsurf = SDL_CreateRGBSurface(SDL_SWSURFACE, surf->w, surf->h, 24,
										0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
#endif
			}else{
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
				tempsurf = SDL_CreateRGBSurface(SDL_SWSURFACE, surf->w, surf->h, 24,
										0xff0000, 0x00ff00, 0x0000ff, 0x00000000);
#else
				tempsurf = SDL_CreateRGBSurface(SDL_SWSURFACE, surf->w, surf->h, 24,
										0x000000ff, 0x0000ff00, 0x00ff0000, 0x00000000);
#endif
			}
			if(!tempsurf){
				SDL_SetError("Couldn't allocate temp surface");
				goto savedone;
			}
			if(surf->flags&SDL_SRCALPHA){
				temp_alpha=fmt->alpha;
				used_alpha=1;
				SDL_SetAlpha(surf,0,255); /* Set for an opaque blit */
			}else{
				used_alpha=0;
			}
			if(SDL_BlitSurface(surf,NULL,tempsurf,NULL)!=0){
				SDL_SetError("Couldn't blit surface to temp surface");
				SDL_FreeSurface(tempsurf);
				goto savedone;
			}
			if (used_alpha) {
				SDL_SetAlpha(surf,SDL_SRCALPHA,(Uint8)temp_alpha); /* Restore alpha settings*/
			}
			for(i=0;i<tempsurf->h;i++){
				row_pointers[i]= ((png_byte*)tempsurf->pixels) + i*tempsurf->pitch;
			}
			if(SDL_MUSTLOCK(tempsurf)){
				SDL_LockSurface(tempsurf);
			}
			png_write_image(png_ptr, row_pointers);
			if(SDL_MUSTLOCK(tempsurf)){
				SDL_UnlockSurface(tempsurf);
			}
			SDL_FreeSurface(tempsurf);
		} else {
			for(i=0;i<surf->h;i++){
				row_pointers[i]= ((png_byte*)surf->pixels) + i*surf->pitch;
			}
			if(SDL_MUSTLOCK(surf)){
				SDL_LockSurface(surf);
			}
			png_write_image(png_ptr, row_pointers);
			if(SDL_MUSTLOCK(surf)){
				SDL_UnlockSurface(surf);
			}
		}
	}

	png_write_end(png_ptr, NULL);
	ret=0; /* got here, so nothing went wrong. YAY! */

savedone: /* clean up and return */
	png_destroy_write_struct(&png_ptr,&info_ptr);
	if (palette) {
		free(palette);
	}
	if (palette_alpha) {
		free(palette_alpha);
	}
	if (row_pointers) {
		free(row_pointers);
	}
	return ret;
}
Esempio n. 14
0
int main()
{
    const int FPS = 60;
    const int FRAME_TIME = 1000/FPS; //Temps entre chaque frame en ms
    
    long time = 0, lastTime = 0;
    
    SDL_Surface *ecran = NULL, *ballonTex[12];
    SDL_Rect posBallon[12];
    SDL_Event event;

    SDL_Init(SDL_INIT_VIDEO);

    ecran = SDL_SetVideoMode(800, 600, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
    SDL_WM_SetCaption("Robocup Python POC", NULL);

    ballonTex[0] = IMG_Load("images/football.png");
    ballonTex[1] = IMG_Load("images/football_red.png");
    if(ballonTex != NULL){
	    
	    StrategieEngine strategie; //Initialiseur de l'engin de stratégie

	    int exit = 0;
	    while (!exit){

		time = SDL_GetTicks(); //Temps depuis l'execution du programme

		GameState gameState;

		gameState.time = time;

		strategie.setGameState(gameState); //Envoi de l'état du jeu

		if(time - lastTime > FRAME_TIME){ //Voir s'il est temps de dessiner le prochain frame
			struct StrategyState pyGame = strategie.getState(); //Reception de l'état du moteur de stratégie

			//Affichage
			SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 0, 0, 0));	
			
			for(int b = 0; b<2; b++){
				setPosition(ballonTex[b], &posBallon[b], pyGame.players[b].x * ecran->w/2 + ecran->w/2, pyGame.players[b].y * ecran->h/2 + ecran->h/2);
			
				SDL_BlitSurface(ballonTex[b], NULL, ecran, &posBallon[b]);

			}

			SDL_Flip(ecran);

			lastTime = time;
		}
		else{
			SDL_Delay(FRAME_TIME - (time - lastTime)); //Attendre jusqu'au prochain frame
		}

		//Gestion d'events (Dans ce cas fermeture de fenêtre)
		SDL_PollEvent(&event); 
		switch(event.type)
		{
		    case SDL_QUIT:
			exit = 1;
			break;
		}

	    }
    }
    else{
	printf("Cannot find \"football.png\". Exiting...\n");
    }
    for(int s = 0; s < 2; s++){
	SDL_FreeSurface(ballonTex[s]);
    }
    
    SDL_Quit();

    return EXIT_SUCCESS;
}
Esempio n. 15
0
void Sprite::draw(SDL_Surface * screen){
  SDL_BlitSurface(*img, NULL, screen, *edge);
}
Esempio n. 16
0
int main(int argc, char *argv[]) 
{
	SDL_Surface *surface;
	SDL_Event event;
	SDL_Rect squares[9] = {{0, 0, 130, 130}, {140, 0, 130, 130}, {280, 0, 130, 130},
				{0, 140, 130, 130}, {140, 140, 130, 130}, {280, 140, 130, 130},
				{0, 280, 130, 130}, {140, 280, 130, 130}, {280, 280, 130, 130}};
	SDL_Rect imagepos = {0, 0, 0, 0};
	SDL_Surface *imagex;
	SDL_Surface *imageo;
	short int states[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
	int valid = 0;
	int i;
	int ret;
	int mx, my;

	bool done = false;

	SDL_Init(SDL_INIT_VIDEO);

	imagex = SDL_LoadBMP("x.bmp");
	imageo = SDL_LoadBMP("o.bmp");
	if (imagex == NULL || imageo == NULL) {
		fprintf(stderr, "Could not load image: %s\n", SDL_GetError());
		return -1;
	}

	/* Control window position */
	putenv(strdup("SDL_VIDEO_CENTERED=1"));
 
	surface = SDL_SetVideoMode(410, 410, 16, SDL_SWSURFACE);
	if (!surface) {
		fprintf(stderr, "Video mode set failed: %s\n", SDL_GetError());
		return -1;
	}

	SDL_WM_SetCaption("TICTACTOE", "Can't Beat Me");

	/* Fill screen and then put white squares on top */
	SDL_FillRect(surface, &surface->clip_rect, SDL_MapRGB(surface->format, 0x0, 0x0, 0x0));
	for (i = 0; i < 9; i++)
		SDL_FillRect(surface, &squares[i], 0xFFFFFF);

	/* Update screen buffer */
	SDL_Flip(surface);
	SDL_Surface *image = NULL;
	while(!done) {
		while(SDL_PollEvent(&event)) {
			switch (event.type) {
				case SDL_QUIT:
					done = true;
					break;
				case SDL_MOUSEBUTTONDOWN:
					valid = handle_button(&mx, &my, &imagepos, states);
					if (valid == 0)
						player = !player;
					break;
			}
		}
		if (imagepos.x != 0 && valid == 0) {
			image = player ? imageo : imagex;
			if (SDL_BlitSurface(image, NULL, surface, &imagepos) != 0) {
				fprintf(stderr, "Failed to blit image: %s\n", SDL_GetError());
				return -1;
			}
			SDL_Flip(surface);
		}
		ret = check_win(states);
		if (ret == 1) {
			printf("Player 1 won\n");
			done = true;
		} else if (ret == 2) {
			printf("Player 2 won\n");
			done = true;
		} else if (ret == 0){
			printf("Draw!\n");
			done = true;
		} else {
			continue;
		}
	}

	SDL_Quit();

	return 0;
}
Esempio n. 17
0
void blit_label_t(label_t* label, SDL_Surface* dest) {
	SDL_BlitSurface(label->surf, NULL, dest, &label->rect);
}
Esempio n. 18
0
int main ( int argc , char** argv ) {

	SDL_Init( SDL_INIT_EVERYTHING ) ;

	SDL_Surface *screen = NULL ;
	SDL_Surface *ball = NULL ;
	SDL_Surface *enemy = NULL ;
	SDL_Event event ;
	SDL_Rect enemy_rect , ball_rect ;

	ball_rect.x = 320 ;
	ball_rect.y = 160 ;

	enemy_rect.x = 0 ;
	enemy_rect.y = 160 ;

	screen = SDL_SetVideoMode( 640 , 320 , 32 , SDL_SWSURFACE ) ;
	SDL_WM_SetCaption("Avoid the rocket!" , NULL ) ;
	ball = SDL_LoadBMP( "dot.bmp" ) ;
	enemy = SDL_LoadBMP( "rocket.bmp" ) ;

	SDL_BlitSurface( ball , NULL , screen , &ball_rect ) ;
	SDL_BlitSurface( enemy , NULL , screen , &enemy_rect ) ;
	SDL_Flip( screen ) ;
	SDL_LockSurface( screen ) ;

	for ( ;; ) {

		SDL_PollEvent( &event ) ;

		if ( event.type == SDL_QUIT ) break ;

		if ( event.type = SDL_KEYDOWN ) {

			switch( event.key.keysym.sym ) {

				case SDLK_UP : ball_rect.y-- ; break ;
				case SDLK_DOWN : ball_rect.y++ ; break ;
				case SDLK_RIGHT : ball_rect.x++ ; break ;
				case SDLK_LEFT : ball_rect.x-- ; break ;

			}

		}

		if ( ball_rect.x >= 640 ) ball_rect.x = 0 ;
		if ( ball_rect.y >= 320 ) ball_rect.y = 0 ;

		enemy_rect.x++ ;

		if ( enemy_rect.x >= 640 ) enemy_rect.x = 0 ;

		if ( collision( enemy_rect , ball_rect ) ) break ;


		SDL_UnlockSurface( screen ) ;
		SDL_BlitSurface( ball , NULL , screen , &ball_rect ) ;
		SDL_BlitSurface( enemy , NULL , screen , &enemy_rect ) ;
		SDL_Flip( screen ) ;
		SDL_LockSurface( screen ) ;
	
	}

	SDL_FreeSurface( ball ) ;
	SDL_FreeSurface( enemy ) ;
	SDL_Quit() ;

	return 0 ;

}
Esempio n. 19
0
void ResourceObject::Init(int type, std::string resType, std::string resObject)
{

	/*dataTypes = new dataFile_Types[4];
	dataTypes[DATAFILE_SPRITE_PHYSDATA].fileValueCount = 7;
	dataTypes[DATAFILE_SPRITE_UNITDATA].fileValueCount = 10;
	dataTypes[DATAFILE_SPRITE_ANIMDATA].fileValueCount = 4;*/
	
	this->resInfo.type = resType;

	//this->
	
	// if we're loading a single image containing all animations
	if (type == RES_TYPE_TILEMAP) {
	
		sstr.str("");
		sstr<<"content\\"<<resType<<"\\"<<resObject<<"\\tileset.bmp";
		str1 = sstr.str();

		surface = load_image(str1,this->resInfo.alpha_r,this->resInfo.alpha_g,this->resInfo.alpha_b);

		this->resInfo.width = surface->w;
		this->resInfo.height = surface->h;
		this->resInfo.xTileSize = 32;
		this->resInfo.yTileSize = 32;

		long clips, framesMax, anglesMax;
		clips = 1;
		framesMax = 1;
		anglesMax = 1;

		animData = new animation_Data[clips];
		stateToAnim.resize(states::COUNT_ANIM_STATE);

		

		animData[0].clipArray = new frame_Array[framesMax];

			
		animData[0].clipArray[0].angles = new angle_Array[anglesMax];

		animData[0].clipArray[0].angles[0].clip.x = 0;
		animData[0].clipArray[0].angles[0].clip.y = 0;
		animData[0].clipArray[0].angles[0].clip.w = surface->w;
		animData[0].clipArray[0].angles[0].clip.h = surface->h;


		stateToAnim.at(0) = &animData[0];
		stateToAnim.at(1) = &animData[0];
		stateToAnim.at(2) = &animData[0];
		stateToAnim.at(10) = &animData[0];



	}
	//If we're loading a series of files to merge to one
	else if (type == RES_TYPE_FILEMAP) {
		sstr.str("");
		sstr<<"content\\"<<resType<<"\\"<<resObject<<"\\animdata.dat";
		str1 = sstr.str();

		std::ifstream animFile( str1.c_str() );

		if( animFile == NULL )
		{
			return;
		}

		long clips, framesMax, anglesMax;
		long resWidth = 0, resHeight = 0, totalFrameCount = 0;

		animFile >> clips;
		animFile >> framesMax;
		animFile >> anglesMax;

		animation_Data* animDataTemp = new animation_Data;

		animData = new animation_Data[clips];
		//animData = new animation_Data[clips+2];
		stateToAnim.resize(states::COUNT_ANIM_STATE);
		std::vector<animation_Data *>::iterator itaD = stateToAnim.begin();
		
		//itaD = stateToAnim.begin();
		//itaD+=0;
		animDataTemp->ID = -1;
		//stateToAnim.insert(itaD,animDataTemp);
		//stateToAnim.insert(itaD,animDataTemp);
		stateToAnim.at(0) = animDataTemp;
		stateToAnim.at(2) = animDataTemp;
		stateToAnim.at(10) = animDataTemp;

		itaD = stateToAnim.begin();
		

		//stateToAnim = new animation_Data[COUNT_ANIM_STATE];

		SDL_Rect biggestClip;

		animFile >> biggestClip.x;
		animFile >> biggestClip.y;
		animFile >> biggestClip.w;
		animFile >> biggestClip.h;
		int i;
		for (i = 0; i < clips; i++) {
			animFile >> animData[i].ID;
			animFile >> animData[i].frames;
			animFile >> animData[i].angles;
			animFile >> animData[i].execTime;
			animData[i].clipArray = new frame_Array[framesMax];

			for (int k = 0; k < framesMax; k++) {
				animData[i].clipArray[k].angles = new angle_Array[anglesMax];
				for (int l = 0; l < anglesMax; l++) {
					
					animData[i].clipArray[k].angles[l].clip.x = 0;
					animData[i].clipArray[k].angles[l].clip.y = 0;
					animData[i].clipArray[k].angles[l].clip.w = 0;
					animData[i].clipArray[k].angles[l].clip.h = 0;
				}
			}
			if (animData[i].angles == 0) {
				resWidth += (1 * biggestClip.w);
				totalFrameCount += animData[i].frames;
			} else {
				resWidth += (animData[i].frames * biggestClip.w);
				totalFrameCount += animData[i].frames * anglesMax;
			}

			//animData[i].Init(framesMax,anglesMax);

			//itaD = stateToAnim.begin();
			//itaD+=animData[i].ID;
			//stateToAnim.insert(itaD,&animData[i]);
			stateToAnim.at(animData[i].ID) = &animData[i];

			if (animData[i].ID == 1) {
				if (stateToAnim.at(0)->ID == -1) {
					stateToAnim.at(0) = &animData[i];
				}
				if (stateToAnim.at(2)->ID == -1) {
					stateToAnim.at(2) = &animData[i];
				}
				if (stateToAnim.at(10)->ID == -1) {
					stateToAnim.at(10) = &animData[i];
				}

			}

			//update render and animate code to use this lookup vector, also update ai states to anim code
			
		}

		if (stateToAnim.at(0)->ID < 0) {
			int asdasd = stateToAnim.at(0)->ID;
			int sdf = 0;
		}

		//SDL_Rect lol = animData[4].frameArray[0][0];
		//animData[4].frameArray[0][0] = lol;
		
		resHeight = anglesMax * biggestClip.h;

		if (animFile.fail()) {
			//ERROR
			animFile.close();
		}
		
		animFile.close();

		this->surface = SDL_CreateRGBSurface(SDL_HWSURFACE,resWidth,resHeight,32,0xff000000,0x00ff0000,0x0000ff00,0x000000ff);
		
		SDL_Surface* image = new SDL_Surface;
		SDL_Surface* mask = new SDL_Surface;
		SDL_Surface* temp = new SDL_Surface;
		SDL_Surface* temp2 = new SDL_Surface;

		SDL_Rect offset;
		SDL_Rect clip;

		//Flip vars
		int yOffset;
		int yOffsetFlipped = 16;
		bool bFlip;
		int maxWidth = 0;
		int maxHeight = 0;

		int clipNum = 0;
		int frameNum = 0;
		int angleNum = 0;

		int xTileStart = 0;

		SDL_Rect tPtr;
		
		
		//biggestClip.y = 99;						//REMOVE MEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE


		//animData[4].frameArray[0][0] = lol;
		for (i = 0; i < totalFrameCount; i++) {

			float yTemp = (fmod(i*1.0f,anglesMax*1.0f));

			bFlip = false;
			if (yTemp == 0) {
				yOffsetFlipped = 15;
				yOffset = 0;
			}
			if (fmod(yTemp,2) == 1) {
				if (yTemp != 1) {
					angleNum = yOffsetFlipped;
					
					yOffsetFlipped--;
					bFlip = true;
				}
			} else {
				angleNum = yOffset;
				
				yOffset++;
			}


			//this code determines where the next blit should be placed
			offset.y = angleNum*biggestClip.h;
			offset.x = ((int)(i/anglesMax))*biggestClip.w;
			offset.w = biggestClip.w;
			offset.h = biggestClip.h;
			
			std::string sZeroes;
			sstr.str("");

			
			if (totalFrameCount < 10) {
				
				/*if (i < 10) {
					sstr<<"00";
				} else if (i < 100) {*/
					sstr<<"";
				//}
			} else if (totalFrameCount < 100) {	
				if (i < 10) {
					sstr<<"0";
				} else if (i < 100) {
					sstr<<"";
				}
			} else {
				
				
				if (i < 10) {
					sstr<<"00";
				} else if (i < 100) {
					sstr<<"0";
				}
			}

			/*sstr.str("");
			sstr<<resType<<"\\"<<resObject<<"\\img\\";
			str1 = sstr.str();

			std::vector<std::string> results;
			this->lsdir(str1.c_str(),results);*/

			//changed for vulture
			

			sZeroes = sstr.str();
			//lol = animData[4].frameArray[0][0];
			//animData[4].frameArray[0][0] = animData[4].frameArray[0][1];
			sstr.str("");
			sstr<<"content\\"<<resType<<"\\"<<resObject<<"\\img\\"<<resObject<<" "<<sZeroes<<i<<".bmp";
			str1 = sstr.str();
			image = load_image(str1,this->resInfo.alpha_r,this->resInfo.alpha_g,this->resInfo.alpha_b);
			//this->LoadTextures();
			//animData[4].angles = 5;
			//lol = animData[4].frameArray[0][1];
			
			clip.x = 0;
			clip.y = 0;
			clip.w = image->w;
			clip.h = image->h;
			//animData[4].clipArray[0].angles[0].clip = &clip;


			//image = SDL_CreateRGBSurface(SDL_HWSURFACE,128,128,32,0xff000000,0x00ff0000,0x0000ff00,0x000000ff);
			//mask = SDL_CreateRGBSurface(SDL_HWSURFACE,128,128,32,0xff000000,0x00ff0000,0x0000ff00,0x000000ff);
			temp = SDL_CreateRGBSurface(SDL_HWSURFACE,clip.w,clip.h,32,0xff000000,0x00ff0000,0x0000ff00,0x000000ff);
			temp2 = SDL_CreateRGBSurface(SDL_HWSURFACE,clip.w,clip.h,32,0xff000000,0x00ff0000,0x0000ff00,0x000000ff);
			this->test = SDL_CreateRGBSurface(SDL_HWSURFACE,clip.w,clip.h,32,0xff000000,0x00ff0000,0x0000ff00,0x000000ff);
			//temp = SDL_DisplayFormat(temp);
	
			if (bFlip) {
				SDL_BlitSurface(image,&image->clip_rect,temp,&temp->clip_rect);
				SDL_FillRect( image, &image->clip_rect, SDL_MapRGB( image->format,this->resInfo.alpha_r,this->resInfo.alpha_g,this->resInfo.alpha_b ) );
				SDL_SetColorKey( image, SDL_SRCCOLORKEY, SDL_MapRGB( image->format,this->resInfo.alpha_r,this->resInfo.alpha_g,this->resInfo.alpha_b ) );
				xFlip(temp,image);
			}

			sstr.str("");
			sstr<<"content\\"<<resType<<"\\"<<resObject<<"\\img\\"<<resObject<<"_mask "<<sZeroes<<i<<".bmp";
			str1 = sstr.str();
			mask = load_image(str1,this->resInfo.alpha_r,this->resInfo.alpha_g,this->resInfo.alpha_b);

			//new
			
			SDL_FillRect( temp2, &temp2->clip_rect, SDL_MapRGB( temp2->format,this->resInfo.alpha_r,this->resInfo.alpha_g,this->resInfo.alpha_b ) );

			SDL_BlitSurface(mask,&mask->clip_rect,temp2,&temp2->clip_rect);

			SDL_FillRect( mask, &mask->clip_rect, SDL_MapRGB( mask->format, 255, 255, 255 ) );
			//SDL_SetColorKey( temp2, SDL_SRCCOLORKEY, SDL_MapRGB( temp2->format, 255, 255, 255 ) );

			//SDL_FillRect( test, &test->clip_rect, SDL_MapRGB( test->format, 255, 255, 255 ) );
			SDL_SetColorKey( mask, SDL_SRCCOLORKEY, SDL_MapRGB( mask->format, 255, 255, 255 ) );
			
			this->invert_mask(temp2,mask);
			SDL_BlitSurface(mask,&mask->clip_rect,test,&test->clip_rect);

			if (bFlip) {
				SDL_BlitSurface(mask,&mask->clip_rect,temp,&temp->clip_rect);
				SDL_FillRect( mask, &mask->clip_rect, SDL_MapRGB( mask->format, 255, 255, 255 ) );
				SDL_SetColorKey( mask, SDL_SRCCOLORKEY, SDL_MapRGB( mask->format, 255, 255, 255 ) );
				xFlip(temp,mask);
			}

			

			//all this converts the black background to rgb 0 255 255 so its the new transparent color
			//without messing up the fact that black is used in these images normally
			SDL_FillRect( temp, &temp->clip_rect, SDL_MapRGB( temp->format, 0, 255, 255 ) );
			SDL_BlitSurface(mask,&mask->clip_rect,temp,&temp->clip_rect);
			SDL_BlitSurface(image,&image->clip_rect,temp,&temp->clip_rect);

			

			int xTile = ((int)(i/anglesMax));
			int yTile = (fmod(i*1.0f,anglesMax*1.0f));
			
			//int frameNum = 0;
			//angleNum = yTile; // im setup above
			frameNum = xTile-xTileStart;

			//FIX THIS CODE, iterates through clips, i added clipnum++, right?
			//for (int j = 0; j < clips; j++) {
				if (frameNum >= animData[clipNum].frames) {
					frameNum = 0;
					xTileStart = xTile;
					clipNum++;
					int lol = 0;
					//tPtr = animData[clipNum].clipArray[frameNum].angles[angleNum].clip;
				} else {
					//clipNum = j;
					
				}
			//}


			tPtr = this->getVisualSize(temp,0,255,255);

			/*offset.x += biggestClip.x;
			offset.y += biggestClip.y;
			offset.w = biggestClip.w;
			offset.h = biggestClip.h;*/

			SDL_Rect bufferClip = offset;

			bufferClip.x += ((biggestClip.w - tPtr.w)/2);//((tPtr.x - biggestClip.x));// + ((biggestClip.w - tPtr.w)/2);//-((tPtr.w)/2);
			bufferClip.y += ((biggestClip.h - tPtr.h)/2);//((tPtr.y - biggestClip.y));// + ((biggestClip.h - tPtr.h)/2);//-((tPtr.h)/2);  (tPtr.y - biggestClip.y);//-((tPtr.h)/2);
			bufferClip.w = tPtr.w;
			bufferClip.h = tPtr.h;



			//REMOVE ME!
			//SDL_FillRect(surface,&offset,SDL_MapRGB(surface->format,0,(rand() % 255),0));

			if (resObject == "vulture") {
				int asas = 0;
			}
			animData[clipNum].clipArray[frameNum].angles[angleNum].clip = bufferClip; // i think this is crashing cause it goes over clip max, also last frame isnt accounted for right, ling death
			animData[clipNum].clipArray[frameNum].angles[angleNum].xOffset = tPtr.x-biggestClip.x;
			animData[clipNum].clipArray[frameNum].angles[angleNum].yOffset = tPtr.y-biggestClip.y;

			SDL_BlitSurface( temp, &tPtr, surface, &bufferClip );

			//keep this code to get the biggest clip size of other graphics for the data files
			if (tPtr.x < biggestClip.x) {
				biggestClip.x = tPtr.x;
			}
			if (tPtr.w > biggestClip.w) {
				biggestClip.w = tPtr.w;
			}
			if (tPtr.y < biggestClip.y) {
				biggestClip.y = tPtr.y;
			}
			if (tPtr.h > biggestClip.h) {
				biggestClip.h = tPtr.h;
			}
			

		}

		this->resInfo.width = surface->w;
		this->resInfo.height = surface->h;
		this->resInfo.xTileSize = biggestClip.w;
		this->resInfo.yTileSize = biggestClip.h;


		SDL_SetColorKey( surface, SDL_SRCCOLORKEY | SDL_HWSURFACE, SDL_MapRGB( surface->format, 0, 255, 255 ) );
		surface = SDL_DisplayFormat( surface );

		test = SDL_DisplayFormat( test );
		
		
        //Free the old image
        //SDL_FreeSurface( loadedImage );

		


	}
bool ONScripterLabel::doEffect( EffectLink *effect, bool clear_dirty_region )
{
    bool first_time = (effect_counter == 0);

    effect_start_time = SDL_GetTicks();

    effect_timer_resolution = effect_start_time - effect_start_time_old;
    effect_start_time_old = effect_start_time;

    int effect_no = effect->effect;
    if (first_time) {
        if ( (effect_cut_flag &&
              ( ctrl_pressed_status || skip_mode & SKIP_NORMAL )) ||
             (effectspeed == EFFECTSPEED_INSTANT) )
            effect_no = 1;
    }

    skip_effect = false;

    int i, amp;
    int width, width2;
    int height, height2;
    SDL_Rect src_rect={0, 0, screen_width, screen_height};
    SDL_Rect dst_rect={0, 0, screen_width, screen_height};
    SDL_Rect quake_rect={0, 0, screen_width, screen_height};

    /* ---------------------------------------- */
    /* Execute effect */
    if (debug_level > 0 && first_time)
        printf("Effect number %d, %d ms\n", effect_no, effect_duration );

    bool not_implemented = false;
    switch ( effect_no ){
      case 0: // Instant display
      case 1: // Instant display
        //drawEffect( &src_rect, &src_rect, effect_dst_surface );
        break;

      case 2: // Left shutter
        width = EFFECT_STRIPE_WIDTH * effect_counter / effect_duration;
        for ( i=0 ; i<screen_width/EFFECT_STRIPE_WIDTH ; i++ ){
            src_rect.x = i * EFFECT_STRIPE_WIDTH;
            src_rect.y = 0;
            src_rect.w = width;
            src_rect.h = screen_height;
            drawEffect(&src_rect, &src_rect, effect_dst_surface);
        }
        break;

      case 3: // Right shutter
        width = EFFECT_STRIPE_WIDTH * effect_counter / effect_duration;
        for ( i=1 ; i<=screen_width/EFFECT_STRIPE_WIDTH ; i++ ){
            src_rect.x = i * EFFECT_STRIPE_WIDTH - width - 1;
            src_rect.y = 0;
            src_rect.w = width;
            src_rect.h = screen_height;
            drawEffect(&src_rect, &src_rect, effect_dst_surface);
        }
        break;

      case 4: // Top shutter
        height = EFFECT_STRIPE_WIDTH * effect_counter / effect_duration;
        for ( i=0 ; i<screen_height/EFFECT_STRIPE_WIDTH ; i++ ){
            src_rect.x = 0;
            src_rect.y = i * EFFECT_STRIPE_WIDTH;
            src_rect.w = screen_width;
            src_rect.h = height;
            drawEffect(&src_rect, &src_rect, effect_dst_surface);
        }
        break;

      case 5: // Bottom shutter
        height = EFFECT_STRIPE_WIDTH * effect_counter / effect_duration;
        for ( i=1 ; i<=screen_height/EFFECT_STRIPE_WIDTH ; i++ ){
            src_rect.x = 0;
            src_rect.y = i * EFFECT_STRIPE_WIDTH - height - 1;
            src_rect.w = screen_width;
            src_rect.h = height;
            drawEffect(&src_rect, &src_rect, effect_dst_surface);
        }
        break;

      case 6: // Left curtain
        width = EFFECT_STRIPE_CURTAIN_WIDTH * effect_counter * 2 / effect_duration;
        for ( i=0 ; i<=screen_width/EFFECT_STRIPE_CURTAIN_WIDTH ; i++ ){
            width2 = width - EFFECT_STRIPE_CURTAIN_WIDTH * EFFECT_STRIPE_CURTAIN_WIDTH * i / screen_width;
            if ( width2 >= 0 ){
                src_rect.x = i * EFFECT_STRIPE_CURTAIN_WIDTH;
                src_rect.y = 0;
                src_rect.w = width2;
                src_rect.h = screen_height;
                drawEffect(&src_rect, &src_rect, effect_dst_surface);
            }
        }
        break;

      case 7: // Right curtain
        width = EFFECT_STRIPE_CURTAIN_WIDTH * effect_counter * 2 / effect_duration;
        for ( i=0 ; i<=screen_width/EFFECT_STRIPE_CURTAIN_WIDTH ; i++ ){
            width2 = width - EFFECT_STRIPE_CURTAIN_WIDTH * EFFECT_STRIPE_CURTAIN_WIDTH * i / screen_width;
            if ( width2 >= 0 ){
                if ( width2 > EFFECT_STRIPE_CURTAIN_WIDTH ) width2 = EFFECT_STRIPE_CURTAIN_WIDTH;
                src_rect.x = screen_width - i * EFFECT_STRIPE_CURTAIN_WIDTH - width2;
                src_rect.y = 0;
                src_rect.w = width2;
                src_rect.h = screen_height;
                drawEffect(&src_rect, &src_rect, effect_dst_surface);
            }
        }
        break;

      case 8: // Top curtain
        height = EFFECT_STRIPE_CURTAIN_WIDTH * effect_counter * 2 / effect_duration;
        for ( i=0 ; i<=screen_height/EFFECT_STRIPE_CURTAIN_WIDTH ; i++ ){
            height2 = height - EFFECT_STRIPE_CURTAIN_WIDTH * EFFECT_STRIPE_CURTAIN_WIDTH * i / screen_height;
            if ( height2 >= 0 ){
                src_rect.x = 0;
                src_rect.y = i * EFFECT_STRIPE_CURTAIN_WIDTH;
                src_rect.w = screen_width;
                src_rect.h = height2;
                drawEffect(&src_rect, &src_rect, effect_dst_surface);
            }
        }
        break;

      case 9: // Bottom curtain
        height = EFFECT_STRIPE_CURTAIN_WIDTH * effect_counter * 2 / effect_duration;
        for ( i=0 ; i<=screen_height/EFFECT_STRIPE_CURTAIN_WIDTH ; i++ ){
            height2 = height - EFFECT_STRIPE_CURTAIN_WIDTH * EFFECT_STRIPE_CURTAIN_WIDTH * i / screen_height;
            if ( height2 >= 0 ){
                src_rect.x = 0;
                src_rect.y = screen_height - i * EFFECT_STRIPE_CURTAIN_WIDTH - height2;
                src_rect.w = screen_width;
                src_rect.h = height2;
                drawEffect(&src_rect, &src_rect, effect_dst_surface);
            }
        }
        break;

      default:
        not_implemented = true;
        if (first_time) {
            snprintf(script_h.errbuf, MAX_ERRBUF_LEN,
                     "effect No. %d not implemented; substituting crossfade",
                     effect_no);
            errorAndCont(script_h.errbuf);
        }

      case 10: // Cross fade
        height = 256 * effect_counter / effect_duration;
        effectBlend( NULL, ALPHA_BLEND_CONST, height, &dirty_rect.bounding_box );
        break;

      case 11: // Left scroll
        width = screen_width * effect_counter / effect_duration;
        src_rect.x = 0;
        dst_rect.x = width;
        src_rect.y = dst_rect.y = 0;
        src_rect.w = dst_rect.w = screen_width - width;
        src_rect.h = dst_rect.h = screen_height;
        drawEffect(&dst_rect, &src_rect, effect_src_surface);

        src_rect.x = screen_width - width - 1;
        dst_rect.x = 0;
        src_rect.y = dst_rect.y = 0;
        src_rect.w = dst_rect.w = width;
        src_rect.h = dst_rect.h = screen_height;
        drawEffect(&dst_rect, &src_rect, effect_dst_surface);
        break;

      case 12: // Right scroll
        width = screen_width * effect_counter / effect_duration;
        src_rect.x = width;
        dst_rect.x = 0;
        src_rect.y = dst_rect.y = 0;
        src_rect.w = dst_rect.w = screen_width - width;
        src_rect.h = dst_rect.h = screen_height;
        drawEffect(&dst_rect, &src_rect, effect_src_surface);

        src_rect.x = 0;
        dst_rect.x = screen_width - width - 1;
        src_rect.y = dst_rect.y = 0;
        src_rect.w = dst_rect.w = width;
        src_rect.h = dst_rect.h = screen_height;
        drawEffect(&dst_rect, &src_rect, effect_dst_surface);
        break;

      case 13: // Top scroll
        width = screen_height * effect_counter / effect_duration;
        src_rect.x = dst_rect.x = 0;
        src_rect.y = 0;
        dst_rect.y = width;
        src_rect.w = dst_rect.w = screen_width;
        src_rect.h = dst_rect.h = screen_height - width;
        drawEffect(&dst_rect, &src_rect, effect_src_surface);

        src_rect.x = dst_rect.x = 0;
        src_rect.y = screen_height - width - 1;
        dst_rect.y = 0;
        src_rect.w = dst_rect.w = screen_width;
        src_rect.h = dst_rect.h = width;
        drawEffect(&dst_rect, &src_rect, effect_dst_surface);
        break;

      case 14: // Bottom scroll
        width = screen_height * effect_counter / effect_duration;
        src_rect.x = dst_rect.x = 0;
        src_rect.y = width;
        dst_rect.y = 0;
        src_rect.w = dst_rect.w = screen_width;
        src_rect.h = dst_rect.h = screen_height - width;
        drawEffect(&dst_rect, &src_rect, effect_src_surface);

        src_rect.x = dst_rect.x = 0;
        src_rect.y = 0;
        dst_rect.y = screen_height - width - 1;
        src_rect.w = dst_rect.w = screen_width;
        src_rect.h = dst_rect.h = width;
        drawEffect(&dst_rect, &src_rect, effect_dst_surface);
        break;

      case 15: // Fade with mask
        effectBlend( effect->anim.image_surface, ALPHA_BLEND_FADE_MASK, 256 * effect_counter / effect_duration, &dirty_rect.bounding_box );
        break;

      case 16: // Mosaic out
        generateMosaic( effect_src_surface, 5 - 6 * effect_counter / effect_duration );
        break;

      case 17: // Mosaic in
        generateMosaic( effect_dst_surface, 6 * effect_counter / effect_duration );
        break;

      case 18: // Cross fade with mask
        effectBlend( effect->anim.image_surface, ALPHA_BLEND_CROSSFADE_MASK, 256 * effect_counter * 2 / effect_duration, &dirty_rect.bounding_box );
        break;

      case (MAX_EFFECT_NUM + 0): // quakey
        if ( effect_timer_resolution > effect_duration / 4 / effect->no )
            effect_timer_resolution = effect_duration / 4 / effect->no;
        amp = (Sint16)(sin(M_PI * 2.0 * effect->no * effect_counter / effect_duration) *
                       EFFECT_QUAKE_AMP * effect->no * (effect_duration -  effect_counter) / effect_duration);
        dst_rect.x = 0;
        dst_rect.y = amp;
        drawEffect(&dst_rect, &src_rect, effect_dst_surface);

        if (amp >= 0){
            quake_rect.y = 0;
            quake_rect.h = amp;
        }
        else{
            quake_rect.y = screen_height + amp;
            quake_rect.h = -amp;
        }
        SDL_FillRect( accumulation_surface, &quake_rect, SDL_MapRGBA( accumulation_surface->format, 0, 0, 0, 0xff ) );
        break;

      case (MAX_EFFECT_NUM + 1): // quakex
        if ( effect_timer_resolution > effect_duration / 4 / effect->no )
            effect_timer_resolution = effect_duration / 4 / effect->no;
        amp = (Sint16)(sin(M_PI * 2.0 * effect->no * effect_counter / effect_duration) *
                       EFFECT_QUAKE_AMP * effect->no * (effect_duration -  effect_counter) / effect_duration);
        dst_rect.x = amp;
        dst_rect.y = 0;
        drawEffect(&dst_rect, &src_rect, effect_dst_surface);

        if (amp >= 0){
            quake_rect.x = 0;
            quake_rect.w = amp;
        }
        else{
            quake_rect.x = screen_width + amp;
            quake_rect.w = -amp;
        }
        SDL_FillRect( accumulation_surface, &quake_rect, SDL_MapRGBA( accumulation_surface->format, 0, 0, 0, 0xff ) );
        break;

      case (MAX_EFFECT_NUM + 2 ): // quake
        dst_rect.x = effect->no*((int)(3.0*rand()/(RAND_MAX+1.0)) - 1) * 2;
        dst_rect.y = effect->no*((int)(3.0*rand()/(RAND_MAX+1.0)) - 1) * 2;
        SDL_FillRect( accumulation_surface, NULL, SDL_MapRGBA( accumulation_surface->format, 0, 0, 0, 0xff ) );
        drawEffect(&dst_rect, &src_rect, effect_dst_surface);
        break;

      case (MAX_EFFECT_NUM + 3 ): // flushout
        if (effect_counter > 0){
            width = 30 * effect_counter / effect_duration;
            height = 30 * (effect_counter + effect_timer_resolution) / effect_duration;
            if (height > width){
                doFlushout(height);
                effectBlend( NULL, ALPHA_BLEND_CONST, effect_counter * 256 / effect_duration, &dirty_rect.bounding_box, effect_tmp_surface );
            }
        }
        break;

      case 99: // dll-based
        if (dll != NULL) {
            if (!strncmp(dll, "cascade.dll", 11)) {
                effectCascade(params, effect_duration);
            } else if (!strncmp(dll, "whirl.dll", 9)) {
                effectWhirl(params, effect_duration);
            } else if (!strncmp(dll, "trvswave.dll", 12)) {
                effectTrvswave(params, effect_duration);
            } else if (!strncmp(dll, "breakup.dll", 11)) {
                effectBreakup(params, effect_duration);
            } else {
                not_implemented = true;
                if (first_time) {
                    snprintf(script_h.errbuf, MAX_ERRBUF_LEN,
                             "dll effect '%s' (%d) not implemented; substituting crossfade",
                             dll, effect_no);
                    errorAndCont(script_h.errbuf);
                }
            }
        } else { //just in case no dll is given
            not_implemented = true;
            if (first_time) {
                snprintf(script_h.errbuf, MAX_ERRBUF_LEN,
                         "no dll provided for effect %d; substituting crossfade",
                         effect_no);
                errorAndCont(script_h.errbuf);
            }
        }
        if (not_implemented) {
            // do crossfade
            height = 256 * effect_counter / effect_duration;
            effectBlend( NULL, ALPHA_BLEND_CONST, height, &dirty_rect.bounding_box );
        }
        break;
    }

    if (debug_level > 1)
        printf("\teffect count %d / dur %d\n", effect_counter, effect_duration);

    effect_counter += effect_timer_resolution;

    //check for events before drawing
    event_mode = IDLE_EVENT_MODE;
    event_mode |= WAIT_NO_ANIM_MODE;
    if (effectskip_flag) {
        event_mode |= WAIT_INPUT_MODE;
    }
    waitEvent(0);
    event_mode &= ~(WAIT_NO_ANIM_MODE | WAIT_INPUT_MODE);

    if ( effect_counter < effect_duration && effect_no != 1 ){
        if ( effect_no != 0 ) flush( REFRESH_NONE_MODE, NULL, false );

        if (effectskip_flag && skip_effect)
            effect_counter = effect_duration;

        return true;
    }
    else {
        //last call
        SDL_BlitSurface(effect_dst_surface, &dirty_rect.bounding_box,
                        accumulation_surface, &dirty_rect.bounding_box);

        if (effect_no != 0)
            flush(REFRESH_NONE_MODE, NULL, clear_dirty_region);
        if (effect_no == 1)
            effect_counter = 0;
        else if ((effect_no == 99) && (dll != NULL)){
            dll = params = NULL;
        }

        display_mode &= ~DISPLAY_MODE_UPDATED;

        if (effect_blank != 0 && effect_counter != 0) {
            event_mode = WAIT_TIMER_MODE;
            if ( ctrl_pressed_status || (skip_mode & SKIP_TO_WAIT) )
                waitEvent(1); //allow a moment to detect ctrl unpress, if any
            else
                waitEvent(effect_blank);
        }
        event_mode = IDLE_EVENT_MODE;

        return false;
    }
}
Esempio n. 21
0
void screen_editor(SDL_Surface* screen, int theplacecursor) { //sticks the frame of the editor
    int i;

    SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 255, 255, 255));
    SDL_Surface *spritestone = NULL;
    SDL_Rect place;
    SDL_Rect placecursor;
    SDL_Surface *spritetree = NULL;
    SDL_Surface *spritekey = NULL;
    SDL_Surface *spritecase = NULL;
    SDL_Surface *spritedoor = NULL;
    SDL_Surface *spriteplayer = NULL;
    SDL_Surface *spritemonster = NULL;
    SDL_Surface * spriteeraser = NULL;
    SDL_Surface *line = NULL;
    SDL_Surface *cursor = NULL;
    cursor = IMG_Load(IMG_CURSOR);
    line = IMG_Load(IMG_BANNER_LINE);
    spritestone = IMG_Load(IMG_MAP_STONE);
    spritetree = IMG_Load(IMG_MAP_TREE);
    spritekey = IMG_Load(IMG_MAP_KEY);
    spritecase = IMG_Load(IMG_MAP_CASE);
    spritedoor = IMG_Load(IMG_MAP_CLOSED_DOOR);
    spritemonster = IMG_Load(IMG_MONSTER_DOWN);
    spriteplayer = IMG_Load(IMG_PLAYER_DOWN);
    spriteeraser = IMG_Load(IMG_ERASER);
    place.y = 12 * SIZE_BLOC;
    for (i = 0; i < 12; i++) {
        place.x = i * SIZE_BLOC;
        SDL_BlitSurface(line, NULL, screen, &place);
    }

    place.y = (12 * SIZE_BLOC) + SIZE_LINE;

    int white_bloc = ((12 * SIZE_BLOC) - 6 * SIZE_BLOC) / 4;

    place.x = 0;
    SDL_BlitSurface(spritestone, NULL, screen, &place);
    placecursor.x = theplacecursor;
    placecursor.y = 12 * SIZE_BLOC -25 ;
    SDL_BlitSurface(cursor, NULL, screen, &placecursor);
    // TODO : link lifes in banner and lifes of player
    place.x = 0.25 * white_bloc + 1 * SIZE_BLOC;
    SDL_BlitSurface(spritetree, NULL, screen, &place);

    place.x = 0.5 * white_bloc + 2 * SIZE_BLOC;
    SDL_BlitSurface(spritekey, NULL, screen, &place);

    place.x = 0.75 * white_bloc + 3 * SIZE_BLOC;
    SDL_BlitSurface(spritecase, NULL, screen, &place);

    place.x = 1 * white_bloc + 4 * SIZE_BLOC;
    SDL_BlitSurface(spritedoor, NULL, screen, &place);
    place.x = 1.25 * white_bloc + 5 * SIZE_BLOC;
    SDL_BlitSurface(spritemonster, NULL, screen, &place);
    place.x = 1.5 * white_bloc + 6 * SIZE_BLOC;
    SDL_BlitSurface(spriteplayer, NULL, screen, &place);
    place.x = 1.75 * white_bloc + 7 * SIZE_BLOC;
    SDL_BlitSurface(spriteeraser, NULL, screen, &place);
    SDL_Flip(screen);

}
bool ONScripterLabel::setEffect( EffectLink *effect, bool generate_effect_dst, bool update_backup_surface )
{
    if ( effect->effect == 0 ) return true;

    if (update_backup_surface)
        refreshSurface(backup_surface, &dirty_rect.bounding_box, REFRESH_NORMAL_MODE);
    
    int effect_no = effect->effect;

    SDL_BlitSurface( accumulation_surface, NULL, effect_src_surface, NULL );

    if (generate_effect_dst){
        int refresh_mode = refreshMode();
        if (update_backup_surface && refresh_mode == REFRESH_NORMAL_MODE){
            SDL_BlitSurface( backup_surface, &dirty_rect.bounding_box, effect_dst_surface, &dirty_rect.bounding_box );
        }
        else{
            if (effect_no == 1)
                refreshSurface( effect_dst_surface, &dirty_rect.bounding_box, refresh_mode );
            else
                refreshSurface( effect_dst_surface, NULL, refresh_mode );
        }
    }
    
    effect_counter = 0;
    effect_start_time_old = SDL_GetTicks();
    effect_duration = effect->duration;
    if (ctrl_pressed_status || skip_mode & SKIP_NORMAL) {
        // shorten the duration of effects while skipping
        if ( effect_cut_flag ) {
            effect_duration = 0;
            return false; //don't parse effects if effectcut skip
        } else if (effect_duration > 100) {
            effect_duration = effect_duration / 10;
        } else if (effect_duration > 10) {
            effect_duration = 10;
        } else {
            effect_duration = 1;
        }
    } else if (effectspeed == EFFECTSPEED_INSTANT) {
        effect_duration = 0;
        return false; //don't parse effects if instant speed
    } else if (effectspeed == EFFECTSPEED_QUICKER) {
        effect_duration = effect_duration / 2;
        if (effect_duration <= 0)
            effect_duration = 1;
    }

    /* Load mask image */
    if ( effect_no == 15 || effect_no == 18 ){
        if ( !effect->anim.image_surface ){
            parseTaggedString( &effect->anim, true );
#ifdef RCA_SCALE
            setupAnimationInfo( &effect->anim, NULL, scr_stretch_x, scr_stretch_y );
#else
            setupAnimationInfo( &effect->anim );
#endif
        }
    }
    if ( effect_no == 11 || effect_no == 12 || effect_no == 13 || effect_no == 14 ||
         effect_no == 16 || effect_no == 17 )
        dirty_rect.fill( screen_width, screen_height );

    dll = params = NULL;
    if (effect_no == 99) { // dll-based
        dll = effect->anim.image_name;
        if (dll != NULL) { //just in case no dll is given
            if (debug_level > 0)
                printf("dll effect: Got dll/params '%s'\n", dll);

            params = dll;
            while (*params != 0 && *params != '/') params++;
            if (*params == '/') params++;

            if (!strncmp(dll, "whirl.dll", 9)) {
                buildSinTable();
                buildCosTable();
                buildWhirlTable();
                dirty_rect.fill( screen_width, screen_height );
            }
            else if (!strncmp(dll, "trvswave.dll", 12)) {
                buildSinTable();
                dirty_rect.fill( screen_width, screen_height );
            }
            else if (!strncmp(dll, "breakup.dll", 11)) {
                initBreakup(params);
                dirty_rect.fill( screen_width, screen_height );
            }
            else {
                dirty_rect.fill( screen_width, screen_height );
            }
        }
    }

    return false;
}
Esempio n. 23
0
void bliterEcran(SDL_Surface *ecran, Portion_Map chunk[][PROFONDEUR_MONDE], Camera camera, int largeurFenetre, int hauteurFenetre)
{
    int memX(0), memY(0);

    SDL_Surface *caseLumineuse(0);

    caseLumineuse = SDL_CreateRGBSurface(SDL_HWSURFACE, TAILLE_BLOCK, TAILLE_BLOCK, 32, 0, 0, 0, 0);
    SDL_FillRect(caseLumineuse, NULL, SDL_MapRGB(ecran->format, 0, 0, 0));

    for (int x(0); x < LARGEUR_MONDE; x++) // Affichage de la génération à l'écran
    {
        for (int y(0); y < PROFONDEUR_MONDE; y++)
        {
            for (int a(0); a < LARGEUR_PARTIE_MAP; a++)
            {
                for (int b(0); b < PROFONDEUR_PARTIE_MAP; b++)
                {
                    memX = chunk[x][y].blocs[a][b].positionBloc.x;
                    memY = chunk[x][y].blocs[a][b].positionBloc.y;
                    chunk[x][y].blocs[a][b].positionBloc.x -= camera.posCamX;
                    chunk[x][y].blocs[a][b].positionBloc.y -= camera.posCamY;

                    if ((memX > camera.posCamX - TAILLE_BLOCK) && (memX < (camera.posCamX + largeurFenetre) + TAILLE_BLOCK))
                    {
                        if ((memY > camera.posCamY - TAILLE_BLOCK) && (memY < (camera.posCamY + hauteurFenetre) + TAILLE_BLOCK))
                        {
                            if (chunk[x][y].blocs[a][b].luminosite != 0)
                            {
                                if (chunk[x][y].blocs[a][b].type == TERRE)
                                    SDL_BlitSurface(surfTerre, NULL, ecran, &chunk[x][y].blocs[a][b].positionBloc);

                                else if (chunk[x][y].blocs[a][b].type == HERBE)
                                    SDL_BlitSurface(surfHerbe, NULL, ecran, &chunk[x][y].blocs[a][b].positionBloc);

                                else if (chunk[x][y].blocs[a][b].type == PIERRE)
                                    SDL_BlitSurface(surfPierre, NULL, ecran, &chunk[x][y].blocs[a][b].positionBloc);

                                else if (chunk[x][y].blocs[a][b].type == CHARBON)
                                    SDL_BlitSurface(surfCharbon, NULL, ecran, &chunk[x][y].blocs[a][b].positionBloc);

                                else if (chunk[x][y].blocs[a][b].type == FER)
                                    SDL_BlitSurface(surfFer, NULL, ecran, &chunk[x][y].blocs[a][b].positionBloc);

                                else if (chunk[x][y].blocs[a][b].type == BOIS)
                                    SDL_BlitSurface(surfBois, NULL, ecran, &chunk[x][y].blocs[a][b].positionBloc);

                                else if (chunk[x][y].blocs[a][b].type == BOIS_NATUREL)
                                    SDL_BlitSurface(surfBoisNaturel, NULL, ecran, &chunk[x][y].blocs[a][b].positionBloc);

                                else if (chunk[x][y].blocs[a][b].type == FEUILLE)
                                    SDL_BlitSurface(surfFeuille, NULL, ecran, &chunk[x][y].blocs[a][b].positionBloc);

                                if (chunk[x][y].blocs[a][b].casse == 0)
                                {}
                                else if (chunk[x][y].blocs[a][b].casse < chunk[x][y].blocs[a][b].casseMax / 4)
                                {
                                    SDL_BlitSurface(casseUn, NULL, ecran, &chunk[x][y].blocs[a][b].positionBloc);
                                }
                                else if (chunk[x][y].blocs[a][b].casse < (chunk[x][y].blocs[a][b].casseMax / 4) * 2)
                                {
                                    SDL_BlitSurface(casseDeux, NULL, ecran, &chunk[x][y].blocs[a][b].positionBloc);
                                }
                                else if (chunk[x][y].blocs[a][b].casse < (chunk[x][y].blocs[a][b].casseMax / 4) * 3)
                                {
                                    SDL_BlitSurface(casseTrois, NULL, ecran, &chunk[x][y].blocs[a][b].positionBloc);
                                }
                                else if (chunk[x][y].blocs[a][b].casse <= chunk[x][y].blocs[a][b].casseMax)
                                {
                                    SDL_BlitSurface(casseQuatre, NULL, ecran, &chunk[x][y].blocs[a][b].positionBloc);
                                }
                            }

                            if (chunk[x][y].blocs[a][b].type != AIR)
                            {
                                if (chunk[x][y].blocs[a][b].luminosite < 0)
                                {
                                    chunk[x][y].blocs[a][b].luminosite = 0;
                                }
                                else if (chunk[x][y].blocs[a][b].luminosite > 15)
                                {
                                    chunk[x][y].blocs[a][b].luminosite = 15;
                                }

                                switch (chunk[x][y].blocs[a][b].luminosite)
                                {
                                    case 0:
                                        SDL_BlitSurface(caseLumineuse, NULL, ecran, &chunk[x][y].blocs[a][b].positionBloc);
                                        break;

                                    case 1:
                                        SDL_SetAlpha(caseLumineuse, SDL_SRCALPHA, 238);
                                        SDL_BlitSurface(caseLumineuse, NULL, ecran, &chunk[x][y].blocs[a][b].positionBloc);
                                        break;

                                    case 2:
                                        SDL_SetAlpha(caseLumineuse, SDL_SRCALPHA, 221);
                                        SDL_BlitSurface(caseLumineuse, NULL, ecran, &chunk[x][y].blocs[a][b].positionBloc);
                                        break;

                                    case 3:
                                        SDL_SetAlpha(caseLumineuse, SDL_SRCALPHA, 204);
                                        SDL_BlitSurface(caseLumineuse, NULL, ecran, &chunk[x][y].blocs[a][b].positionBloc);
                                        break;

                                    case 4:
                                        SDL_SetAlpha(caseLumineuse, SDL_SRCALPHA, 187);
                                        SDL_BlitSurface(caseLumineuse, NULL, ecran, &chunk[x][y].blocs[a][b].positionBloc);
                                        break;

                                    case 5:
                                        SDL_SetAlpha(caseLumineuse, SDL_SRCALPHA, 170);
                                        SDL_BlitSurface(caseLumineuse, NULL, ecran, &chunk[x][y].blocs[a][b].positionBloc);
                                        break;

                                    case 6:
                                        SDL_SetAlpha(caseLumineuse, SDL_SRCALPHA, 153);
                                        SDL_BlitSurface(caseLumineuse, NULL, ecran, &chunk[x][y].blocs[a][b].positionBloc);
                                        break;

                                    case 7:
                                        SDL_SetAlpha(caseLumineuse, SDL_SRCALPHA, 136);
                                        SDL_BlitSurface(caseLumineuse, NULL, ecran, &chunk[x][y].blocs[a][b].positionBloc);
                                        break;

                                    case 8:
                                        SDL_SetAlpha(caseLumineuse, SDL_SRCALPHA, 119);
                                        SDL_BlitSurface(caseLumineuse, NULL, ecran, &chunk[x][y].blocs[a][b].positionBloc);
                                        break;

                                    case 9:
                                        SDL_SetAlpha(caseLumineuse, SDL_SRCALPHA, 102);
                                        SDL_BlitSurface(caseLumineuse, NULL, ecran, &chunk[x][y].blocs[a][b].positionBloc);
                                        break;

                                    case 10:
                                        SDL_SetAlpha(caseLumineuse, SDL_SRCALPHA, 85);
                                        SDL_BlitSurface(caseLumineuse, NULL, ecran, &chunk[x][y].blocs[a][b].positionBloc);
                                        break;

                                    case 11:
                                        SDL_SetAlpha(caseLumineuse, SDL_SRCALPHA, 68);
                                        SDL_BlitSurface(caseLumineuse, NULL, ecran, &chunk[x][y].blocs[a][b].positionBloc);
                                        break;

                                    case 12:
                                        SDL_SetAlpha(caseLumineuse, SDL_SRCALPHA, 51);
                                        SDL_BlitSurface(caseLumineuse, NULL, ecran, &chunk[x][y].blocs[a][b].positionBloc);
                                        break;

                                    case 13:
                                        SDL_SetAlpha(caseLumineuse, SDL_SRCALPHA, 34);
                                        SDL_BlitSurface(caseLumineuse, NULL, ecran, &chunk[x][y].blocs[a][b].positionBloc);
                                        break;

                                    case 14:
                                        SDL_SetAlpha(caseLumineuse, SDL_SRCALPHA, 17);
                                        SDL_BlitSurface(caseLumineuse, NULL, ecran, &chunk[x][y].blocs[a][b].positionBloc);
                                        break;
                                }
                            }

                        }
                    }

                    chunk[x][y].blocs[a][b].positionBloc.x = memX;
                    chunk[x][y].blocs[a][b].positionBloc.y = memY;
                }
            }
        }
    }

    SDL_FreeSurface(caseLumineuse);
}
Esempio n. 24
0
void drawPixel(t_pixel pixel)
{
	SDL_BlitSurface(carre[pixel.color], NULL, screen, &pixel.position);
}
Esempio n. 25
0
void CFlash::render()
{
    // Blit it and free temp surface
    SDL_BlitSurface( mpFadeSurface.get(), NULL,
                     g_pVideoDriver->getBlitSurface(), NULL );
}
Esempio n. 26
0
void ezioEmulator::CreateSurfaces(void)
{
	// Define the colours we'll use
	bg.r = 73; bg.g = 84; bg.b = 149;
	bg_chr.r = 84; bg_chr.g = 97; bg_chr.b = 172;
	fg_chr.r = 250; fg_chr.g = 250; fg_chr.b = 255;

	// Create panel, pixel, and character surfaces
	lcd_panel = SDL_CreateRGBSurface(SDL_SWSURFACE,
		px_lcd_width, px_lcd_height, 32, rmask, gmask, bmask, amask);
	pixel_on = SDL_CreateRGBSurface(SDL_SWSURFACE,
		px_size / 2, px_size / 2, 32, rmask, gmask, bmask, amask);
	pixel_off = SDL_CreateRGBSurface(SDL_SWSURFACE,
		px_size / 2, px_size / 2, 32, rmask, gmask, bmask, amask);
	chr_on = SDL_CreateRGBSurface(SDL_SWSURFACE,
		px_chr_width, px_chr_height, 32, rmask, gmask, bmask, amask);
	chr_off = SDL_CreateRGBSurface(SDL_SWSURFACE,
		px_chr_width, px_chr_height, 32, rmask, gmask, bmask, amask);
	chr_uscore = SDL_CreateRGBSurface(SDL_SWSURFACE,
		px_chr_width, px_size / 2, 32, rmask, gmask, bmask, amask);

	SDL_SetAlpha(lcd_panel, 0, 0);
	SDL_SetAlpha(pixel_on, 0, 0);
	SDL_SetAlpha(pixel_off, 0, 0);
	SDL_SetAlpha(chr_on, 0, 0);
	SDL_SetAlpha(chr_off, 0, 0);
	SDL_SetAlpha(chr_uscore, 0, 0);

	SDL_FillRect(lcd_panel, NULL,
		SDL_MapRGB(lcd_panel->format, bg.r, bg.g, bg.b));
	SDL_FillRect(pixel_on, NULL,
		SDL_MapRGB(pixel_on->format, fg_chr.r, fg_chr.g, fg_chr.b));
	SDL_FillRect(pixel_off, NULL,
		SDL_MapRGB(pixel_off->format, bg_chr.r, bg_chr.g, bg_chr.b));
	SDL_FillRect(chr_on, NULL,
		SDL_MapRGB(chr_on->format, bg.r, bg.g, bg.b));
	SDL_FillRect(chr_off, NULL,
		SDL_MapRGB(chr_off->format, bg.r, bg.g, bg.b));
	SDL_FillRect(chr_uscore, NULL,
		SDL_MapRGB(chr_uscore->format, bg.r, bg.g, bg.b));

	// Create on/off pixel surfaces
	SDL_Rect rect;

	for (rect.y = 0;
		rect.y < px_chr_height; rect.y += (px_size / 2 + 1)) {
		for (rect.x = 0;
			rect.x < px_chr_width; rect.x += (px_size / 2 + 1)) {
			rect.w = rect.h = (px_size / 2);
			SDL_BlitSurface(pixel_on, NULL, chr_on, &rect);
		}
	}
	for (rect.y = 0;
		rect.y < px_chr_height; rect.y += (px_size / 2 + 1)) {
		for (rect.x = 0;
			rect.x < px_chr_width; rect.x += (px_size / 2 + 1)) {
			rect.w = rect.h = (px_size / 2);
			SDL_BlitSurface(pixel_off, NULL, chr_off, &rect);
		}
	}

	// Create underscore
	rect.y = 0;
	for (rect.x = 0;
		rect.x < px_chr_width; rect.x += (px_size / 2 + 1)) {
		rect.w = rect.h = (px_size / 2);
		SDL_BlitSurface(pixel_on, NULL, chr_uscore, &rect);
	}

	// Create font glyph surfaces
	device->GetFont()->Render(chr_off, pixel_on, pixel_off);

	// Create unknown character
	// TODO: throw: fatal if not found
	chr_unknown = device->GetFont()->GetGlyph('?');

	// Clear display
	UpdateDisplay(0);
}
Esempio n. 27
0
GLuint SDL_GL_LoadTexture(SDL_Surface *surface, GLfloat *texcoord)
{
    GLuint texture;
    int w, h;
    SDL_Surface *image;
    SDL_Rect area;
    Uint32 saved_flags;
    Uint8  saved_alpha;

    /* Use the surface width and height expanded to powers of 2 */
    w = power_of_two(surface->w);
    h = power_of_two(surface->h);
    texcoord[0] = 0.0f;			/* Min X */
    texcoord[1] = 0.0f;			/* Min Y */
    texcoord[2] = (GLfloat)surface->w / w;	/* Max X */
    texcoord[3] = (GLfloat)surface->h / h;	/* Max Y */

    image = SDL_CreateRGBSurface(
                SDL_SWSURFACE,
                w, h,
                32,
#if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */
                0x000000FF,
                0x0000FF00,
                0x00FF0000,
                0xFF000000
#else
                0xFF000000,
                0x00FF0000,
                0x0000FF00,
                0x000000FF
#endif
            );
    if ( image == NULL ) {
        return 0;
    }

    /* Save the alpha blending attributes */
    saved_flags = surface->flags&(SDL_SRCALPHA|SDL_RLEACCELOK);
    saved_alpha = surface->format->alpha;
    if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {
        SDL_SetAlpha(surface, 0, 0);
    }

    /* Copy the surface into the GL texture image */
    area.x = 0;
    area.y = 0;
    area.w = surface->w;
    area.h = surface->h;
    SDL_BlitSurface(surface, &area, image, &area);

    /* Restore the alpha blending attributes */
    if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {
        SDL_SetAlpha(surface, saved_flags, saved_alpha);
    }

    /* Create an OpenGL texture for the image */
    glGenTextures(1, &texture);
    glBindTexture(GL_TEXTURE_2D, texture);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexImage2D(GL_TEXTURE_2D,
                 0,
                 GL_RGBA,
                 w, h,
                 0,
                 GL_RGBA,
                 GL_UNSIGNED_BYTE,
                 image->pixels);
    SDL_FreeSurface(image); /* No longer needed */

    return texture;
}
Esempio n. 28
0
void DrawGradientText( const char* text, _sge_TTFont* font, int y, SDL_Surface* target, bool a_bTranslate )
{
	int i;

	if ( a_bTranslate )
	{
		text = Translate( text );
	}

	// 1. CREATE OFFSCREEN SURFACE
	
	SDL_Rect size = sge_TTF_TextSize( font, (char*)text );
	size.w += 2;
	size.h += 2;
	size.x = 320 - size.w / 2;
	if ( size.x < 0 ) size.x = 0;
	size.y = y;
	SDL_Surface* surface = SDL_CreateRGBSurface( SDL_SRCCOLORKEY, size.w, size.h, 8, 0,0,0,0 );


	if ( NULL == surface )
	{
		debug( "DrawGradientText: Couldn't allocate %d by %d surface!\n", size.w, size.h );
		return;
	}

	// 2. SET OFFSCREEN SURFACE COLORS

	SDL_SetColorKey( surface, SDL_SRCCOLORKEY, 0 );
	SDL_Color colors[256];
	colors[0].r = colors[0].g = colors[0].b = 0;
	colors[1] = colors[0];

	// The rest is red->yellow gradient.

	for ( i=2; i<255; ++i )
	{
		int j = i > 25 ? i-25 : 0;
		colors[i].r = 255;
		colors[i].g = 255-j;
		colors[i].b = 0;
	}

	SDL_SetColors( surface, colors, 0, 256 );

	// 3. DRAW TEXT, APPLY BORDER, APPLY GRADIENT.

	int y1 = sge_TTF_FontAscent(font);
	sge_tt_textout( surface, font, text,
		1, y1, 255, 0, 255);


	if ( SDL_MUSTLOCK(surface) ) SDL_LockSurface(surface);
	for ( y=1; y<size.h-1; ++y )
	{
		int color = 254 * y / (size.h-1) + 1;
		unsigned char *p0, *p1, *p2;
		p1 = (unsigned char*) surface->pixels;
		p1 += surface->pitch * y + 1;
		p0 = p1 - surface->pitch;
		p2 = p1 + surface->pitch;
		
		for ( int x=1; x<size.w-1; ++x, ++p0, ++p1, ++p2 )
		{
			if ( *p1 > 2 )
			{
				*p1 = color;
			}
			else
			{
				if ( (*(p1-1) > 2) || (*(p1+1) > 2) || *p0 > 2 || *p2 > 2 )
				{
					*p1 = 1;
				}
			}
		}
	}
	if ( SDL_MUSTLOCK(surface) ) SDL_UnlockSurface(surface);

	// 4. FINALLY

	SDL_BlitSurface( surface, NULL, target, &size );
	SDL_FreeSurface( surface );
	SDL_UpdateRect( target, size.x, size.y, size.w, size.h );
}
Esempio n. 29
0
static void update_rgb_surface (int index)
{
	update_rgb_pixels (video.buffer.buf[index].start);
	SDL_BlitSurface (screen.rgb.surface, NULL, screen.display, NULL);
	SDL_Flip (screen.display);
}
Esempio n. 30
0
void flashback(char* path) {

	//////////////////////////////////////initialize music, video and text/////////////////////////////////////

	SDL_Surface *screen; 
	SDL_Window *window;
	SDL_Surface *text;
	SDL_Rect paper = { 560, 140, 800, 800 };

	char *fullString = ReadFile(path);
	char *string; 
	int cnt = 0;
	int quit = 1;

	Mix_Music *typing = NULL;

	//init sdl mixer
	if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048) < 0) { 
		printf("SDL_mixer could not initialize! SDL_mixer Error: %s\n", Mix_GetError());  
	}

	//load music
	typing = Mix_LoadMUS("sounds/typing.mp3");
	if (NULL == typing) {
		printf("Failed to load low sound effect! SDL_mixer Error: %s\n", Mix_GetError());
	}
	Mix_PlayMusic(typing, -1);

	// init video
	SDL_Init(SDL_INIT_VIDEO); 

	// create the window
	
	window = SDL_CreateWindow("popup", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1920, 1080, SDL_WINDOW_BORDERLESS);

	// Initialize SDL_ttf library
	if (TTF_Init() != 0)
	{
		fprintf(stderr, "Init TTF failed! SDL_Error: %s", SDL_GetError());
	}

	// Load a font
	TTF_Font *font;
	font = TTF_OpenFont("FreeMonoBold.ttf", 24);
	if (font == NULL)
	{
		fprintf(stderr, "loading font failed! SDL_Error: %s", SDL_GetError());
	}

	// draw directly to the screen
	screen = SDL_GetWindowSurface(window);

	SDL_Event end;

	//////////////////////////////////////render Text on Screen/////////////////////////////////////
	while (1) {
		
		while(SDL_PollEvent(&end));

		string = addToString(cnt, fullString);
		cnt++;

		//write text to surface
		SDL_Color text_color = { 255, 255, 255 };
		text = TTF_RenderText_Blended_Wrapped(font,
			string,
			text_color,
			1000);


		SDL_FillRect(screen, NULL, 0x000000); 		//overwrite screen in black
		SDL_BlitSurface(text, NULL, screen, &paper);	// blit it to the screen
		

		SDL_UpdateWindowSurface(window);

		// show image for 60 ms
		SDL_Delay(60);


		//////////////////////////////////////Skip text on tap any key//////////////////////////////////
		
		if (SDL_KEYDOWN == end.type || '\0' == fullString[cnt]) {

			Mix_HaltMusic();
			end.type = 0;
			SDL_FillRect(screen, NULL, 0x000000);

			text = TTF_RenderText_Blended_Wrapped(font,
				fullString,
				text_color,
				1000);
			SDL_BlitSurface(text, NULL, screen, &paper); 
			SDL_UpdateWindowSurface(window);
			Mix_HaltMusic();

 			while (1) {
				while(SDL_PollEvent(&end));
 				if (SDL_KEYDOWN == end.type) {
					quit = 0;
					break;
				}
			}
			break;	
		}
	}

	Mix_HaltMusic();
	Mix_FreeMusic(typing);
	typing = NULL;
	SDL_FreeSurface(text);
	SDL_FreeSurface(screen);
	SDL_DestroyWindow(window);
}