android迷宫图像生成,Android - 绘制一个迷宫,以平滑的角色移动的画布

我目前正在创建一个基于Tile的游戏,它基本上使用2套布尔值数组绘制一个迷宫,以确定每个墙壁需要绘制的位置。Android - 绘制一个迷宫,以平滑的角色移动的画布

我有这个所有的工作,因为它应该只有一个迷宫的5 x 5部分被绘制(总体迷宫大小是30 x 30)。然而,我遇到的问题是当我移动角色时,整个屏幕跳跃,这是由于迷宫的下一部分正在绘制,以保持5 x 5纵横比。我尝试了各种不同的事情,试图让这个运行顺利,但似乎无法做到这一点。

有人可以建议或指导我一些链接/例子,以便我可以让迷宫和人物动作都顺利发生。下面是一些基本的代码,用于说明当前绘制迷宫的主循环以及它为了绘制墙壁而引用的2个布尔数组。

// THE CODE TO DRAW THE MAZE AND ITS WALLS

for(int i = 0; i < 5; i++)

{

for(int j = 0; j < 5; j++)

{

float x = j * totalCellWidth;

float y = i * totalCellHeight;

if(currentY != 0)

indexY = i + currentY - 1;

else

indexY = i + currentY;

if(currentX != 0)

indexX = j + currentX - 1;

else

indexX = j + currentX;

// Draw Verticle line (y axis)

if (indexY < vLength && indexX < vLines[indexY].length && vLines[indexY][indexX])

{

RectOuterBackground.set((int)x + (int)cellWidth, (int)y, (int)x + (int)cellWidth + 15, (int)y + (int)cellHeight + 15);

canvas.drawBitmap(walls, null, RectOuterBackground, null);

}

// Draws Horizontal lines (x axis)

if (indexY < hLength && indexX < hLines[indexY].length && hLines[indexY][indexX])

{

RectOuterBackground.set((int)x, (int)y + (int)cellHeight,(int)x + (int)cellWidth + 15,(int)y + (int)cellHeight + 15);

canvas.drawBitmap(walls, null, RectOuterBackground, null);

}

}

}

// THE 2 BOOLEAN ARRAYS THE FORLOOP REFERENCES

boolean[][] vLines = new boolean[][]{

{true ,true ,true ,true ,true ,true ,true ,true ,true ,true ,true },

{true ,true ,true ,true ,true ,true ,true ,true ,true ,true ,true },

{true ,true ,true ,false,false,false,true ,false,false,true ,true },

{true ,true ,true ,false,false,true ,false,true ,true ,true ,true },

{true ,true ,false,true ,false,false,true ,false,false,true ,true },

{true ,true ,false,true ,true ,false,false,false,true ,true ,true },

{true ,true ,true ,false,false,false,true ,true ,false,true ,true },

{true ,true ,false,true ,false,false,true ,false,false,true ,true },

{true ,true ,false,true ,true ,true ,true ,true ,false,true ,true },

{true ,true ,false,false,false,true ,false,false,false,true ,true },

{true ,true ,true ,true ,true ,true ,true ,true ,true ,true ,true },

{true ,true ,true ,true ,true ,true ,true ,true ,true ,true ,true }

};

boolean[][] hLines = new boolean[][]{

{true ,true ,true ,true ,true ,true ,true ,true ,true ,true ,true ,true },

{true ,true ,true ,true ,true ,true ,true ,true ,true ,true ,true ,true },

{true ,true ,false,false,true ,true ,false,false,true ,false,true ,true },

{true ,true ,false,false,true ,true ,false,true ,false,false,true ,true },

{true ,true ,true ,true ,false,true ,true ,false,true ,true ,true ,true },

{true ,true ,false,false,true ,false,true ,true ,false,false,true ,true },

{true ,true ,false,true ,true ,true ,true ,false,true ,true ,true ,true },

{true ,true ,true ,false,false,true ,false,false,true ,false,true ,true },

{true ,true ,false,true ,false,false,false,true ,false,true ,true ,true },

{true ,true ,true ,true ,true ,true ,true ,true ,true ,true ,true ,true },

{true ,true ,true ,true ,true ,true ,true ,true ,true ,true ,true ,true }

};

我愿意完全地重新编写的代码段,如果我能得到它顺利地画,但有尝试了几种不同的varations不能让它顺利,我总有跳。

我试图让它与canvas翻译一起工作,通过绘制whoel迷宫,然后将其缩放以便只显示5 x 5,然后简单地使用翻译来移动缩放部分,同时保持字符在屏幕的中心,在那里运动平稳。但是,我无法让翻译顺利进行。

+0

您是否愿意使用第三方游戏引擎(库),还是只想使用Android库解决此问题? –

+0

我没有问题使用第三方库,只要它适合我目前的布局,你有什么想法? –

+0

向我们展示您的游戏循环类/方法。你在主线程还是自己的线程上运行? –

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我可以为您介绍一种使用 Python 绘制迷宫地图的方法。 首先,我们需要准备一个迷宫地图的数据结构,可以使用二维数组来表示迷宫地图。其中,0 表示可以通过的通道,1 表示障碍物或墙壁。例如,以下是一个 5x5 的迷宫地图: ```python maze = [[0, 1, 0, 0, 0], [0, 1, 0, 1, 0], [0, 0, 0, 0, 0], [0, 1, 1, 1, 0], [0, 0, 0, 1, 0]] ``` 接下来,我们可以使用 Python 的 turtle 模块来绘制迷宫地图。turtle 模块是 Python 自带的一个图形库,可以用来绘制各种图形,包括线条、图形等。 以下是一个使用 turtle 模块绘制迷宫地图的示例代码: ```python import turtle # 定义迷宫地图 maze = [[0, 1, 0, 0, 0], [0, 1, 0, 1, 0], [0, 0, 0, 0, 0], [0, 1, 1, 1, 0], [0, 0, 0, 1, 0]] # 定义画布和画笔 screen = turtle.Screen() pen = turtle.Turtle() # 定义每个格子的大小 CELL_SIZE = 20 # 绘制迷宫地图 def draw_maze(maze): screen.tracer(False) for i in range(len(maze)): for j in range(len(maze[0])): if maze[i][j] == 1: x = j * CELL_SIZE y = i * CELL_SIZE pen.penup() pen.goto(x, y) pen.pendown() pen.setheading(0) pen.forward(CELL_SIZE) pen.setheading(90) pen.forward(CELL_SIZE) pen.setheading(180) pen.forward(CELL_SIZE) pen.setheading(270) pen.forward(CELL_SIZE) screen.tracer(True) # 设置画笔颜色和速度 pen.color('black') pen.speed(0) # 绘制迷宫地图 draw_maze(maze) # 等待用户关闭画布 screen.mainloop() ``` 上述代码中,我们定义了一个 `draw_maze` 函数来绘制迷宫地图。在函数中,我们使用 turtle 模块来绘制每个格子的四条边,形成一个完整的方格。然后,我们在主函数中调用 `draw_maze` 函数来绘制迷宫地图。 您可以将以上代码复制到 Python 环境中运行,即可看到绘制迷宫地图
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值