Guest User

Untitled

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