SHARE
TWEET

Untitled

a guest Feb 19th, 2019 55 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.  me.move(me.getX() == 2 && me.canMove('down') ? 'down'
  25.        : me.getX() < 30 ? 'right'
  26.        : me.getX() == 30 && me.canMove('up') ? 'up'
  27.        : me.canMove('right') ? 'right'
  28.        : 'down');
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.         }
  41.     });
  42.  
  43.     map.defineObject('barrier', {
  44.         'symbol': '░',
  45.         'color': 'purple',
  46.         'impassable': true,
  47.         'passableFor': ['robot']
  48.     });
  49.  
  50.     map.placeObject(map.getWidth() - 1, map.getHeight() - 1, 'exit');
  51.     map.placeObject(1, 1, 'robot');
  52.     map.placeObject(map.getWidth() - 2, 8, 'greenKey');
  53.     map.placeObject(map.getWidth() - 2, 9, 'barrier');
  54.  
  55.     for (var x = 0; x < map.getWidth(); x++) {
  56.         map.placeObject(x, 0, 'block');
  57.         if (x != map.getWidth() - 2) {
  58.             map.placeObject(x, 9, 'block');
  59.         }
  60.     }
  61.  
  62.     for (var y = 1; y < 9; y++) {
  63.         map.placeObject(0, y, 'block');
  64.         map.placeObject(map.getWidth() - 1, y, 'block');
  65.     }
  66.  
  67.     for (var i = 0; i < 4; i++) {
  68.         map.placeObject(20 - i, i + 1, 'block');
  69.         map.placeObject(35 - i, 8 - i, 'block');
  70.     }
  71. }
  72.  
  73. function validateLevel(map) {
  74.     map.validateExactlyXManyObjects(1, 'exit');
  75.     map.validateExactlyXManyObjects(1, 'robot');
  76.     map.validateAtMostXObjects(1, 'greenKey');
  77. }
  78.  
  79. function onExit(map) {
  80.     if (!map.getPlayer().hasItem('greenKey')) {
  81.         map.writeStatus("We need to get that key!");
  82.         return false;
  83.     } else {
  84.         return true;
  85.     }
  86. }
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