SHARE
TWEET

Untitled

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