擅长:python、mysql、java
<p>正如大卫·杰伊·布雷迪所解释的,解决方案就在这里。你知道吗</p>
<h2>与墙壁相撞</h2>
<pre><code> #pdb.set_trace() # Debugging
for blockRect in wall:
if rectGhost.colliderect(blockRect):
while 1:# Cycle that solve the problem
if self._direction == LEFT:
rectGhost.left = blockRect.right
self._direction = random.choice([RIGHT, UP, DOWN])
break
if self._direction == RIGHT:
rectGhost.right = blockRect.left
self._direction = random.choice([LEFT, UP, DOWN]
break
if self._direction == UP:
rectGhost.top = blockRect.bottom
self._direction = random.choice([LEFT, RIGHT, DOWN]
break
if self._direction == DOWN:
rectGhost.bottom = blockRect.top
self._direction = random.choice([LEFT, RIGHT, UP])
break
</code></pre>