daily pastebin goal
1%
SHARE
TWEET

Untitled

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