制作pacman有些问题? [英] Having some issues with making pacman?

查看:128
本文介绍了制作pacman有些问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑:完全忘了提到我用Java编码

Totally forgot to mention I'm coding in Java

我真的很难制作某种检测系统或某种方法来制作我的pacman精灵/角色在游戏中顺利通过我的棋盘。我没有让它成为一张图片。

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.

推荐答案

存储旧学校游戏板的典型方法是使用 char int < a href =http://en.wikipedia.org/wiki/Multidimensional_array#Multi-dimensional_arrays =nofollow noreferrer>多维数组。使用 Matt优秀的小图形,您可以看到有21个董事会中21个方块:

A typical approach to storing "old school" game boards is to use a char or int multidimensional array. Using Matt's excellent little graphic you can see there are 21 by 21 squares in the board:

int board[21][21] = {{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, 
                     {1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1},
                     {1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1},
                     /* ... and so on, for all 21 lines .. */                      }};

您为墙壁和路径选择的数字并不重要。 路径位置最初包含包含点的代码。当paccy消耗这些点时,将新值存储到该位置的板中以指示该点已被消耗但它仍然是路径方块。对于墙,马特推荐 -1 0 表示没有点, 1 换一个点 - 这是一个非常好的计划,因为它让你的墙碰撞程序只是寻找

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, and 1 for a dot -- that's a pretty plan, as it lets your "wall collision" routines simply look for

if (board[pac.x][pac.y] > 0) {
    /* still in bounds */
} else {
    /* collided against a wall */
}

缺点是 -1 在你的数组初始化程序中看起来更尴尬。

The downside is the -1 is more awkward looking in your array initializer.

如果这是在C中完成的话,使用 char很容易改进这个board [21] [21] 而不是 int board [21] [21] 并将游戏板存储为C字符串:

If this were done in C, it'd be easy enough to "improve" this using char board[21][21] instead of int board[21][21] and store the game board as a C string:

char board[21][21] = " XXXXXXXXXXXXXXXXXXX "
                     " X        X        X "
                     " X XX XXX X XXX XX X "
                     " X                 X "
                     " X XX X XXXXX X XX X "
                     " X    X   X   X    X "
                     " XXXX XXX X XXX XXXX "
                     "    X X       X X    "
                     "XXXXX X XXXXX X XXXXX"
                     "        X   X        "
                     "XXXXX X XXXXX X XXXXX"
                     "    X X       X X    "
                     " XXXX X XXXXX X XXXX "
                     " X        X        X "
                     " X XX XXX X XXX XX X "
                     " X  X           X  X "
                     " XX X X XXXXX X X XX "
                     " X    X   X   X    X "
                     " X XXXXXX X XXXXXX X "
                     " X                 X "
                     " XXXXXXXXXXXXXXXXXXX";

这在源代码中更容易阅读,占用更少的内存和墙碰撞例程可以看起来像这样:

This is far easier to read in the source code, takes less memory, and your wall-collision routines can look like this:

if (board[pac.x][pac.y] == 'X') {
    /* collided with a wall */
} else {
    /* still in bounds */
}

(虽然编译器将在字符串末尾插入的尾随 NUL 意味着右下方永远不能用于途径墙 - 可以通过一点点努力来解决这个问题,但它并不是那么美好。)

(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.)

我不记得有足够的Java来用Java做这项工作 - 但我相信如果这看起来足够引人注目,你可以弄明白。

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.

这篇关于制作pacman有些问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆