Advertisement
Guest User

Untitled

a guest
May 24th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.80 KB | None | 0 0
  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. let pad = number => ("000"+number).slice(-3);
  23. var player = map.getPlayer();
  24.  
  25. function getNextColor(color){
  26. // parse the string, treat hex as binary, and add 2
  27. // ex, #0f0 becomes 010
  28. let i = parseInt(color.replace(/f/g, 1).substring(1,4), 2) + 2;
  29. // If value got too big, recursively call with reset val of 0
  30. if(i > 6) return getNextColor(pad(0));
  31. // convert binary back to hex, ensure left padding, and add #
  32. // ex, 100 becomes #f00
  33. return '#' + pad(i.toString(2).replace(/1/g, 'f'));
  34. }
  35.  
  36. // Set next color
  37. player.setColor(getNextColor(player.getColor()));
  38.  
  39.  
  40.  
  41.  
  42.  
  43. });
  44.  
  45.  
  46. map.defineObject('redLock', {
  47. symbol: '☒',
  48. color: "#f00", // red
  49. impassable: function(player, object) {
  50. return player.getColor() != object.color;
  51. }
  52. });
  53.  
  54. map.defineObject('greenLock', {
  55. symbol: '☒',
  56. color: "#0f0", // green
  57. impassable: function(player, object) {
  58. return player.getColor() != object.color;
  59. }
  60. });
  61.  
  62. map.defineObject('yellowLock', {
  63. symbol: '☒',
  64. color: "#ff0", // yellow
  65. impassable: function(player, object) {
  66. return player.getColor() != object.color;
  67. }
  68. });
  69.  
  70. for (var x = 20; x <= 40; x++) {
  71. map.placeObject(x, 11, 'block');
  72. map.placeObject(x, 13, 'block');
  73. }
  74. map.placeObject(22, 12, 'greenLock');
  75. map.placeObject(25, 12, 'redLock');
  76. map.placeObject(28, 12, 'yellowLock');
  77. map.placeObject(31, 12, 'greenLock');
  78. map.placeObject(34, 12, 'redLock');
  79. map.placeObject(37, 12, 'yellowLock');
  80. map.placeObject(40, 12, 'exit');
  81. for (var y = 0; y < map.getHeight(); y++) {
  82. if (y != 12) {
  83. map.placeObject(40, y, 'block');
  84. }
  85. for (var x = 41; x < map.getWidth(); x++) {
  86. map.setSquareColor(x, y, '#080');
  87. }
  88. }
  89. }
  90.  
  91. function validateLevel(map) {
  92. map.validateExactlyXManyObjects(1, 'exit');
  93. }
  94.  
  95. function onExit(map) {
  96. if (!map.getPlayer().hasItem('phone')) {
  97. map.writeStatus("We need the phone!");
  98. return false;
  99. } else {
  100. return true;
  101. }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement