我一直在使用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)}
更多推荐
发布评论