daily pastebin goal
38%
SHARE
TWEET

Untitled

a guest Feb 21st, 2019 58 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.             moveToward(me, 'player');
  48.             if(me.x) return; me.x=1;
  49.  
  50.             map.l = map.l || [];
  51.             map.l.push(this);
  52.         }
  53.     });
  54.  
  55.     map.defineObject('reinforcementDrone', {
  56.         'type': 'dynamic',
  57.         'symbol': 'd',
  58.         'color': 'yellow',
  59.         'onCollision': function (player) {
  60.             player.killedBy('a reinforcement drone');
  61.         },
  62.         'behavior': function (me) {
  63.             me.move('left');
  64.             if(me.x) return; me.x=1;
  65.  
  66.             map.l = map.l || [];
  67.             map.l.push(this);
  68.         }
  69.     });
  70.  
  71.     map.defineObject('defenseDrone', {
  72.         'type': 'dynamic',
  73.         'symbol': 'd',
  74.         'color': 'green',
  75.         'onCollision': function (player) {
  76.             player.killedBy('a defense drone');
  77.         },
  78.         'behavior': function (me) {
  79.             if(me.x) return; me.x=1;
  80.  
  81.             map.l = map.l || [];
  82.             map.l.push(this);
  83.  
  84.             screenPane.onkeydown = e => {
  85.                 e.key == 'e' && map.l.map(l => {
  86.                     l.color = 'gray';
  87.                     l.behavior = ()=>{};
  88.                     l.onCollision = (p, s) => {
  89.                         map.setSquareColor(p.getX(), p.getY(), '#222');
  90.                         (async () => { await 0; s._destroy() })();
  91.                     }
  92.                    });
  93.             };
  94.         }
  95.     });
  96.  
  97.     // just for decoration
  98.     map.defineObject('water', {
  99.         'symbol': '░',
  100.         'color': '#44f'
  101.     });
  102.  
  103.     map.placePlayer(0, 12);
  104.  
  105.     for (var x = 0; x < map.getWidth(); x++) {
  106.         map.placeObject(x, 10, 'block');
  107.         map.placeObject(x, 14, 'block');
  108.  
  109.         for (var y = 20; y < map.getHeight(); y++) {
  110.             map.placeObject(x, y, 'water');
  111.         }
  112.     }
  113.  
  114.     map.placeObject(23, 11, 'attackDrone');
  115.     map.placeObject(23, 12, 'attackDrone');
  116.     map.placeObject(23, 13, 'attackDrone');
  117.  
  118.     map.placeObject(27, 11, 'defenseDrone');
  119.     map.placeObject(27, 12, 'defenseDrone');
  120.     map.placeObject(27, 13, 'defenseDrone');
  121.  
  122.     map.placeObject(24, 11, 'reinforcementDrone');
  123.     map.placeObject(25, 11, 'reinforcementDrone');
  124.     map.placeObject(26, 11, 'reinforcementDrone');
  125.     map.placeObject(24, 13, 'reinforcementDrone');
  126.     map.placeObject(25, 13, 'reinforcementDrone');
  127.     map.placeObject(26, 13, 'reinforcementDrone');
  128.  
  129.     map.placeObject(map.getWidth()-1, 12, 'exit');
  130. }
  131.  
  132. function validateLevel(map) {
  133.     map.validateExactlyXManyObjects(1, 'exit');
  134. }
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