Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.40 KB | None | 0 0
  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.  
  48. if (me.canMove('right'))
  49. {
  50. me.move('right');
  51. } else if (me.canMove('up')) {
  52. me.move('up');
  53. }
  54. else
  55. {
  56. me.move('left');
  57. }
  58. }
  59. });
  60.  
  61. map.defineObject('reinforcementDrone', {
  62. 'type': 'dynamic',
  63. 'symbol': 'd',
  64. 'color': 'yellow',
  65. 'onCollision': function (player) {
  66. player.killedBy('a reinforcement drone');
  67. },
  68. 'behavior': function (me) {
  69.  
  70. }
  71. });
  72.  
  73. map.defineObject('defenseDrone', {
  74. 'type': 'dynamic',
  75. 'symbol': 'd',
  76. 'color': 'green',
  77. 'onCollision': function (player) {
  78. player.killedBy('a defense drone');
  79. },
  80. 'behavior': function (me) {
  81.  
  82. if (me.canMove('right'))
  83. {
  84. me.move('right');
  85. } else if (me.canMove('up')) {
  86. me.move('up');
  87. }
  88. else
  89. {
  90. me.move('left');
  91. }
  92. }
  93. });
  94.  
  95. // just for decoration
  96. map.defineObject('water', {
  97. 'symbol': 'β–‘',
  98. 'color': '#44f'
  99. });
  100.  
  101. map.placePlayer(0, 12);
  102.  
  103. for (var x = 0; x < map.getWidth(); x++) {
  104. map.placeObject(x, 10, 'block');
  105. map.placeObject(x, 14, 'block');
  106.  
  107. for (var y = 20; y < map.getHeight(); y++) {
  108. map.placeObject(x, y, 'water');
  109. }
  110. }
  111.  
  112. map.placeObject(23, 11, 'attackDrone');
  113. map.placeObject(23, 12, 'attackDrone');
  114. map.placeObject(23, 13, 'attackDrone');
  115.  
  116. map.placeObject(27, 11, 'defenseDrone');
  117. map.placeObject(27, 12, 'defenseDrone');
  118. map.placeObject(27, 13, 'defenseDrone');
  119.  
  120. map.placeObject(24, 11, 'reinforcementDrone');
  121. map.placeObject(25, 11, 'reinforcementDrone');
  122. map.placeObject(26, 11, 'reinforcementDrone');
  123. map.placeObject(24, 13, 'reinforcementDrone');
  124. map.placeObject(25, 13, 'reinforcementDrone');
  125. map.placeObject(26, 13, 'reinforcementDrone');
  126.  
  127. map.placeObject(map.getWidth()-1, 12, 'exit');
  128. }
  129.  
  130. function validateLevel(map) {
  131. map.validateExactlyXManyObjects(1, 'exit');
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement