SHARE
TWEET

Untitled

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