Guest User

Untitled

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