vendredi 22 mai 2015

Can't get out of a loop- SDL2 C

i'm trying to create a random path by coloring cases of the SDL window, but it seems like my function can't get out of the loop, thus it gives me dancing shapes x) here's the code

#include<stdio.h>
#include<SDL2/SDL.h>
#include<stdlib.h>
#include<time.h>

#define N 0
#define S 2
#define W 3
#define E 1
void drawRectangle(int n, SDL_Renderer* renderer, int i, int j){
        SDL_Rect rectangle;
        SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
        rectangle.x = j*(WIDTH/n);
        rectangle.y = i*(WIDTH/n);
        rectangle.w = WIDTH/n;
        rectangle.h = WIDTH/n;
        SDL_RenderFillRect(renderer, &rectangle);
}
void create_path(int n,SDL_Renderer* renderer){
    int i,j,k;
    drawRectangle(n,renderer,0,1);
    drawRectangle(n,renderer,1,1);
    for(i=1;i<n;i++){
    for(j=0;j<n;j++){
        k=rand()%4;
                if(k==N){
                drawRectangle(n,renderer, i-1, j);

                }
               else if(k==E){
                   drawRectangle(n,renderer,i,j+1);

                }
           else if(k==S){
                drawRectangle(n,renderer,i+1,j);

                }
          else if(k==W){
                  drawRectangle(n,renderer,i,j-1);
                  }
    }
}
}

Thank you for your help !




Aucun commentaire:

Enregistrer un commentaire