Guest User

Untitled

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