制作 pacman 时遇到一些问题?
编辑:完全忘记提及我正在用 Java 进行编码,
我真的很难制作某种检测系统或某种方法来使我的 pacman 精灵/角色在游戏中的棋盘上顺利移动。我没有把黑板做成图像。
我首先尝试过颜色检测,效果最好,但一点也不平滑,而且相当不稳定。
然后我尝试手动输入不允许输入的位置坐标。这也没有那么顺利。
我目前正在尝试让程序使用颜色检测并检查一个单独的看不见的板,看看我是否仍在路上。这是迄今为止最失败的。这似乎是最聪明的,但角落太多,很难通过调整图像来修复。
我想知道你们会建议什么方法来完成这样的任务。
Edit: Totally forgot to mention I'm coding in Java
I'm having a real hard time making some kind of detection system or some way to make my pacman sprite/character move smoothly through my board in the game. I did not make the board it's a image.
I had tried colour detection first which worked the best yet was not smooth at all and pretty choppy.
I then tried to manual input coordinates of location not allowed to be entered. This also did not work out so well.
I'm currently trying now to have the program use colour detection and check a separate unseen board to see if I'm still on the path. This has failed by far the most. It seems like it would be the smartest but the corners are just alful and hard to fix by adjusting the images.
I'm wondering what method you guys would suggest for such a task.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
存储“老式”游戏板的典型方法是使用
char
或int
多维数组。使用 Matt 出色的小图,您可以看到有 21 个棋盘上有 21 个方格:您为墙壁和路径选择哪个数字并不重要。 “路径”位置最初包含“包含点”的代码。当 paccy 消耗掉这些点时,将一个新值存储到棋盘中的位置,以指示该点已被消耗,但它仍然是一个路径方块。 Matt 建议使用
-1
表示墙壁,0
表示无点,1
表示有点 - 这是一个很好的计划,因为它可以让您的“墙碰撞”例程只是简单地查找。缺点是
-1
在数组初始值设定项中看起来更尴尬。如果这是用 C 语言完成的,那么使用
char board[21][21]
而不是int board[21][21]
来“改进”这一点就很容易了> 并将游戏板存储为 C 字符串:这在源代码中更容易阅读,占用的内存更少,并且您的墙壁碰撞例程可以如下所示:(
尽管尾部的
NUL
编译器将在末尾插入字符串意味着右下角的正方形永远不能用于路径或墙——多一点努力可以解决这个问题,但它并不那么漂亮。)我不记得了足够的 Java 可以在 Java 中完成这项工作——但我相信如果这看起来足够引人注目的话,你一定能想出一些办法。
A typical approach to storing "old school" game boards is to use a
char
orint
multidimensional array. Using Matt's excellent little graphic you can see there are 21 by 21 squares in the board:It doesn't really matter which numbers you pick for walls and pathways. The "pathway" positions initially contain a code for "contains a dot". As paccy consumes the dots, store a new value into the board at the position to indicate that the dot has been consumed but it is still a pathway square. Matt recommended
-1
for walls,0
for no dot, and1
for a dot -- that's a pretty plan, as it lets your "wall collision" routines simply look forThe downside is the
-1
is more awkward looking in your array initializer.If this were done in C, it'd be easy enough to "improve" this using
char board[21][21]
instead ofint board[21][21]
and store the game board as a C string:This is far easier to read in the source code, takes less memory, and your wall-collision routines can look like this:
(Though the trailing
NUL
that the compiler will insert at the end of the string means that lower-right-hand square can never be used for pathway or wall -- a little more effort can work around that, but it isn't as beautiful.)I don't remember enough Java to make this work in Java -- but I'm sure you can figure out something if this looks compelling enough.