TGfxImage * Blur(TGfxImage * pImage, const int iSizeX, const int iSizeY) { TGfxImage * pTempImage = GfxImageCreate(iSizeX, iSizeY); for (int y = 0; y < iSizeY; y++) { for (int x = 0; x < iSizeX; x++) { const int iIndex = y*(iSizeX) + x; const unsigned int iColor = GfxImageGetData(pImage)[iIndex]; //-------- const int iIndexLeft = iIndex - 1; const int iIndexRight = iIndex + 1; const int iIndexUp = iIndex - iSizeX; const int iIndexDown = iIndex + iSizeX; //-------- unsigned int iColorPix = 0; // if (GfxImageGetData(pImage)[iIndexLeft] != iColor)iColorPix++; // if (GfxImageGetData(pImage)[iIndexRight] != iColor)iColorPix++; // if (GfxImageGetData(pImage)[iIndexUp] != iColor)iColorPix++; // if (GfxImageGetData(pImage)[iIndexDown] != iColor)iColorPix++; if (iIndexLeft >= 0) if (GfxImageGetData(pImage)[iIndexLeft] != iColor)iColorPix++; if (iIndexRight < (iSizeX*iSizeY)) if (GfxImageGetData(pImage)[iIndexRight] != iColor)iColorPix++; if (iIndexUp >= 0) if (GfxImageGetData(pImage)[iIndexUp] != iColor)iColorPix++; if (iIndexDown < (iSizeX*iSizeY)) if (GfxImageGetData(pImage)[iIndexDown] != iColor)iColorPix++; if ((x == 0) || (y == 0) || (x == (iSizeX-1)) || (y == (iSizeY-1))) GfxImageGetData(pTempImage)[iIndex] = EGfxColor_Black; else { if (iColorPix > 2) GfxImageGetData(pTempImage)[iIndex] = (GfxImageGetData(pImage)[iIndex] == EGfxColor_Black) ? EGfxColor_White : EGfxColor_Black; else GfxImageGetData(pTempImage)[iIndex] = GfxImageGetData(pImage)[iIndex]; } } } GfxImageDestroy(pImage); return pTempImage; }
TGfxImage * Clear(TGfxImage * pImage, const int iSizeX, const int iSizeY, const int iPowerClear) { TGfxImage * pTempImage = GfxImageCreate(iSizeX, iSizeY); for (int y = 0; y < iSizeY; y++) { for (int x = 0; x < iSizeX; x++) { const int iIndex = y*(iSizeX)+x; if (GfxImageGetData(pImage)[iIndex] == EGfxColor_Black) { //-------- const int iIndexLeft = iIndex - 1; const int iIndexRight = iIndex + 1; const int iIndexUp = iIndex - iSizeX; const int iIndexDown = iIndex + iSizeX; //-------- int iColorPix = 0; if (iIndex >= 0 && iIndex < (iSizeX*iSizeY)) { if (iIndexLeft >= 0) if (GfxImageGetData(pImage)[iIndexLeft] != EGfxColor_White)iColorPix++; if (iIndexRight < (iSizeX*iSizeY)) if (GfxImageGetData(pImage)[iIndexRight] != EGfxColor_White)iColorPix++; if (iIndexUp >= 0) if (GfxImageGetData(pImage)[iIndexUp] != EGfxColor_White)iColorPix++; if (iIndexDown < (iSizeX*iSizeY)) if (GfxImageGetData(pImage)[iIndexDown] != EGfxColor_White)iColorPix++; } if (iColorPix > iPowerClear) GfxImageGetData(pTempImage)[iIndex] = EGfxColor_Black; else GfxImageGetData(pTempImage)[iIndex] = EGfxColor_White; } else GfxImageGetData(pTempImage)[iIndex] = EGfxColor_White; if ((x == 0) || (y == 0) || (x == (iSizeX-1)) || (y == (iSizeY-1))) GfxImageGetData(pTempImage)[iIndex] = EGfxColor_Black; } } GfxImageDestroy(pImage); return pTempImage; }
void Initialize() { g_pBackground = GfxImageLoad("gfx/bg3.tga"); g_pTextureTest = GfxTextureCreate(g_pBackground); g_pSpritesBg = GfxSpriteCreate(g_pTextureTest); g_pTexture = GfxTextureLoad("gfx/tileset.tga"); // On crée g_pTexture ici et on l'envoie dans l'appel de fonction g_pSpriteHero = CreateTile(g_pTexture, 7, 7, 7, 5); // Initialisée en dehors du scope pour l'utiliser autre part ( Donc on n'écrit pas "TGfxSPrite *" devant ) ( debug mode = 2, 1 | normal mode = 0, 0 ) TGfxImage * pMapImage = GfxImageLoad("gfx/map.tga"); // Pas en const car on peut vouloir la delete ( Si on le laisse comme ça, il sera inutile et prendra de la mémoire inutile ! il faut le delete après la boucle avec le destroy int iImgSizeX = GfxImageGetSizeX(pMapImage); int iImgSizeY = GfxImageGetSizeY(pMapImage); for (int y = 0; y < iImgSizeY; ++y) { for (int x = 0; x < iImgSizeX; ++x) { const int iIndex = x + y * iImgSizeX; if (GfxImageGetData(pMapImage)[iIndex] == GfxColor(255, 255, 255, 255)) // SI je veux aller voir le premier élément je dois mettre [0] { g_pSpriteWall[g_iWallCount] = CreateTile(g_pTexture, 6, 1, x, y); // 6 et 1 au lieu de 1 et 1 pour mur ( 1, 1 = debug mode test ) g_iWallCount++; } if (GfxImageGetData(pMapImage)[iIndex] == GfxColor(255, 0, 0, 255)) // SI je veux aller voir le premier élément je dois mettre [0] { g_pSpriteDeathWall[g_iDeathWallCount] = CreateTile(g_pTexture, 7, 1, x, y); g_iDeathWallCount++; } } } GfxImageDestroy(pMapImage); // for (int i = 0; i < WALL_HEIGHT; i++) !!!!!! Attention que ça doit bien s'adapter à la taille du tableau !!!!!! // { // g_pSpriteWall[i] = CreateTile(g_pTexture, 12, 3, 0, i); // } // TGfxImage Les 3 permettent d'afficher des choses. // TGfxTexture Une image est un ensemble de pixel d'un certaine taille. // TGfxSprite 32 bits par pixel. // Un sprite n'est pas autonome, ça fait référence à une texture existente, il contiendra les info qui lui diront avec quelle rotation, quelle SCALE, et quelle partie de la texture utiliser ! Le sprite c'est la transformation. une partie de la texture }
void Initialize() { g_pTexture = GfxTextureLoad("gfx/tileset.tga"); // On crée g_pTexture ici et on l'envoie dans l'appel de fonction g_pSpriteHero = CreateTile(g_pTexture, 1, 4, 1, 1); // Initialisée en dehors du scope pour l'utiliser autre part ( Donc on n'écrit pas "TGfxSPrite *" devant ) g_pSpriteEnemy = CreateTile(g_pTexture, 8, 7, 2, 2); TGfxImage * pMapImage = GfxImageLoad("gfx/map.tga"); // Pas en const car on peut vouloir la delete ( Si on le laisse comme ça, il sera inutile et prendra de la mémoire inutile ! il faut le delete après la boucle avec le destroy int iImgSizeX = GfxImageGetSizeX(pMapImage); int iImgSizeY = GfxImageGetSizeY(pMapImage); for (int y = 0; y < iImgSizeY; ++y) { for (int x = 0; x < iImgSizeX; ++x) { const int iIndex = x + y * iImgSizeX; // Le *15 permet de compter les lignes déja parcourue ... if (GfxImageGetData(pMapImage)[iIndex] == GfxColor(255,255,255,255)) // SI je veux aller voir le premier élément je dois mettre [0] { g_pSpriteWall[g_iWallCount] = CreateTile(g_pTexture, 6, 1, x, y); g_iWallCount++; } } } GfxImageDestroy(pMapImage); // for (int i = 0; i < WALL_HEIGHT; i++) !!!!!! Attention que ça doit bien s'adapter à la taille du tableau !!!!!! // { // g_pSpriteWall[i] = CreateTile(g_pTexture, 12, 3, 0, i); // } GfxSpriteSetPosition(g_pSpriteEnemy, -16 * SCALE, 0 * SCALE); // *4 car on a agrandi la texture X4, c'est pour avoir la même échelle // TGfxImage Les 3 permettent d'afficher des choses. // TGfxTexture Une image est un ensemble de pixel d'un certaine taille. // TGfxSprite 32 bits par pixel. // Un sprite n'est pas autonome, ça fait référence à une texture existente, il contiendra les info qui lui diront avec quelle rotation, quelle SCALE, et quelle partie de la texture utiliser ! Le sprite c'est la transformation. une partie de la texture }
void Initialize() { g_pBackgroundImage = GfxImageLoad("map.tga"); g_pData = GfxImageGetData(g_pBackgroundImage); const int iImgSizeX = GfxImageGetSizeX(g_pBackgroundImage); const int iImgSizeY = GfxImageGetSizeY(g_pBackgroundImage); for (int y = 0; y < iImgSizeY; ++y) { for (int x = 0; x < iImgSizeX; ++x) { const int iIndex = x + (y * iImgSizeX); if (g_pData[iIndex] == GfxColor(0, 0, 255, 255) || g_pData[iIndex] == GfxColor(255, 0, 0, 255) || g_pData[iIndex] == GfxColor(0, 255, 0, 255)) { g_pData[iIndex] = EGfxColor_White; } } } g_pBackgroundTexture = GfxTextureCreate(g_pBackgroundImage); g_pBackgroundSprite = GfxSpriteCreate(g_pBackgroundTexture); GfxSpriteSetScale(g_pBackgroundSprite, 32, 32); GfxSpriteSetFilteringEnabled(g_pBackgroundSprite, false); g_pSpriteIncome = GfxTextSpriteCreate(); GfxTextSpritePrintf(g_pSpriteIncome, "revenue: $%d", g_iIncome); GfxSpriteSetFilteringEnabled(g_pSpriteIncome, false); GfxSpriteSetScale(g_pSpriteIncome, 2, 2); GfxSpriteSetPosition(g_pSpriteIncome, float((GfxGetDisplaySizeX() / 2) - GfxSpriteGetSizeX(g_pSpriteIncome)), 290); GfxSpriteSetColor(g_pSpriteIncome, GfxColor(255, 255, 255, 255)); TGfxImage * pMapImage = GfxImageLoad("map.tga"); const int iSecondImgSizeX = GfxImageGetSizeX(pMapImage); const int iSecondImgSizeY = GfxImageGetSizeY(pMapImage); for (int i = 0; i < 3; i++) // Boucle créant les numéros sur les buildings { for (int y = 0; y < iSecondImgSizeY; ++y) { for (int x = 0; x < iSecondImgSizeX; ++x) { const int iIndex = x + (y * iSecondImgSizeX); if (i == 0) { if (GfxImageGetData(pMapImage)[iIndex] == GfxColor(255, 0, 0, 255)) // RED CHECKING & CREATING { g_tBuilding[g_iBuildingCount].Create(x, y, g_iBuildingCount, SCALE); g_iBuildingCount++; } } else if (i == 1) { if (GfxImageGetData(pMapImage)[iIndex] == GfxColor(0, 255, 0, 255)) // GREEN CHECKING & CREATING { g_tBuilding[g_iBuildingCount].Create(x, y, g_iBuildingCount, SCALE); g_iBuildingCount++; } } else if (i == 2) { if (GfxImageGetData(pMapImage)[iIndex] == GfxColor(0, 0, 255, 255)) // BLUE CHECKING & CREATING { g_tBuilding[g_iBuildingCount].Create(x, y, g_iBuildingCount, SCALE); g_iBuildingCount++; } } } } } GfxImageDestroy(pMapImage); }