SHARE
TWEET

Untitled

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