Guest User

Untitled

a guest
Aug 20th, 2019
76
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. var r = Math.random();
  48. if (r<0.2)
  49. me.move('left');
  50. else if (r<0.4)
  51. me.move('right');
  52. else
  53. me.move('down');
  54. }
  55. });
  56.  
  57. map.defineObject('reinforcementDrone', {
  58. 'type': 'dynamic',
  59. 'symbol': 'd',
  60. 'color': 'yellow',
  61. 'onCollision': function (player) {
  62. player.killedBy('a reinforcement drone');
  63. },
  64. 'behavior': function (me) {
  65. var r = Math.random();
  66. if (r<0.2)
  67. me.move('left');
  68. else if (r<0.4)
  69. me.move('right');
  70. else
  71. me.move('down');
  72. }
  73. });
  74.  
  75. map.defineObject('defenseDrone', {
  76. 'type': 'dynamic',
  77. 'symbol': 'd',
  78. 'color': 'green',
  79. 'onCollision': function (player) {
  80. player.killedBy('a defense drone');
  81. },
  82. 'behavior': function (me) {
  83.  
  84. var r = Math.random();
  85. if (r<0.2)
  86. me.move('left');
  87. else if (r<0.4)
  88. me.move('right');
  89. else
  90. me.move('down');
  91. }
  92. });
  93.  
  94. // just for decoration
  95. map.defineObject('water', {
  96. 'symbol': '░',
  97. 'color': '#44f'
  98. });
  99.  
  100. map.placePlayer(0, 12);
  101.  
  102. for (var x = 0; x < map.getWidth(); x++) {
  103. map.placeObject(x, 10, 'block');
  104. map.placeObject(x, 14, 'block');
  105.  
  106. for (var y = 20; y < map.getHeight(); y++) {
  107. map.placeObject(x, y, 'water');
  108. }
  109. }
  110.  
  111. map.placeObject(23, 11, 'attackDrone');
  112. map.placeObject(23, 12, 'attackDrone');
  113. map.placeObject(23, 13, 'attackDrone');
  114.  
  115. map.placeObject(27, 11, 'defenseDrone');
  116. map.placeObject(27, 12, 'defenseDrone');
  117. map.placeObject(27, 13, 'defenseDrone');
  118.  
  119. map.placeObject(24, 11, 'reinforcementDrone');
  120. map.placeObject(25, 11, 'reinforcementDrone');
  121. map.placeObject(26, 11, 'reinforcementDrone');
  122. map.placeObject(24, 13, 'reinforcementDrone');
  123. map.placeObject(25, 13, 'reinforcementDrone');
  124. map.placeObject(26, 13, 'reinforcementDrone');
  125.  
  126. map.placeObject(map.getWidth()-1, 12, 'exit');
  127. }
  128.  
  129. function validateLevel(map) {
  130. map.validateExactlyXManyObjects(1, 'exit');
  131. }
RAW Paste Data