Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C SDL中的瓦片迷宫_C_Sdl_Maze - Fatal编程技术网

C SDL中的瓦片迷宫

C SDL中的瓦片迷宫,c,sdl,maze,C,Sdl,Maze,我正试图根据我的2D阵列绘制一个迷宫。它只在窗口顶部打印,其他地方不打印 #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 {"###################"}, {"#+##### # #"}, {"

我正试图根据我的2D阵列绘制一个迷宫。它只在窗口顶部打印,其他地方不打印

#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;
}
#包括“SDL.h”
#包括“SDL_gfexperiments.h”
#包括
int main(int argc,char*args[]
{
char caMaze[20][20]={//迷宫的数组
{"###################"},
{"#+#####  #        #"},
{"#    ## ###########"},
{"## #    #####     #"},
{"## ## ####### #####"},
{"## ## ####### #####"},
{"## ##     #      ##"},
{"##   ##     ## ####"},
{"########### ## ####"},
{"####        ## ####"},
{"#### ### ##### ####"},
{"#  #  ## ####  ####"},
{"## ## ##  ### #####"},
{"## ##  ##     #####"},
{"## ### #### #######"},
{"##   #    #  ######"},
{"#### #### #########"},
{"#########        =#"},
{"###################"},
};
int-x1=-40;
int x2=0;
int y1=-40;
int y2=0;
SDL_表面*屏幕=空;
SDL_Init(SDL_Init_EVERYTHING);
屏幕=SDL_设置视频模式(800、600、32、SDL_表面);
int循环=0;
对于(int i=0;i<20;i++)
{
y1+=40;
y2+=40;
对于(int j=0;j<20;j++)
{
x1+=40;
x2+=40;
if(caMaze[i][j]='#')
{
boxRGBA(屏幕,x1、y1、x2、y2、255、0、0、255);
}
if(caMaze[i][j]='')
{
boxRGBA(屏幕,x1、y1、x2、y2、255、0、255、255);
}
if(caMaze[i][j]='+')
{
boxRGBA(屏幕,x1、y1、x2、y2、0、0、255、255);
}
if(caMaze[i][j]='='=')
{
boxRGBA(屏幕,x1、y1、x2、y2、0、255、0、255);
}
}
}
如果(SDL_翻转(屏幕)=-1)
{
返回1;
}
getch();
SDL_退出();
返回0;
}

您从未重置
x1
x2
值。一旦到达行的末尾并增加下一行的
y1
y2
,x1和x2继续超过800

第一个for循环应该包括

int x1 = -40;
int x2 = 0;

屏幕截图在这里会很有帮助。这是怎么回事?您使用的是SDL,请使用SDL输入例程。@genpfault OP使用的是
#include
和+getch()来查看屏幕,我看不出有什么问题。@genpfault就是为了在我急于查看绘图例程为什么不起作用时加上一个“控制台说我能行之前不要结束”。它将被删除。