SHARE
TWEET

Untitled

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