Hardware Reference
In-Depth Information
return p
def wallV(p,os):
clear = True
for pix in range(0,pieMan,4) :
if screen.get_at((os,p[1]+pix)) == blue:
clear = False
return clear
def wallH(p,os):
clear = True
for pix in range(0,pieMan,4) :
if screen.get_at((p[0]+pix, os)) == blue:
clear = False
return clear
def wallHt2(p,ox,oy,r): #test for turning
clear = True
for pix in range(0,r,4) :
if screen.get_at((p[0]+pix+ox, p[1]+oy)) == blue:
clear = False
return clear
here are four functions here. he main one, makeStep , takes three parameters: he irst, p ,
is a list containing the X and Y coordinates of the plot position, and the others are the direc-
tion and how far you need to go in that direction. his function has diferent code depending
on the required direction, but the purpose of the code is the same. It is saying, “Is the space
in front of the sprite enough to move the required distance?”, and if so, it lets the sprite
move. If not, it pulls in the sprite one pixel at a time until it is up against the obstacle. When
that has been done the new position of the sprite is returned.
he three functions following this simply scan the pixels the required distance away to see if it is
clear, where clear means not blue, the colour of the walls. Note that the exact colour is speciied;
you could draw something that was only one bit diferent from the full blue you are looking for,
which would look identical, but you would be able to walk through it. Also, notice that it is the
screen layer that is being tested; there is nothing to stop you from testing the background layer
if you want to. In that way you could have an identical colour on the pills layer of the screen layer
that would not act as an obstacle. Note there is also a global variable called move that is set if a
step has been taken successfully, which is used later on for the ghost movements.
here is an additional test for directions 0 and 2 to cope with Pie Man exiting on one side of
the screen and entering on the other. In early computers this was a pure consequence of the
Search WWH ::




Custom Search