Advertisement
Guest User

Untitled

a guest
Dec 13th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. // Figure out which direction the ogres are coming from.
  2.  
  3. while(true) {
  4. var enemy = hero.findNearestEnemy();
  5. if(enemy) {
  6. // Left: enemy.pos.x is less than hero.pos.x
  7. var isLeft = enemy.pos.x < hero.pos.x;
  8. // Above: enemy.pos.y is greater than hero.pos.y
  9. var isAbove = enemy.pos.y > hero.pos.y;
  10. // Right: enemy.pos.x is greater than hero.pos.x
  11. var isRight = enemy.pos.x > hero.pos.x;
  12. // Below: enemy.pos.y is less than hero.pos.y
  13. var isBelow = enemy.pos.y < hero.pos.y;
  14.  
  15. // If enemy isAbove and isLeft:
  16. // buildXY() a "fire-trap" at the X mark.
  17. if(isAbove && isLeft) {
  18. hero.buildXY("fire-trap", 40 - 20, 34 + 17);
  19. }
  20. // If enemy isAbove and isRight:
  21. // buildXY() a "fire-trap" at the X mark.
  22. if(isAbove && isRight) {
  23. hero.buildXY("fire-trap", 60, 51);
  24. }
  25. // If enemy isBelow and isLeft:
  26. // buildXY() a "fire-trap" at the X mark.
  27. if(isBelow && isLeft) {
  28. hero.buildXY("fire-trap", 20, 17);
  29. }
  30. // If enemy isBelow and isRight:
  31. // buildXY() a "fire-trap" at the X mark.
  32. if(isBelow && isRight) {
  33. hero.buildXY("fire-trap", 60, 17);
  34. }
  35. hero.moveXY(40, 34);
  36. } else {
  37. hero.moveXY(40, 34);
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement