Guest User

Untitled

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