SHARE
TWEET

Untitled

a guest Apr 26th, 2019 57 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() == 12) {
  48.                 if (me.getX() == 23) { me.move('left'); }
  49.                 else { me.move('up'); }
  50.             }
  51.         }
  52.     });
  53.  
  54.     map.defineObject('reinforcementDrone', {
  55.         'type': 'dynamic',
  56.         'symbol': 'd',
  57.         'color': 'yellow',
  58.         'onCollision': function (player) {
  59.             player.killedBy('a reinforcement drone');
  60.         },
  61.         'behavior': function (me) {
  62.  
  63.         }
  64.     });
  65.  
  66.     map.defineObject('defenseDrone', {
  67.         'type': 'dynamic',
  68.         'symbol': 'd',
  69.         'color': 'green',
  70.         'onCollision': function (player) {
  71.             player.killedBy('a defense drone');
  72.         },
  73.         'behavior': function (me) {
  74.             if (me.getY() == 12) {
  75.                 if (me.getX() == 27) { me.move('right'); }
  76.                 else { me.move('up'); }
  77.             }
  78.         }
  79.     });
  80.  
  81.     // just for decoration
  82.     map.defineObject('water', {
  83.         'symbol': '░',
  84.         'color': '#44f'
  85.     });
  86.  
  87.     map.placePlayer(0, 12);
  88.  
  89.     for (var x = 0; x < map.getWidth(); x++) {
  90.         map.placeObject(x, 10, 'block');
  91.         map.placeObject(x, 14, 'block');
  92.  
  93.         for (var y = 20; y < map.getHeight(); y++) {
  94.             map.placeObject(x, y, 'water');
  95.         }
  96.     }
  97.  
  98.     map.placeObject(23, 11, 'attackDrone');
  99.     map.placeObject(23, 12, 'attackDrone');
  100.     map.placeObject(23, 13, 'attackDrone');
  101.  
  102.     map.placeObject(27, 11, 'defenseDrone');
  103.     map.placeObject(27, 12, 'defenseDrone');
  104.     map.placeObject(27, 13, 'defenseDrone');
  105.  
  106.     map.placeObject(24, 11, 'reinforcementDrone');
  107.     map.placeObject(25, 11, 'reinforcementDrone');
  108.     map.placeObject(26, 11, 'reinforcementDrone');
  109.     map.placeObject(24, 13, 'reinforcementDrone');
  110.     map.placeObject(25, 13, 'reinforcementDrone');
  111.     map.placeObject(26, 13, 'reinforcementDrone');
  112.  
  113.     map.placeObject(map.getWidth()-1, 12, 'exit');
  114. }
  115.  
  116. function validateLevel(map) {
  117.     map.validateExactlyXManyObjects(1, 'exit');
  118. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top