SHARE
TWEET

Untitled

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