0
def CFW(D):
for a in WL:
if D == 0:
CFW是返回,如果播放器接觸的壁(d爲的方向) WL是包含壁的座標數組的數組的函數,然而它會只讀取WL中的第一個數組,而不是迭代到下一個數組,因此只有在玩家正在觸摸WL中的第一組座標時纔會返回。誰能告訴我我做錯了什麼? 這裏是整個函數:For循環只讀取陣列的第一項
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]]
'WL'長什麼樣子? –
WL = [[32,32],[64,32]] – user2883136
假設D總是等於0,1,2或3,for循環中的每個代碼路徑都會返回。 – Matt