Advertisement
Guest User

Untitled

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