SHARE
TWEET

Untitled

a guest Jan 19th, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * robotNav.js
  3.  *
  4.  * The green key is located in a slightly more
  5.  * complicated room. You'll need to get the robot
  6.  * past these obstacles.
  7.  */
  8.  
  9. function startLevel(map) {
  10.     // Hint: you can press R or 5 to "rest" and not move the
  11.     // player, while the robot moves around.
  12.  
  13.     map.placePlayer(0, map.getHeight() - 1);
  14.     var player = map.getPlayer();
  15.  
  16.     map.defineObject('robot', {
  17.         'type': 'dynamic',
  18.         'symbol': 'R',
  19.         'color': 'gray',
  20.         'onCollision': function (player, me) {
  21.             me.giveItemTo(player, 'greenKey');
  22.         },
  23.         'behavior': function (me) {
  24.             if (me.canMove('right')) {
  25.                 me.move('right');
  26.             } else {
  27.                 me.move('down');
  28.             }
  29.  
  30.  
  31. if (player.teleportersAreReady) {
  32.         // Do not add teleporters more than once
  33.         return;
  34.     }
  35.  
  36.     // Place two teleporters at the map
  37.     map.placeObject(player.getX(), player.getY() - 1, 'teleporter');
  38.     map.placeObject(map.getWidth() - 2, 7, 'teleporter');
  39.  
  40.     // We need teleporters objects, so find them
  41.     var objs = map.getDynamicObjects();
  42.     var teleporters = [];
  43.  
  44.     for (var i = 0, len = objs.length; i < len; i++) {
  45.         if (objs[i].getType() == 'teleporter') {
  46.                 teleporters.push(objs[i]);
  47.         }
  48.     }
  49.  
  50.     // Link teleporters one to another
  51.     teleporters[0].setTarget(teleporters[1]);
  52.     teleporters[1].setTarget(teleporters[0]);
  53.  
  54.     // We need an indicator to know if teleporters already
  55.     // in place or not. Use "player" object from the closure
  56.     player.teleportersAreReady = true;
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.         }
  67.     });
  68.  
  69.     map.defineObject('barrier', {
  70.         'symbol': '░',
  71.         'color': 'purple',
  72.         'impassable': true,
  73.         'passableFor': ['robot']
  74.     });
  75.  
  76.     map.placeObject(map.getWidth() - 1, map.getHeight() - 1, 'exit');
  77.     map.placeObject(1, 1, 'robot');
  78.     map.placeObject(map.getWidth() - 2, 8, 'greenKey');
  79.     map.placeObject(map.getWidth() - 2, 9, 'barrier');
  80.  
  81.     for (var x = 0; x < map.getWidth(); x++) {
  82.         map.placeObject(x, 0, 'block');
  83.         if (x != map.getWidth() - 2) {
  84.             map.placeObject(x, 9, 'block');
  85.         }
  86.     }
  87.  
  88.     for (var y = 1; y < 9; y++) {
  89.         map.placeObject(0, y, 'block');
  90.         map.placeObject(map.getWidth() - 1, y, 'block');
  91.     }
  92.  
  93.     for (var i = 0; i < 4; i++) {
  94.         map.placeObject(20 - i, i + 1, 'block');
  95.         map.placeObject(35 - i, 8 - i, 'block');
  96.     }
  97. }
  98.  
  99. function validateLevel(map) {
  100.     map.validateExactlyXManyObjects(1, 'exit');
  101.     map.validateExactlyXManyObjects(1, 'robot');
  102.     map.validateAtMostXObjects(1, 'greenKey');
  103. }
  104.  
  105. function onExit(map) {
  106.     if (!map.getPlayer().hasItem('greenKey')) {
  107.         map.writeStatus("We need to get that key!");
  108.         return false;
  109.     } else {
  110.         return true;
  111.     }
  112. }
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