Guest User

Untitled

a guest
Feb 18th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. # get the distance between the monster and player
  2. dist = math.hypot(pX - mX, pY - mY)
  3.  
  4. if dist > 1.5 and dist < 10:
  5.  
  6. # make an 'array' grid to store updated distances in
  7. goto = np.full((3, 3), 10, dtype=float)
  8.  
  9. # if each position in the array passes a
  10. # collision check, add each new distance
  11.  
  12. if collisionCheck(mID, (mX-1), (mY-1), mMap) == 0:
  13. goto[0][0] = round(math.hypot(pX - (mX-1), pY - (mY-1)), 1)
  14.  
  15. if collisionCheck(mID, mX, (mY-1), mMap) == 0:
  16. goto[0][1] = round(math.hypot(pX - mX, pY - (mY-1)), 1)
  17.  
  18. if collisionCheck(mID, (mX+1), (mY-1), mMap) == 0:
  19. goto[0][2] = round(math.hypot(pX - (mX+1), pY - (mY-1)), 1)
  20.  
  21. if collisionCheck(mID, (mX-1), mY, mMap) == 0:
  22. goto[1][0] = round(math.hypot(pX - (mX-1), pY - mY), 1)
  23.  
  24. # goto[1][1] is skipped since that is the monsters current position
  25.  
  26. if collisionCheck(mID, (mX+1), mY, mMap) == 0:
  27. goto[1][2] = round(math.hypot(pX - (mX+1), pY - mY), 1)
  28.  
  29. if collisionCheck(mID, (mX-1), (mY+1), mMap) == 0:
  30. goto[2][0] = round(math.hypot(pX - (mX-1), pY - (mY+1)), 1)
  31.  
  32. if collisionCheck(mID, mX, (mY+1), mMap) == 0:
  33. goto[2][1] = round(math.hypot(pX - mX, pY - (mY+1)), 1)
  34.  
  35. if collisionCheck(mID, (mX+1), (mY+1), mMap) == 0:
  36. goto[2][2] = round(math.hypot(pX - (mX+1), pY - (mY+1)), 1)
  37.  
  38. # get the lowest distance, and its key
  39. lowest = goto.min()
  40. lowestKey = goto.argmin()
  41.  
  42. # if the lowest distance is lower than monsters current position, move
  43.  
  44. if lowest < dist:
  45. if lowestKey == 0:
  46. newX = mX - 1
  47. newY = mY - 1
  48.  
  49. if lowestKey == 1:
  50. newY = mY - 1
  51.  
  52. if lowestKey == 2:
  53. newX = mX + 1
  54. newY = mY - 1
  55.  
  56. if lowestKey == 3:
  57. newX = mX - 1
  58.  
  59. if lowestKey == 5:
  60. newX = mX + 1
  61.  
  62. if lowestKey == 6:
  63. newY = mY + 1
  64. newX = mX - 1
  65.  
  66. if lowestKey == 7:
  67. newY = mY + 1
  68.  
  69. if lowestKey == 8:
  70. newX = mX + 1
  71. newY = mY + 1
Add Comment
Please, Sign In to add comment