Guest User

Untitled

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