daily pastebin goal
31%
SHARE
TWEET

Untitled

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