daily pastebin goal
63%
SHARE
TWEET

Untitled

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