daily pastebin goal
93%
SHARE
TWEET

Untitled

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