Partage
  • Partager sur Facebook
  • Partager sur Twitter

Problème de SDL_Rect (je suppose ...)

Sujet résolu
    18 février 2017 à 20:58:17

    Bonsoir,

    merci de bien vouloir m'aider j'ai fait une courte vidéo sur le lien suivant pour vous montrez mon problème je trouve ça plus simple pour expliquer :

    https://www.youtube.com/watch?v=HxM25apNEyk&feature=youtu.be

    Mon code :

    #include <stdlib.h>
    #include <stdio.h>
    #include <string.h>
    #include <time.h>
    #include <SDL/SDL.h>
    #include <SDL/SDL_image.h>
    #include <SDL/SDL_ttf.h>
    #include <fmod.h>
    
    
    
    
    typedef struct
    {
    	char key[SDLK_LAST];
    	int mousex,mousey;
    	int mousexrel,mouseyrel;
    	char mousebuttons[8];
            char quit;
    } Input;
    
    
    
    void UpdateEvents(Input* in)
    {
    	SDL_Event event;
            in->mousebuttons[SDL_BUTTON_WHEELUP] = 0;
            in->mousebuttons[SDL_BUTTON_WHEELDOWN] = 0;
    	while(SDL_PollEvent(&event))
    	{
    		switch (event.type)
    		{
    		case SDL_KEYDOWN:
    			in->key[event.key.keysym.sym]=1;
    			break;
    		case SDL_KEYUP:
    			in->key[event.key.keysym.sym]=0;
    			break;
    		case SDL_MOUSEMOTION:
    			in->mousex=event.motion.x;
    			in->mousey=event.motion.y;
    			in->mousexrel=event.motion.xrel;
    			in->mouseyrel=event.motion.yrel;
    			break;
    		case SDL_MOUSEBUTTONDOWN:
    			in->mousebuttons[event.button.button]=1;
    			break;
    		case SDL_MOUSEBUTTONUP:
                            if (event.button.button!=SDL_BUTTON_WHEELUP && event.button.button!=SDL_BUTTON_WHEELDOWN)
    			   in->mousebuttons[event.button.button]=0;
    			break;
    		case SDL_QUIT:
    			in->quit = 1;
    			break;
    		default:
    			break;
    		}
    	}
    }
    
    
    
    int main ( int argc, char** argv )
    {
    
        SDL_Surface *ecran = NULL;
        SDL_Surface *fond = NULL;
    
        SDL_Surface *slotMenu = NULL;
    
        SDL_Surface *slotMap[7]; // 0 = vide || 1 = coal || 2 = iron || 3 = gold || 4 = diamond || 5 = emerald || 6 = building
        SDL_Surface *slotShop[6]; // 0 = mineral || 1 = tool || 2 = build || 3 = upgrade || 4 = contract || 5 = inventory
        SDL_Surface *slotInfo[8]; // 0 = money || 1 = energy || 2 = stone || 3 = coal || 4 = iron || 5 = gold || 6 = diamond || 7 = emerald
        SDL_Surface *slotMapLock = NULL;
        SDL_Surface *slotMapOk[7]; // 0 = vide || 1 = coal || 2 = iron || 3 = gold || 4 = diamond || 5 = emerald || 6 = building
    
        SDL_Surface *slotQuitMap = NULL;
        SDL_Surface *slotOptionMap = NULL;
        SDL_Surface *slotOptionMapOk = NULL;
        SDL_Surface *slotOptionMapChoice = NULL;
        SDL_Surface *mapTheme[7]; // 0 = vide || 1 = coal || 2 = iron || 3 = gold || 4 = diamond || 5 = emerald || 6 = building
    
        SDL_Surface *slotShopOk[6];
    
        SDL_Surface *slotInventory[24];
    
        SDL_Surface *slotSwitchInventory[2];
        SDL_Surface *slotSwitchInventoryOk[2];
    
    
    
    
    
        SDL_Surface *textPaper = NULL;
        SDL_Surface *textEnergy = NULL;
        SDL_Surface *textStone = NULL;
        SDL_Surface *textCoal = NULL;
        SDL_Surface *textIron = NULL;
        SDL_Surface *textGold = NULL;
        SDL_Surface *textDiamond = NULL;
        SDL_Surface *textEmerald = NULL;
    
        SDL_Surface *textMaxEnergy = NULL;
        SDL_Surface *textMaxStone = NULL;
        SDL_Surface *textMaxCoal = NULL;
        SDL_Surface *textMaxIron = NULL;
        SDL_Surface *textMaxGold = NULL;
        SDL_Surface *textMaxDiamond = NULL;
        SDL_Surface *textMaxEmerald = NULL;
    
    
    
    
        int i = 0;
        int u = 0;
        int b = 0;
        int a = 0;
    
        SDL_Rect posInit;
        SDL_Rect posSlotMenu;
        SDL_Rect posSlotMap[9];
        SDL_Rect posSlotShop[6];
        SDL_Rect posSlotInfo[8];
        SDL_Rect posSlotQuitMap;
        SDL_Rect posSlotOptionChoice[3];
        SDL_Rect posS;
        SDL_Rect posTextInfo[15];
        SDL_Rect posSlotInventory[10];
    
        posInit.x = 0;
        posInit.y = 0;
    
        posSlotMenu.x = 1000; // ------------------------------------------------------
        posSlotMenu.y = 0;
    
        posSlotMap[0].x = 0;
        posSlotMap[0].y = 0;
        posSlotMap[1].x = 0;
        posSlotMap[1].y = 165;
        posSlotMap[2].x = 0;
        posSlotMap[2].y = 330;
        posSlotMap[3].x = 0;
        posSlotMap[3].y = 495;
        posSlotMap[4].x = 250;
        posSlotMap[4].y = 0;
        posSlotMap[5].x = 250;
        posSlotMap[5].y = 165;
        posSlotMap[6].x = 250;
        posSlotMap[6].y = 330;
        posSlotMap[7].x = 250;
        posSlotMap[7].y = 495;
    
        posSlotShop[0].x = 501;
        posSlotShop[0].y = 0;
        posSlotShop[1].x = 584;
        posSlotShop[1].y = 0;
        posSlotShop[2].x = 667;
        posSlotShop[2].y = 0;
        posSlotShop[3].x = 750;
        posSlotShop[3].y = 0;
        posSlotShop[4].x = 833;
        posSlotShop[4].y = 0;
        posSlotShop[5].x = 916;
        posSlotShop[5].y = 0;
    
        posSlotInfo[0].x = 1000;
        posSlotInfo[0].y = 50;
        posSlotInfo[1].x = 1000;
        posSlotInfo[1].y = 126;
        posSlotInfo[2].x = 1000;
        posSlotInfo[2].y = 202;
        posSlotInfo[3].x = 1000;
        posSlotInfo[3].y = 278;
        posSlotInfo[4].x = 1000;
        posSlotInfo[4].y = 354;
        posSlotInfo[5].x = 1000;
        posSlotInfo[5].y = 430;
        posSlotInfo[6].x = 1000;
        posSlotInfo[6].y = 506;
        posSlotInfo[7].x = 1000;
        posSlotInfo[7].y = 582;
    
        posSlotQuitMap.x = 475; // ---------------------------------------------------------
        posSlotQuitMap.y = 0;
    
        posSlotOptionChoice[0].x = 150;
        posSlotOptionChoice[0].y = 0;
        posSlotOptionChoice[1].x = 150;
        posSlotOptionChoice[1].y = 50;
        posSlotOptionChoice[2].x = 150;
        posSlotOptionChoice[2].y = 100;
    
        posTextInfo[0].x = 1010;
        posTextInfo[0].y = 55;
        posTextInfo[1].x = 1010;
        posTextInfo[1].y = 131;
        posTextInfo[2].x = 1060;
        posTextInfo[2].y = 165;
        posTextInfo[3].x = 1010;
        posTextInfo[3].y = 207;
        posTextInfo[4].x = 1060;
        posTextInfo[4].y = 241;
        posTextInfo[5].x = 1010;
        posTextInfo[5].y = 283;
        posTextInfo[6].x = 1060;
        posTextInfo[6].y = 317;
        posTextInfo[7].x = 1010;
        posTextInfo[7].y = 359;
        posTextInfo[8].x = 1060;
        posTextInfo[8].y = 393;
        posTextInfo[9].x = 1010;
        posTextInfo[9].y = 435;
        posTextInfo[10].x = 1060;
        posTextInfo[10].y = 469;
        posTextInfo[11].x = 1010;
        posTextInfo[11].y = 511;
        posTextInfo[12].x = 1060;
        posTextInfo[12].y = 545;
        posTextInfo[13].x = 1010;
        posTextInfo[13].y = 587;
        posTextInfo[14].x = 1060;
        posTextInfo[14].y = 621;
    
        posSlotInventory[0].x = 500;
        posSlotInventory[0].y = 80;
        posSlotInventory[1].x = 750;
        posSlotInventory[1].y = 80;
        posSlotInventory[2].x = 500;
        posSlotInventory[2].y = 196;
        posSlotInventory[3].x = 750;
        posSlotInventory[3].y = 196;
        posSlotInventory[4].x = 500;
        posSlotInventory[4].y = 312;
        posSlotInventory[5].x = 750;
        posSlotInventory[5].y = 312;
        posSlotInventory[6].x = 500;
        posSlotInventory[6].y = 428;
        posSlotInventory[7].x = 750;
        posSlotInventory[7].y = 428;
        posSlotInventory[8].x = 500;
        posSlotInventory[8].y = 544;
        posSlotInventory[9].x = 750;
        posSlotInventory[9].y = 544;
    
    
    
    
    
    
    
        SDL_Init(SDL_INIT_VIDEO);
        TTF_Init();
    
        FILE* fichier = NULL;
    
        Input in;
    
    
        TTF_Font *police = NULL;
        SDL_Color couleurNoir = {0, 0, 0};
        police = TTF_OpenFont("police/ariblk.ttf", 20);
    
    
        int terminer = 0;
        int continuer = 0;
        int free = 0; //pour libérer les mémoire
    
        int mapLock[8];
    
        int slotOkMap[8];
    
        int showMap = 8; // 8 = rien
    
    
    
        int slotMapQuitOk = 0;
        int slotOkOptionMap = 0;
    
        int showOptionChoice = 0;
    
    
    
        int slotOkShop[6];
        int shopOpen = 6;
    
        int slotItemInventory[24];
        int menuInventory = 0; // 0-1-2
    
        int slotInventorySwitchOk[2];
    
        slotItemInventory[0] = 0;
        slotItemInventory[1] = 0;
        slotItemInventory[2] = 0;
        slotItemInventory[3] = 0;
        slotItemInventory[4] = 0;
        slotItemInventory[5] = 0;
        slotItemInventory[6] = 0;
        slotItemInventory[7] = 0;
        slotItemInventory[8] = 0;
        slotItemInventory[9] = 0;
        slotItemInventory[10] = 0;
        slotItemInventory[11] = 0;
        slotItemInventory[12] = 0;
        slotItemInventory[13] = 0;
        slotItemInventory[14] = 0;
        slotItemInventory[15] = 0;
        slotItemInventory[16] = 0;
        slotItemInventory[17] = 0;
        slotItemInventory[18] = 0;
        slotItemInventory[19] = 0;
        slotItemInventory[20] = 0;
        slotItemInventory[21] = 0;
        slotItemInventory[22] = 0;
        slotItemInventory[23] = 0;
    
    
    
    
    
    
        int paper = 0;
        int energy = 0;
        int stone = 0;
        int coal = 0;
        int iron = 0;
        int gold = 0;
        int diamond = 0;
        int emerald = 0;
    
        int maxEnergy = 0;
        int maxStone = 0;
        int maxCoal = 0;
        int maxIron = 0;
        int maxGold = 0;
        int maxDiamond = 0;
        int maxEmerald = 0;
    
        char charPaper[25] = "";
        char charEnergy[25] = "";
        char charStone[25] = "";
        char charCoal[25] = "";
        char charIron[25] = "";
        char charGold[25] = "";
        char charDiamond[25] = "";
        char charEmerald[25] = "";
    
        char charMaxEnergy[25] = "";
        char charMaxStone[25] = "";
        char charMaxCoal[25] = "";
        char charMaxIron[25] = "";
        char charMaxGold[25] = "";
        char charMaxDiamond[25] = "";
        char charMaxEmerald[25] = "";
    
    
        i = 0;
        while (i != 8)
        {
            mapLock[i] = 1;
            slotOkMap[i] = 0;
            slotOkShop[i] = 0;
            slotInventorySwitchOk[i] = 0;
            i ++;
        }
        mapLock[0] = 0;
    
    
    
    
        ecran = SDL_SetVideoMode(1280, 660, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
        SDL_WM_SetCaption("Mineur Clicker", NULL);
    
        SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 0, 0, 0));
    
        fond = IMG_Load("frame/decord/fond.png");
    
        slotMenu = IMG_Load("frame/slotInfo/slotMenu.png");
    
        slotMap[0] = IMG_Load("frame/slotMap/slotVide.png");
    
        slotMapOk[0] = IMG_Load("frame/slotMap/slotVideOk.png");
    
        slotMapLock = IMG_Load("frame/slotMap/slotMapLock.png");
    
    
        mapTheme[0] = IMG_Load("frame/map/mapVide.png");
    
        slotQuitMap = IMG_Load("frame/map/slotQuitMap.png");
        slotOptionMap = IMG_Load("frame/map/slotOptionMap.png");
        slotOptionMapOk = IMG_Load("frame/map/slotOptionMapOk.png");
        slotOptionMapChoice = IMG_Load("frame/map/slotOptionMapChoice.png");
    
        slotInfo[0] = IMG_Load("frame/slotInfo/slotPaper.png");
        slotInfo[1] = IMG_Load("frame/slotInfo/slotEnergy.png");
        slotInfo[2] = IMG_Load("frame/slotInfo/slotStone.png");
        slotInfo[3] = IMG_Load("frame/slotInfo/slotCoal.png");
        slotInfo[4] = IMG_Load("frame/slotInfo/slotIron.png");
        slotInfo[5] = IMG_Load("frame/slotInfo/slotGold.png");
        slotInfo[6] = IMG_Load("frame/slotInfo/slotDiamond.png");
        slotInfo[7] = IMG_Load("frame/slotInfo/slotEmerald.png");
    
        slotShop[0] = IMG_Load("frame/slotShop/slotMineral.png");
        slotShop[1] = IMG_Load("frame/slotShop/slotTool.png");
        slotShop[2] = IMG_Load("frame/slotShop/slotBuild.png");
        slotShop[3] = IMG_Load("frame/slotShop/slotUpgrade.png");
        slotShop[4] = IMG_Load("frame/slotShop/slotContract.png");
        slotShop[5] = IMG_Load("frame/slotShop/slotInventory.png");
    
        slotShopOk[0] = IMG_Load("frame/slotShop/slotMineralOk.png");
        slotShopOk[1] = IMG_Load("frame/slotShop/slotToolOk.png");
        slotShopOk[2] = IMG_Load("frame/slotShop/slotBuildOk.png");
        slotShopOk[3] = IMG_Load("frame/slotShop/slotUpgradeOk.png");
        slotShopOk[4] = IMG_Load("frame/slotShop/slotContractOk.png");
        slotShopOk[5] = IMG_Load("frame/slotShop/slotInventoryOk.png");
    
        slotInventory[0] = IMG_Load("frame/slotShop/inventory/nothing.png");
        slotInventory[1] = IMG_Load("frame/slotShop/inventory/coalContract.png");
        slotInventory[2] = IMG_Load("frame/slotShop/inventory/ironContract.png");
        slotInventory[3] = IMG_Load("frame/slotShop/inventory/goldContract.png");
        slotInventory[4] = IMG_Load("frame/slotShop/inventory/diamondContract.png");
        slotInventory[5] = IMG_Load("frame/slotShop/inventory/emeraldContract.png");
        slotInventory[6] = IMG_Load("frame/slotShop/inventory/stoneStorage.png");
        slotInventory[7] = IMG_Load("frame/slotShop/inventory/coalStorage.png");
        slotInventory[8] = IMG_Load("frame/slotShop/inventory/ironStorage.png");
        slotInventory[9] = IMG_Load("frame/slotShop/inventory/goldStorage.png");
        slotInventory[10] = IMG_Load("frame/slotShop/inventory/diamondStorage.png");
        slotInventory[11] = IMG_Load("frame/slotShop/inventory/emeraldStorage.png");
        slotInventory[12] = IMG_Load("frame/slotShop/inventory/energyStorage.png");
        slotInventory[13] = IMG_Load("frame/slotShop/inventory/farmer.png");
        slotInventory[14] = IMG_Load("frame/slotShop/inventory/coalDrill.png");
        slotInventory[15] = IMG_Load("frame/slotShop/inventory/ironDrill.png");
        slotInventory[16] = IMG_Load("frame/slotShop/inventory/goldDrill.png");
        slotInventory[17] = IMG_Load("frame/slotShop/inventory/diamondDrill.png");
        slotInventory[18] = IMG_Load("frame/slotShop/inventory/emeraldDrill.png");
        slotInventory[19] = IMG_Load("frame/slotShop/inventory/furnace.png");
        slotInventory[20] = IMG_Load("frame/slotShop/inventory/coalStation.png");
        slotInventory[21] = IMG_Load("frame/slotShop/inventory/solarPanel.png");
        slotInventory[22] = IMG_Load("frame/slotShop/inventory/windTurbine.png");
        slotInventory[23] = IMG_Load("frame/slotShop/inventory/hydraulicSystem.png");
    
        slotSwitchInventory[0] = IMG_Load("frame/slotShop/slotSwitchLeft.png");
        slotSwitchInventory[1] = IMG_Load("frame/slotShop/slotSwitchRight.png");
        slotSwitchInventoryOk[0] = IMG_Load("frame/slotShop/slotSwitchLeftOk.png");
        slotSwitchInventoryOk[1] = IMG_Load("frame/slotShop/slotSwitchRightOk.png");
    
    
    
    
    
        //------------------------------------------------------------- DELETE --------------------------------------------------------------
    
        mapLock[1] = 0;
    
        paper = 10000;
        maxStone = 1000;
        maxCoal = 1000;
    
        slotItemInventory[1] = 4;
        slotItemInventory[0] = 1;
        slotItemInventory[11] = 17;
    
    
    
        //------------------------------------------------------------- DELETE --------------------------------------------------------------
    
    
        memset(&in,0,sizeof(in));
        continuer = 0;
        while (continuer != 1)
        {
    
    
    
    	UpdateEvents(&in);
            if (in.quit)
            {
                continuer = 1;
                terminer = 1;
            }
            if (in.mousebuttons[SDL_BUTTON_LEFT])
            {
                in.mousebuttons[SDL_BUTTON_LEFT] = 0;
    
    
                //------------------------------------------------------------------------------ Map Interact ----------------------------------------------------------------------------------------
                if (showMap != 8)
                {
                    if (slotMapQuitOk == 1)
                    {
                         showMap = 8;
                         showOptionChoice = 0;
                         slotMapQuitOk = 0;
                    }
                    if (slotOkOptionMap == 1)
                    {
                        if (showOptionChoice)
                        {
                            showOptionChoice = 0;
                        }
                        else
                        {
                            showOptionChoice = 1;
                        }
                    }
    
                }
                else
                {
                    i = 0;
                    while (i != 8)
                    {
                        if (slotOkMap[i] == 1)
                        {
                            showMap = i;
                            slotOkMap[i] = 0;
                        }
                        i ++;
                    }
                }
                //------------------------------------------------------------------------------ Map Interact ----------------------------------------------------------------------------------------
    
                //---------------------------------------------------------------------------- Inventory Interact ------------------------------------------------------------------------------------
                if (slotInventorySwitchOk[0] == 1)
                {
                    if (menuInventory != 0)
                    {
                        menuInventory --;
                    }
                }
                if (slotInventorySwitchOk[1] == 1)
                {
                    if (menuInventory != 2)
                    {
                        menuInventory ++;
                    }
                }
                //---------------------------------------------------------------------------- Inventory Interact ------------------------------------------------------------------------------------
    
    
            }
    
    
    
    
    
    
            posS.x = in.mousex;
            posS.y = in.mousey;
    
    
    
    
    
            SDL_BlitSurface(fond, NULL, ecran, &posInit);
    
    
    
    
            //------------------------------------------------------------------------------------ Map -----------------------------------------------------------------------------------------------
            if (showMap == 8)
            {
    
                i = 0;
                while (i != 8)
                {
                    SDL_BlitSurface(slotMap[0], NULL, ecran, &posSlotMap[i]);
                    i ++;
                }
                i = 0;
                while (i != 8)
                {
                    if (posS.x >= posSlotMap[i].x && posS.x <= posSlotMap[i].x + 250 && posS.y >= posSlotMap[i].y && posS.y <= posSlotMap[i].y + 165)
                    {
                        if (mapLock[i] == 0)
                        {
                            slotOkMap[i] = 1;
                            SDL_BlitSurface(slotMapOk[0], NULL, ecran, &posSlotMap[i]);
                        }
    
                    }
                    else
                    {
                        slotOkMap[i] = 0;
                    }
                    i ++;
                }
                i = 0;
                while (i != 8)
                {
                    if (mapLock[i] == 1)
                    {
                        SDL_BlitSurface(slotMapLock, NULL, ecran, &posSlotMap[i]);
                    }
                    i ++;
                }
    
            }
            else
            {
    
                if (posS.x >= posSlotQuitMap.x && posS.x <= posSlotQuitMap.x + 25 && posS.y >= posSlotQuitMap.y && posS.y <= posSlotQuitMap.y + 25)
                {
                    slotMapQuitOk = 1;
                }
                else
                {
                    slotMapQuitOk = 0;
                }
    
    
    
    
    
    
    
    
    
                SDL_BlitSurface(mapTheme[0], NULL, ecran, &posInit);
    
    
    
    
    
    
                SDL_BlitSurface(slotOptionMap, NULL, ecran ,&posInit);
                if (showOptionChoice == 1)
                {
                    SDL_BlitSurface(slotOptionMapChoice, NULL, ecran, &posSlotOptionChoice[0]);
                }
                if (posS.x >= posInit.x && posS.x <= posInit.x + 150 && posS.y >= posInit.y && posS.y <= posInit.y + 50)
                {
                    slotOkOptionMap = 1;
                    SDL_BlitSurface(slotOptionMapOk, NULL, ecran, &posInit);
    
                }
                else if (posS.x >= posInit.x + 150 && posS.x <= posInit.x + 300 && posS.y >= posInit.y && posS.y <= posInit.y + 50 && showOptionChoice == 1)
                {
                    slotOkOptionMap = 2;
                    SDL_BlitSurface(slotOptionMapOk, NULL, ecran, &posSlotOptionChoice[0]);
    
                }
                else if (posS.x >= posInit.x + 150 && posS.x <= posInit.x + 300 && posS.y >= posInit.y + 50 && posS.y <= posInit.y + 100 && showOptionChoice == 1)
                {
                    slotOkOptionMap = 3;
                    SDL_BlitSurface(slotOptionMapOk, NULL, ecran, &posSlotOptionChoice[1]);
    
                }
                else if (posS.x >= posInit.x + 150 && posS.x <= posInit.x + 300 && posS.y >= posInit.y + 100 && posS.y <= posInit.y + 150 && showOptionChoice == 1)
                {
                    slotOkOptionMap = 4;
                    SDL_BlitSurface(slotOptionMapOk, NULL, ecran, &posSlotOptionChoice[2]);
    
                }
                else
                {
                    slotOkOptionMap = 0;
                }
    
    
    
    
    
    
                SDL_BlitSurface(slotQuitMap, NULL, ecran ,&posSlotQuitMap);
    
            }
            //------------------------------------------------------------------------------------ Map -----------------------------------------------------------------------------------------------
    
    
    
            //------------------------------------------------------------------------------------ Shop ----------------------------------------------------------------------------------------------
            i = 0;
            while (i != 6)
            {
                SDL_BlitSurface(slotShop[i], NULL, ecran, &posSlotShop[i]);
                i ++;
            }
            i = 0;
            while (i != 6)
            {
                if (posS.x >= posSlotShop[i].x && posS.x <= posSlotShop[i].x + 83 && posS.y >= posSlotShop[i].y && posS.y <= posSlotShop[i].y + 80)
                {
                    slotOkShop[i] = 1;
                    SDL_BlitSurface(slotShopOk[i], NULL, ecran, &posSlotShop[i]);
                }
                else
                {
                    slotOkShop[i] = 0;
                }
                i ++;
            }
            if (shopOpen == 1)
            {
    
            }
            if (shopOpen == 2)
            {
    
            }
            if (shopOpen == 3)
            {
    
            }
            if (shopOpen == 4)
            {
    
            }
            if (shopOpen == 5)
            {
    
            }
            if (shopOpen == 6)
            {
                i = menuInventory * 8;
                u = 0;
                b = 0;
                a = i + 8;
                while (i != a)
                {
                    u = slotItemInventory[i];
                    SDL_BlitSurface(slotInventory[u], NULL, ecran, &posSlotInventory[b]);
                    b ++;
                    i ++;
                }
    
                SDL_BlitSurface(slotSwitchInventory[0], NULL, ecran, &posSlotInventory[8]);
                SDL_BlitSurface(slotSwitchInventory[1], NULL, ecran, &posSlotInventory[9]);
                if (posS.x >= posSlotInventory[8].x && posS.x <= posSlotInventory[8].x + 250 && posS.y >= posSlotInventory[8].y && posS.y <= posSlotInventory[8].y + 116)
                {
                    slotInventorySwitchOk[0] = 1;
                    SDL_BlitSurface(slotSwitchInventoryOk[0], NULL, ecran, &posSlotInventory[8]);
                }
                else
                {
                    slotInventorySwitchOk[0] = 0;
                }
                if (posS.x >= posSlotInventory[9].x && posS.x <= posSlotInventory[9].x + 250 && posS.y >= posSlotInventory[9].y && posS.y <= posSlotInventory[9].y + 116)
                {
                    slotInventorySwitchOk[1] = 1;
                    SDL_BlitSurface(slotSwitchInventoryOk[1], NULL, ecran, &posSlotInventory[9]);
                }
                else
                {
                    slotInventorySwitchOk[1] = 0;
                }
    
            }
            //------------------------------------------------------------------------------------ Shop ----------------------------------------------------------------------------------------------
    
    
    
            //------------------------------------------------------------------------------------ Info ----------------------------------------------------------------------------------------------
            i = 0;
            while (i != 8)
            {
                SDL_BlitSurface(slotInfo[i], NULL, ecran, &posSlotInfo[i]);
                i ++;
            }
    
            sprintf(charPaper, "%d", paper);
            sprintf(charEnergy, "%d", energy);
            sprintf(charMaxEnergy, "/%d", maxEnergy);
            sprintf(charStone, "%d", stone);
            sprintf(charMaxStone, "/%d",maxStone);
            sprintf(charCoal, "%d", coal);
            sprintf(charMaxCoal, "/%d", maxCoal);
            sprintf(charIron, "%d", iron);
            sprintf(charMaxIron, "/%d", maxIron);
            sprintf(charGold, "%d", gold);
            sprintf(charMaxGold, "/%d", maxGold);
            sprintf(charDiamond, "%d", diamond);
            sprintf(charMaxDiamond, "/%d", maxDiamond);
            sprintf(charEmerald, "%d", emerald);
            sprintf(charMaxEmerald, "/%d", maxEmerald);
    
            textPaper = TTF_RenderText_Blended(police, charPaper, couleurNoir);
            textEnergy = TTF_RenderText_Blended(police, charEnergy, couleurNoir);
            textMaxEnergy = TTF_RenderText_Blended(police, charMaxEnergy, couleurNoir);
            textStone = TTF_RenderText_Blended(police, charStone, couleurNoir);
            textMaxStone = TTF_RenderText_Blended(police, charMaxStone, couleurNoir);
            textCoal = TTF_RenderText_Blended(police, charCoal, couleurNoir);
            textMaxCoal = TTF_RenderText_Blended(police, charMaxCoal, couleurNoir);
            textIron = TTF_RenderText_Blended(police, charIron, couleurNoir);
            textMaxIron = TTF_RenderText_Blended(police, charMaxIron, couleurNoir);
            textGold = TTF_RenderText_Blended(police, charGold, couleurNoir);
            textMaxGold = TTF_RenderText_Blended(police, charMaxGold, couleurNoir);
            textDiamond = TTF_RenderText_Blended(police, charDiamond, couleurNoir);
            textMaxDiamond = TTF_RenderText_Blended(police, charMaxDiamond, couleurNoir);
            textEmerald = TTF_RenderText_Blended(police, charEmerald, couleurNoir);
            textMaxEmerald = TTF_RenderText_Blended(police, charMaxEmerald, couleurNoir);
    
            SDL_BlitSurface(textPaper, NULL, ecran, &posTextInfo[0]);
            SDL_BlitSurface(textEnergy, NULL, ecran, &posTextInfo[1]);
            SDL_BlitSurface(textMaxEnergy, NULL, ecran, &posTextInfo[2]);
            SDL_BlitSurface(textStone, NULL, ecran, &posTextInfo[3]);
            SDL_BlitSurface(textMaxStone, NULL, ecran, &posTextInfo[4]);
            SDL_BlitSurface(textCoal, NULL, ecran, &posTextInfo[5]);
            SDL_BlitSurface(textMaxCoal, NULL, ecran, &posTextInfo[6]);
            SDL_BlitSurface(textIron, NULL, ecran, &posTextInfo[7]);
            SDL_BlitSurface(textMaxIron, NULL, ecran, &posTextInfo[8]);
            SDL_BlitSurface(textGold, NULL, ecran, &posTextInfo[9]);
            SDL_BlitSurface(textMaxGold, NULL, ecran, &posTextInfo[10]);
            SDL_BlitSurface(textDiamond, NULL, ecran, &posTextInfo[11]);
            SDL_BlitSurface(textMaxDiamond, NULL, ecran, &posTextInfo[12]);
            SDL_BlitSurface(textEmerald, NULL, ecran, &posTextInfo[13]);
            SDL_BlitSurface(textMaxEmerald, NULL, ecran, &posTextInfo[14]);
            //------------------------------------------------------------------------------------ Info ----------------------------------------------------------------------------------------------
    
    
            SDL_BlitSurface(slotMenu, NULL, ecran, &posSlotMenu);
    
    
    
    
    
            SDL_Flip(ecran);
        }
    
    
        SDL_FreeSurface(textPaper);
        SDL_FreeSurface(textEnergy);
        SDL_FreeSurface(textStone);
        SDL_FreeSurface(textCoal);
        SDL_FreeSurface(textIron);
        SDL_FreeSurface(textGold);
        SDL_FreeSurface(textDiamond);
        SDL_FreeSurface(textEmerald);
        SDL_FreeSurface(textMaxEnergy);
        SDL_FreeSurface(textMaxStone);
        SDL_FreeSurface(textMaxCoal);
        SDL_FreeSurface(textMaxIron);
        SDL_FreeSurface(textMaxGold);
        SDL_FreeSurface(textMaxDiamond);
        SDL_FreeSurface(textMaxEmerald);
    
        TTF_CloseFont(police);
        TTF_Quit();
    
    
        free = 0;
        while (free != 50)
        {
            SDL_FreeSurface(slotMap[free]);
            SDL_FreeSurface(slotMapOk[free]);
            SDL_FreeSurface(mapTheme[free]);
            SDL_FreeSurface(slotShop[free]);
            SDL_FreeSurface(slotShopOk[free]);
            SDL_FreeSurface(slotInfo[free]);
            SDL_FreeSurface(slotInventory[free]);
            SDL_FreeSurface(slotSwitchInventory[free]);
            SDL_FreeSurface(slotSwitchInventoryOk[free]);
            free ++;
        }
    
        SDL_FreeSurface(slotOptionMapOk);
        SDL_FreeSurface(slotOptionMapChoice);
        SDL_FreeSurface(slotOptionMap);
        SDL_FreeSurface(slotQuitMap);
        SDL_FreeSurface(slotMapLock);
        SDL_FreeSurface(slotMenu);
        SDL_FreeSurface(fond);
        SDL_Quit();
    
    
        EXIT_SUCCESS;
    }
    



    • Partager sur Facebook
    • Partager sur Twitter
    Ne pas se décourager !
      18 février 2017 à 22:14:20

      Salut,

      Tu peux préciser ce qui pose problème (tout le monde n’a pas envie d’aller voir une vidéo pour savoir quel est ton problème). Sinon, ton main est au moins 10 fois trop grand et il n’y a aucune vérification des fonctions à risques. J’ai juste regardé le code en gros, pour avoir plus de détail, règle déjà ce que je t’ai dit (en particulier, fais plus de fonctions), et explique nous le problème.

      • Partager sur Facebook
      • Partager sur Twitter
      Tutoriel Ruby - Bon tutoriel C - Tutoriel SDL 2 - Python avancé - Faîtes un zeste, devenez des zesteurs
        18 février 2017 à 22:36:23

        Daccord alors le problème c'est j'ai 2 SDL_Rect , posSlotMenu et posSlotQuitMap qui sont initialiser et qui se positionne la ou je leur est dit de ce mettre, mais quand j'ajoute qu'une seul ligne de code en particulier et bien leur positions change et devienne x = 0 et y = 0. Merci

        SDL_Rect posSlotMenu; // pos du bouton menu
        posSlotMenu.x = 1000;
        posSlotMenu.y = 0;
        
        SDL_Rect posSlotQuitMap; // pos du bouton pour quitter la map
        posSlotQuitMap.x = 475;
        posSlotQuitMap.y = 0;
        
        
        if (slotInventorySwitchOk[0] == 1)
                    {
                        if (menuInventory != 0)
                        {
                            menuInventory --;
                        }
                    }
                    if (slotInventorySwitchOk[1] == 1)
                    {
                        if (menuInventory != 2)
                        {
                            menuInventory ++; // cette ligne la
        
                        }
                    }
        


        Merci

        • Partager sur Facebook
        • Partager sur Twitter
        Ne pas se décourager !
          19 février 2017 à 1:23:07

          B'soir,

          ligne 361 et 362: accès hors tableau!

           Ps: yo@n a raison: ton code est très mal organisé!

          En plus tu as plein de fuites memoires à cause de ton rendu de texte!

          -
          Edité par breizhbugs 19 février 2017 à 9:49:32

          • Partager sur Facebook
          • Partager sur Twitter
          ** La doc, c'est comme le PQ: ça sert à se démerder tout seul **
            19 février 2017 à 10:00:29

            Merci beaucoup c’était ça !

            D’ailleur ceci est considérer comme des accès hors tableau ou pas ?

            free = 0;
                while (free != 50)
                {
                    SDL_FreeSurface(slotMap[free]);
                    SDL_FreeSurface(slotMapOk[free]);
                    SDL_FreeSurface(mapTheme[free]);
                    SDL_FreeSurface(slotShop[free]);
                    SDL_FreeSurface(slotShopOk[free]);
                    SDL_FreeSurface(slotInfo[free]);
                    SDL_FreeSurface(slotInventory[free]);
                    SDL_FreeSurface(slotSwitchInventory[free]);
                    SDL_FreeSurface(slotSwitchInventoryOk[free]);
                    free ++;
                }

            Est je sais que mon code est très mal organiser mais je ne voie pas comment utiliser des fonctions avec la SDL, car si je veut crée une fonction qui s'occupe juste d'afficher l'inventaire, et bien au moment de Blit j'ai le message d'erreur "ecran was not declared".

            Idem si je veut crée une fonction qui gèrent juste les events et bien c'est mais int comme "shopOpen was not declared".

            Mais merci beaucoup de m'avoir aider !

            EDIT: je ne voie pas ou se trouve les fuites de mémoires dans mon rendu texte peut tu est plus précis stp

            -
            Edité par Sachajoub 19 février 2017 à 14:14:36

            • Partager sur Facebook
            • Partager sur Twitter
            Ne pas se décourager !
              19 février 2017 à 19:56:30

              sachajoubert a écrit:

              D’ailleur ceci est considérer comme des accès hors tableau ou pas ?


              oui.

              sachajoubert a écrit:

              EDIT: je ne voie pas ou se trouve les fuites de mémoires dans mon rendu texte peut tu est plus précis stp

              sachajoubert a écrit:

              Bonsoir,

              merci de bien vouloir m'aider j'ai fait une courte vidéo sur le lien suivant pour vous montrez mon problème je trouve ça plus simple pour expliquer :

              https://www.youtube.com/watch?v=HxM25apNEyk&feature=youtu.be

              Mon code :

                  while (continuer != 1)
                  {
              	UpdateEvents(&in);
              ...
                      textPaper = TTF_RenderText_Blended(police, charPaper, couleurNoir);
                      textEnergy = TTF_RenderText_Blended(police, charEnergy, couleurNoir);
                      textMaxEnergy = TTF_RenderText_Blended(police, charMaxEnergy, couleurNoir);
                      textStone = TTF_RenderText_Blended(police, charStone, couleurNoir);
                      textMaxStone = TTF_RenderText_Blended(police, charMaxStone, couleurNoir);
                      textCoal = TTF_RenderText_Blended(police, charCoal, couleurNoir);
                      textMaxCoal = TTF_RenderText_Blended(police, charMaxCoal, couleurNoir);
                      textIron = TTF_RenderText_Blended(police, charIron, couleurNoir);
                      textMaxIron = TTF_RenderText_Blended(police, charMaxIron, couleurNoir);
                      textGold = TTF_RenderText_Blended(police, charGold, couleurNoir);
                      textMaxGold = TTF_RenderText_Blended(police, charMaxGold, couleurNoir);
                      textDiamond = TTF_RenderText_Blended(police, charDiamond, couleurNoir);
                      textMaxDiamond = TTF_RenderText_Blended(police, charMaxDiamond, couleurNoir);
                      textEmerald = TTF_RenderText_Blended(police, charEmerald, couleurNoir);
                      textMaxEmerald = TTF_RenderText_Blended(police, charMaxEmerald, couleurNoir);
              
                      SDL_BlitSurface(textPaper, NULL, ecran, &posTextInfo[0]);
                      SDL_BlitSurface(textEnergy, NULL, ecran, &posTextInfo[1]);
                      SDL_BlitSurface(textMaxEnergy, NULL, ecran, &posTextInfo[2]);
                      SDL_BlitSurface(textStone, NULL, ecran, &posTextInfo[3]);
                      SDL_BlitSurface(textMaxStone, NULL, ecran, &posTextInfo[4]);
                      SDL_BlitSurface(textCoal, NULL, ecran, &posTextInfo[5]);
                      SDL_BlitSurface(textMaxCoal, NULL, ecran, &posTextInfo[6]);
                      SDL_BlitSurface(textIron, NULL, ecran, &posTextInfo[7]);
                      SDL_BlitSurface(textMaxIron, NULL, ecran, &posTextInfo[8]);
                      SDL_BlitSurface(textGold, NULL, ecran, &posTextInfo[9]);
                      SDL_BlitSurface(textMaxGold, NULL, ecran, &posTextInfo[10]);
                      SDL_BlitSurface(textDiamond, NULL, ecran, &posTextInfo[11]);
                      SDL_BlitSurface(textMaxDiamond, NULL, ecran, &posTextInfo[12]);
                      SDL_BlitSurface(textEmerald, NULL, ecran, &posTextInfo[13]);
                      SDL_BlitSurface(textMaxEmerald, NULL, ecran, &posTextInfo[14]);
              ...
                      SDL_Flip(ecran);
                  }
              
              
                  SDL_FreeSurface(textPaper);
                  SDL_FreeSurface(textEnergy);
                  SDL_FreeSurface(textStone);
                  SDL_FreeSurface(textCoal);
                  SDL_FreeSurface(textIron);
                  SDL_FreeSurface(textGold);
                  SDL_FreeSurface(textDiamond);
                  SDL_FreeSurface(textEmerald);
                  SDL_FreeSurface(textMaxEnergy);
                  SDL_FreeSurface(textMaxStone);
                  SDL_FreeSurface(textMaxCoal);
                  SDL_FreeSurface(textMaxIron);
                  SDL_FreeSurface(textMaxGold);
                  SDL_FreeSurface(textMaxDiamond);
                  SDL_FreeSurface(textMaxEmerald);
              
                  
              



              TTFRenderText alloue une NOUVELLE surface à chaque appel, donc à chaque tour de boucle, TTFRenderText écrase le pointeurr de l'ancienne surface. Tu dois libérer les surfaces de texte dès que tu les a blittées, pas tout à la fin!

              (donc déplace les sdl_freesurface(tex...) juste après les sdl_blitsurface(text...) )

              -
              Edité par breizhbugs 19 février 2017 à 19:57:56

              • Partager sur Facebook
              • Partager sur Twitter
              ** La doc, c'est comme le PQ: ça sert à se démerder tout seul **
                19 février 2017 à 21:23:55

                Daccord merci pour tout tes conseil !

                Je les est tous appliqué mais mon programme RAM toujours, mais au moins il n'y a pas de bug juste un manque de FPS et je pense que ceci est du au faite que mon main est remplie a craqué, et que je n'est pas fait de fonctions.

                Merci ce sujet et résolue.

                • Partager sur Facebook
                • Partager sur Twitter
                Ne pas se décourager !

                Problème de SDL_Rect (je suppose ...)

                × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
                × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
                • Editeur
                • Markdown