SHARE
TWEET

Untitled

a guest Apr 25th, 2019 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*************
  2. * colors.js *
  3.  *************
  4.  *
  5.  * You're almost at the exit. You just need to get past this
  6.  * color lock.
  7.  *
  8.  * Changing your environment is no longer enough. You must
  9.  * learn to change yourself. I've sent you a little something
  10.  * that should help with that.
  11.  */
  12.  
  13. function startLevel(map) {
  14.     map.placePlayer(0, 12);
  15.  
  16.     map.placeObject(5, 12, 'phone');
  17.  
  18.     // The function phone lets you call arbitrary functions,
  19.     // as defined by player.setPhoneCallback() below.
  20.     // The function phone callback is bound to Q or Ctrl-6.
  21.     map.getPlayer().setPhoneCallback(function () {
  22.         var player = map.getPlayer();
  23.  
  24. const green = '#0f0';
  25. const red = '#f00';
  26. const yellow = '#ff0';
  27.  
  28. if (player.getColor() === yellow) {
  29.     player.setColor(green);
  30. } else if (player.getColor() === green) {
  31.     player.setColor(red);
  32. } else if (player.getColor() === red) {
  33.     player.setColor(yellow);
  34. }
  35.  
  36.  
  37.  
  38.  
  39.     });
  40.  
  41.  
  42.     map.defineObject('redLock', {
  43.         symbol: '☒',
  44.         color: "#f00", // red
  45.         impassable: function(player, object) {
  46.             return player.getColor() != object.color;
  47.         }
  48.     });
  49.  
  50.     map.defineObject('greenLock', {
  51.         symbol: '☒',
  52.         color: "#0f0", // green
  53.         impassable: function(player, object) {
  54.             return player.getColor() != object.color;
  55.         }
  56.     });
  57.  
  58.     map.defineObject('yellowLock', {
  59.         symbol: '☒',
  60.         color: "#ff0", // yellow
  61.         impassable: function(player, object) {
  62.             return player.getColor() != object.color;
  63.         }
  64.     });
  65.  
  66.     for (var x = 20; x <= 40; x++) {
  67.         map.placeObject(x, 11, 'block');
  68.         map.placeObject(x, 13, 'block');
  69.     }
  70.     map.placeObject(22, 12, 'greenLock');
  71.     map.placeObject(25, 12, 'redLock');
  72.     map.placeObject(28, 12, 'yellowLock');
  73.     map.placeObject(31, 12, 'greenLock');
  74.     map.placeObject(34, 12, 'redLock');
  75.     map.placeObject(37, 12, 'yellowLock');
  76.     map.placeObject(40, 12, 'exit');
  77.     for (var y = 0; y < map.getHeight(); y++) {
  78.         if (y != 12) {
  79.             map.placeObject(40, y, 'block');
  80.         }
  81.         for (var x = 41; x < map.getWidth(); x++) {
  82.             map.setSquareColor(x, y, '#080');
  83.         }
  84.     }
  85. }
  86.  
  87. function validateLevel(map) {
  88.     map.validateExactlyXManyObjects(1, 'exit');
  89. }
  90.  
  91. function onExit(map) {
  92.     if (!map.getPlayer().hasItem('phone')) {
  93.         map.writeStatus("We need the phone!");
  94.         return false;
  95.     } else {
  96.         return true;
  97.     }
  98. }
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