def CFW(D):
for a in WL:
if D == 0:CFW是一个函数,如果玩家正在触摸一面墙(D代表方向),则返回WL是一个包含墙的坐标数组的数组,但是它只会读取WL中的第一个数组,而不会迭代到下一个数组,所以它只会在玩家触摸WL中的第一组坐标时返回。有人能告诉我我哪里做错了吗?下面是整个函数:
def CFW(D):
for a in WL:
if D == 0:
if a[0] > (plyposx-30) and a[0] < (plyposx+30) and plyposy == a[1]-32:
return 1 # 1 = is touching
else:
return 0 # 0 = is not touching
elif D == 2:
if a[0] > (plyposx-30) and a[0] < (plyposx+30) and plyposy == a[1]+32:
return 1
else:
return 0
elif D == 1:
if a[1] > (plyposy-30) and a[1] < (plyposy+30) and plyposx == a[0]+32:
return 1
else:
return 0
elif D == 3:
if a[1] > (plyposy-30) and a[1] < (plyposy+30) and plyposx == a[0]-32:
return 1
else:
return 0我将代码更改为
def CFW(D):
for c in xrange(0,1):
a = WL[c]
if D == 0: 但是,它仍然不读取第二个数组。我定义WL的方式是这样的:
WL = [[32,32],[64,32]]发布于 2014-01-24 01:39:06
乍一看,我以为这就是你想要做的:
def CFW(D):
for a in WL:
if D == 0:
if a[0] > (plyposx-30) and a[0] < (plyposx+30) and plyposy == a[1]-32:
return 1 # 1 = is touching
elif D == 2:
if a[0] > (plyposx-30) and a[0] < (plyposx+30) and plyposy == a[1]+32:
return 1
elif D == 1:
if a[1] > (plyposy-30) and a[1] < (plyposy+30) and plyposx == a[0]+32:
return 1
elif D == 3:
if a[1] > (plyposy-30) and a[1] < (plyposy+30) and plyposx == a[0]-32:
return 1
return 0 # 0 = is not touching值得注意的是,range和xrange类支持in操作:
>>> 5 in xrange(1, 10)
True
>>> 100 in xrange(1, 10)
Falsehttps://stackoverflow.com/questions/21314997
复制相似问题