Guest User

Untitled

a guest
Sep 11th, 2019
100
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*************
  2. * ambush.js *
  3. *************
  4. *
  5. * Oh. Oh, I see. This wasn't quite part of the plan.
  6. *
  7. * Looks like they won't let you take the Algorithm
  8. * without a fight. You'll need to carefully weave your
  9. * way through the guard drones.
  10. *
  11. * Well, time to improvise. Let's mess with their programming
  12. * a little, shall we?
  13. */
  14.  
  15. function startLevel(map) {
  16. function moveToward(obj, type) {
  17. var target = obj.findNearest(type);
  18. var leftDist = obj.getX() - target.x;
  19. var upDist = obj.getY() - target.y;
  20.  
  21. var direction;
  22. if (upDist == 0 && leftDist == 0) {
  23. return;
  24. } if (upDist > 0 && upDist >= leftDist) {
  25. direction = 'up';
  26. } else if (upDist < 0 && upDist < leftDist) {
  27. direction = 'down';
  28. } else if (leftDist > 0 && leftDist >= upDist) {
  29. direction = 'left';
  30. } else {
  31. direction = 'right';
  32. }
  33.  
  34. if (obj.canMove(direction)) {
  35. obj.move(direction);
  36. }
  37. }
  38.  
  39. map.defineObject('attackDrone', {
  40. 'type': 'dynamic',
  41. 'symbol': 'd',
  42. 'color': 'red',
  43. 'onCollision': function (player) {
  44. player.killedBy('an attack drone');
  45. },
  46. 'behavior': function (me) {
  47. if(me.getY() != 13){
  48. if (me.canMove("down")) {
  49. me.move("down");
  50. }
  51. else {
  52. me.move("left");
  53. }
  54. }
  55. }
  56. });
  57.  
  58. map.defineObject('reinforcementDrone', {
  59. 'type': 'dynamic',
  60. 'symbol': 'd',
  61. 'color': 'yellow',
  62. 'onCollision': function (player) {
  63. player.killedBy('a reinforcement drone');
  64. },
  65. 'behavior': function (me) {
  66.  
  67. }
  68. });
  69.  
  70. map.defineObject('defenseDrone', {
  71. 'type': 'dynamic',
  72. 'symbol': 'd',
  73. 'color': 'green',
  74. 'onCollision': function (player) {
  75. player.killedBy('a defense drone');
  76. },
  77. 'behavior': function (me) {
  78. if(me.getY() != 11){
  79. if (me.canMove("up")) {
  80. me.move("up");
  81. }
  82. else {
  83. me.move("right");
  84. }
  85. }
  86. }
  87. });
  88.  
  89. // just for decoration
  90. map.defineObject('water', {
  91. 'symbol': '░',
  92. 'color': '#44f'
  93. });
  94.  
  95. map.placePlayer(0, 12);
  96.  
  97. for (var x = 0; x < map.getWidth(); x++) {
  98. map.placeObject(x, 10, 'block');
  99. map.placeObject(x, 14, 'block');
  100.  
  101. for (var y = 20; y < map.getHeight(); y++) {
  102. map.placeObject(x, y, 'water');
  103. }
  104. }
  105.  
  106. map.placeObject(23, 11, 'attackDrone');
  107. map.placeObject(23, 12, 'attackDrone');
  108. map.placeObject(23, 13, 'attackDrone');
  109.  
  110. map.placeObject(27, 11, 'defenseDrone');
  111. map.placeObject(27, 12, 'defenseDrone');
  112. map.placeObject(27, 13, 'defenseDrone');
  113.  
  114. map.placeObject(24, 11, 'reinforcementDrone');
  115. map.placeObject(25, 11, 'reinforcementDrone');
  116. map.placeObject(26, 11, 'reinforcementDrone');
  117. map.placeObject(24, 13, 'reinforcementDrone');
  118. map.placeObject(25, 13, 'reinforcementDrone');
  119. map.placeObject(26, 13, 'reinforcementDrone');
  120.  
  121. map.placeObject(map.getWidth()-1, 12, 'exit');
  122. }
  123.  
  124. function validateLevel(map) {
  125. map.validateExactlyXManyObjects(1, 'exit');
  126. }
RAW Paste Data