[英]Tile Maze in SDL
I am trying to draw up a maze in accordance to me 2D array. 我试图按照我的2D阵列绘制一个迷宫。 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;
}
You never reset the x1
and x2
values. 您永远不会重置
x1
和x2
值。 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. 一旦到达行尾并为下一行增加
y1
, y2
,则x1和x2继续超过800。
The first for loop should include 第一个for循环应包括
int x1 = -40;
int x2 = 0;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.