Guest User

Untitled

a guest
May 22nd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 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. var player = map.getPlayer();
  23.  
  24. var chosenColor = "#f00";
  25.  
  26. if (
  27. player.atLocation(24, 12) ||
  28. player.atLocation(33, 12) ) {
  29.  
  30. chosenColor = "#f00";
  31. } else if (
  32. player.atLocation(27, 12) ||
  33. player.atLocation(36, 12) ) {
  34.  
  35. chosenColor = "#ff0";
  36. } else if (
  37. player.atLocation(21, 12) ||
  38. player.atLocation(30, 12) ) {
  39.  
  40. chosenColor = "#0f0";
  41. }
  42.  
  43. player.setColor(chosenColor);
  44. });
  45.  
  46.  
  47. map.defineObject('redLock', {
  48. symbol: '☒',
  49. color: "#f00", // red
  50. impassable: function(player, object) {
  51. return player.getColor() != object.color;
  52. }
  53. });
  54.  
  55. map.defineObject('greenLock', {
  56. symbol: '☒',
  57. color: "#0f0", // green
  58. impassable: function(player, object) {
  59. return player.getColor() != object.color;
  60. }
  61. });
  62.  
  63. map.defineObject('yellowLock', {
  64. symbol: '☒',
  65. color: "#ff0", // yellow
  66. impassable: function(player, object) {
  67. return player.getColor() != object.color;
  68. }
  69. });
  70.  
  71. for (var x = 20; x <= 40; x++) {
  72. map.placeObject(x, 11, 'block');
  73. map.placeObject(x, 13, 'block');
  74. }
  75. map.placeObject(22, 12, 'greenLock');
  76. map.placeObject(25, 12, 'redLock');
  77. map.placeObject(28, 12, 'yellowLock');
  78. map.placeObject(31, 12, 'greenLock');
  79. map.placeObject(34, 12, 'redLock');
  80. map.placeObject(37, 12, 'yellowLock');
  81. map.placeObject(40, 12, 'exit');
  82. for (var y = 0; y < map.getHeight(); y++) {
  83. if (y != 12) {
  84. map.placeObject(40, y, 'block');
  85. }
  86. for (var x = 41; x < map.getWidth(); x++) {
  87. map.setSquareColor(x, y, '#080');
  88. }
  89. }
  90. }
  91.  
  92. function validateLevel(map) {
  93. map.validateExactlyXManyObjects(1, 'exit');
  94. }
  95.  
  96. function onExit(map) {
  97. if (!map.getPlayer().hasItem('phone')) {
  98. map.writeStatus("We need the phone!");
  99. return false;
  100. } else {
  101. return true;
  102. }
  103. }
Add Comment
Please, Sign In to add comment