SHARE
TWEET

Untitled

a guest Apr 19th, 2019 83 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.         let index = 0;
  24.         let colors = ['#f00', '#0f0', '#ff0']
  25.  
  26.         player.setColor(colors[(Math.random() * colors.length).toFixed(0)]);
  27.     });
  28.  
  29.  
  30.     map.defineObject('redLock', {
  31.         symbol: '☒',
  32.         color: "#f00", // red
  33.         impassable: function(player, object) {
  34.             return player.getColor() != object.color;
  35.         }
  36.     });
  37.  
  38.     map.defineObject('greenLock', {
  39.         symbol: '☒',
  40.         color: "#0f0", // green
  41.         impassable: function(player, object) {
  42.             return player.getColor() != object.color;
  43.         }
  44.     });
  45.  
  46.     map.defineObject('yellowLock', {
  47.         symbol: '☒',
  48.         color: "#ff0", // yellow
  49.         impassable: function(player, object) {
  50.             return player.getColor() != object.color;
  51.         }
  52.     });
  53.  
  54.     for (var x = 20; x <= 40; x++) {
  55.         map.placeObject(x, 11, 'block');
  56.         map.placeObject(x, 13, 'block');
  57.     }
  58.     map.placeObject(22, 12, 'greenLock');
  59.     map.placeObject(25, 12, 'redLock');
  60.     map.placeObject(28, 12, 'yellowLock');
  61.     map.placeObject(31, 12, 'greenLock');
  62.     map.placeObject(34, 12, 'redLock');
  63.     map.placeObject(37, 12, 'yellowLock');
  64.     map.placeObject(40, 12, 'exit');
  65.     for (var y = 0; y < map.getHeight(); y++) {
  66.         if (y != 12) {
  67.             map.placeObject(40, y, 'block');
  68.         }
  69.         for (var x = 41; x < map.getWidth(); x++) {
  70.             map.setSquareColor(x, y, '#080');
  71.         }
  72.     }
  73. }
  74.  
  75. function validateLevel(map) {
  76.     map.validateExactlyXManyObjects(1, 'exit');
  77. }
  78.  
  79. function onExit(map) {
  80.     if (!map.getPlayer().hasItem('phone')) {
  81.         map.writeStatus("We need the phone!");
  82.         return false;
  83.     } else {
  84.         return true;
  85.     }
  86. }
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