Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # get the distance between the monster and player
- dist = math.hypot(pX - mX, pY - mY)
- if dist > 1.5 and dist < 10:
- # make an 'array' grid to store updated distances in
- goto = np.full((3, 3), 10, dtype=float)
- # if each position in the array passes a
- # collision check, add each new distance
- if collisionCheck(mID, (mX-1), (mY-1), mMap) == 0:
- goto[0][0] = round(math.hypot(pX - (mX-1), pY - (mY-1)), 1)
- if collisionCheck(mID, mX, (mY-1), mMap) == 0:
- goto[0][1] = round(math.hypot(pX - mX, pY - (mY-1)), 1)
- if collisionCheck(mID, (mX+1), (mY-1), mMap) == 0:
- goto[0][2] = round(math.hypot(pX - (mX+1), pY - (mY-1)), 1)
- if collisionCheck(mID, (mX-1), mY, mMap) == 0:
- goto[1][0] = round(math.hypot(pX - (mX-1), pY - mY), 1)
- # goto[1][1] is skipped since that is the monsters current position
- if collisionCheck(mID, (mX+1), mY, mMap) == 0:
- goto[1][2] = round(math.hypot(pX - (mX+1), pY - mY), 1)
- if collisionCheck(mID, (mX-1), (mY+1), mMap) == 0:
- goto[2][0] = round(math.hypot(pX - (mX-1), pY - (mY+1)), 1)
- if collisionCheck(mID, mX, (mY+1), mMap) == 0:
- goto[2][1] = round(math.hypot(pX - mX, pY - (mY+1)), 1)
- if collisionCheck(mID, (mX+1), (mY+1), mMap) == 0:
- goto[2][2] = round(math.hypot(pX - (mX+1), pY - (mY+1)), 1)
- # get the lowest distance, and its key
- lowest = goto.min()
- lowestKey = goto.argmin()
- # if the lowest distance is lower than monsters current position, move
- if lowest < dist:
- if lowestKey == 0:
- newX = mX - 1
- newY = mY - 1
- if lowestKey == 1:
- newY = mY - 1
- if lowestKey == 2:
- newX = mX + 1
- newY = mY - 1
- if lowestKey == 3:
- newX = mX - 1
- if lowestKey == 5:
- newX = mX + 1
- if lowestKey == 6:
- newY = mY + 1
- newX = mX - 1
- if lowestKey == 7:
- newY = mY + 1
- if lowestKey == 8:
- newX = mX + 1
- newY = mY + 1
Add Comment
Please, Sign In to add comment