PGU Tiles碰撞检测(PGU Tiles collision detection)

编程入门 行业动态 更新时间:2024-10-26 02:27:19
PGU Tiles碰撞检测(PGU Tiles collision detection)

我一直在使用PGU(Phil的Pygame Utilities)。 它有一个名为tdata的字典,它在加载tile时作为参数传递

tdata = {tileno:(agroup,hit_handler,config)}

我正在制作一个pacman克隆,其中我有两组:玩家和鬼,我想用相同类型的瓦片进行碰撞检测。

例如,如果tile no为2,我希望这个tile具有agroups作为player和ghost。 我尝试过以下操作:

tdata = {0x02 :('player',tile_hit_1,config),0x02:('ghost',tile_hit_2,config)}

但是,在这样做时,它只对幽灵进行碰撞检测,而不是玩家。

关于如何使用相同类型的磁贴对玩家和幽灵进行碰撞检测的任何想法?

I've been using PGU(Phil's Pygame Utilities) for a while. It has a dictionary called tdata, which is passed as an argument while loading tiles

tdata = { tileno:(agroup, hit_handler, config)}

I'm making a pacman clone in which I have 2 groups : player and ghost, for which I want to collision detection with the same type of tile.

For example, if the tile no is 2, I want this tile to have agroups as both player and ghost. I tried doing the following:

tdata = {0x02 :('player', tile_hit_1, config), 0x02 : ('ghost', tile_hit_2, config)}

However, on doing this, it only gives collision detection for ghost, not the player.

Any ideas on how I can do collision detection for both the player and the ghost with the same type of tile?

最满意答案

我已经查看了源代码: http : //code.google.com/p/pgu/

在vid.py( http://code.google.com/p/pgu/source/browse/trunk/pgu/vid.py )中,有用于加载tdata信息的代码。

第300行: def tga_load_tiles(self,fname,size,tdata={}):

然后在第324和325行:

agroups,hit,config = tdata[n] tile.agroups = self.string2groups(agroups)

所以看一下从第369行开始的string2groups的定义.agroups参数是一个用逗号分隔的字符串。 所以我认为你可以在字符串中放置多个组的名称。

尝试:

tdata = {0x02: ('player,ghost', tile_hit, config)}

I've had a look at the source code at: http://code.google.com/p/pgu/

In vid.py (http://code.google.com/p/pgu/source/browse/trunk/pgu/vid.py) there is code for loading tdata information.

Line 300: def tga_load_tiles(self,fname,size,tdata={}):

Then on lines 324 and 325:

agroups,hit,config = tdata[n] tile.agroups = self.string2groups(agroups)

So looking at the definiton of string2groups which begins on line 369. The agroups parameter is a string which is split on commas. So I think you can put the name of more than one group in the string.

Try:

tdata = {0x02: ('player,ghost', tile_hit, config)}

更多推荐

本文发布于:2023-07-27 17:54:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1293615.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Tiles   PGU   detection   collision

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!