TheAngryBr1t
TheAngryBr1t

Reputation: 19

Tile Maze in SDL

I am trying to draw up a maze in accordance to me 2D array. It only prints on the top of the window and no where else.

#include "SDL.h"
#include "SDL_gfxPrimitives.h"
#include <conio.h>

int main( int argc, char* args[] )
{

char caMaze[20][20] = { //the array for the maze
{"###################"},
{"#+#####  #        #"},
{"#    ## ###########"},
{"## #    #####     #"},
{"## ## ####### #####"},
{"## ## ####### #####"},
{"## ##     #      ##"},
{"##   ##     ## ####"},
{"########### ## ####"},
{"####        ## ####"},
{"#### ### ##### ####"},
{"#  #  ## ####  ####"},
{"## ## ##  ### #####"},
{"## ##  ##     #####"},
{"## ### #### #######"},
{"##   #    #  ######"},
{"#### #### #########"},
{"#########        =#"},
{"###################"},
};

int x1 = -40;
int x2 = 0;
int y1 = -40;
int y2 = 0;

SDL_Surface *screen = NULL;

SDL_Init(SDL_INIT_EVERYTHING);

screen = SDL_SetVideoMode(800, 600, 32, SDL_SWSURFACE);
int loop = 0;


    for(int i = 0; i < 20; i++)
    {
        y1 += 40;
        y2 += 40;
        for(int j = 0; j< 20; j++)
        {
            x1 += 40;
            x2 += 40;
            if( caMaze[i][j] == '#')
            {
                boxRGBA(screen, x1, y1, x2, y2, 255, 0, 0, 255);
            }
            if( caMaze[i][j] ==  ' ')
            {
                boxRGBA(screen, x1, y1, x2, y2, 255, 0, 255, 255);
            }

            if(caMaze[i][j] == '+')
            {
                boxRGBA(screen, x1, y1, x2, y2, 0, 0, 255, 255);
            }

            if (caMaze[i][j] == '=')
            {
                boxRGBA(screen, x1, y1, x2, y2, 0, 255, 0, 255);
            }
        }

    }

    if(SDL_Flip(screen) == -1)
    {
        return 1;
    }


getch();
SDL_Quit();
return 0;
}

Upvotes: 0

Views: 704

Answers (1)

user1944441
user1944441

Reputation:

You never reset the x1 and x2 values. Once you reach the end of the row and increase y1,y2 for the next row, your x1 and x2 continue to go over 800.

The first for loop should include

int x1 = -40;
int x2 = 0;

Upvotes: 0

Related Questions