Guest User

Untitled

a guest
Apr 20th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 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. moveToward(me, 'exit');
  48. }
  49. });
  50.  
  51. map.defineObject('reinforcementDrone', {
  52. 'type': 'dynamic',
  53. 'symbol': 'd',
  54. 'color': 'yellow',
  55. 'onCollision': function (player) {
  56. player.killedBy('a reinforcement drone');
  57. },
  58. 'behavior': function (me) {
  59. me.move('left');
  60. }
  61. });
  62.  
  63. map.defineObject('defenseDrone', {
  64. 'type': 'dynamic',
  65. 'symbol': 'd',
  66. 'color': 'green',
  67. 'onCollision': function (player) {
  68. player.killedBy('a defense drone');
  69. },
  70. 'behavior': function (me) {
  71. var r = Math.random();
  72. (r<0.2) ? me.move('right') : me.move('left');
  73. }
  74. });
  75.  
  76. // just for decoration
  77. map.defineObject('water', {
  78. 'symbol': '░',
  79. 'color': '#44f'
  80. });
  81.  
  82. map.placePlayer(0, 12);
  83.  
  84. for (var x = 0; x < map.getWidth(); x++) {
  85. map.placeObject(x, 10, 'block');
  86. map.placeObject(x, 14, 'block');
  87.  
  88. for (var y = 20; y < map.getHeight(); y++) {
  89. map.placeObject(x, y, 'water');
  90. }
  91. }
  92.  
  93. map.placeObject(23, 11, 'attackDrone');
  94. map.placeObject(23, 12, 'attackDrone');
  95. map.placeObject(23, 13, 'attackDrone');
  96.  
  97. map.placeObject(27, 11, 'defenseDrone');
  98. map.placeObject(27, 12, 'defenseDrone');
  99. map.placeObject(27, 13, 'defenseDrone');
  100.  
  101. map.placeObject(24, 11, 'reinforcementDrone');
  102. map.placeObject(25, 11, 'reinforcementDrone');
  103. map.placeObject(26, 11, 'reinforcementDrone');
  104. map.placeObject(24, 13, 'reinforcementDrone');
  105. map.placeObject(25, 13, 'reinforcementDrone');
  106. map.placeObject(26, 13, 'reinforcementDrone');
  107.  
  108. map.placeObject(map.getWidth()-1, 12, 'exit');
  109. }
  110.  
  111. function validateLevel(map) {
  112. map.validateExactlyXManyObjects(1, 'exit');
  113. }
Add Comment
Please, Sign In to add comment