Guest User

Untitled

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