Guest User

Untitled

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