Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. /*
  2. * robotNav.js
  3. *
  4. * The green key is located in a slightly more
  5. * complicated room. You'll need to get the robot
  6. * past these obstacles.
  7. */
  8.  
  9. function startLevel(map) {
  10. // Hint: you can press R or 5 to "rest" and not move the
  11. // player, while the robot moves around.
  12.  
  13. map.placePlayer(0, map.getHeight() - 1);
  14. var player = map.getPlayer();
  15.  
  16. map.defineObject('robot', {
  17. 'type': 'dynamic',
  18. 'symbol': 'R',
  19. 'color': 'gray',
  20. 'onCollision': function (player, me) {
  21. me.giveItemTo(player, 'greenKey');
  22. },
  23. 'behavior': function (me) {
  24. if (player.getX() === 5) {
  25. me.move('right');
  26. } else if (player.getX() === 3) {
  27. me.move('left');
  28. }
  29. else if (player.getY() === 17) {
  30. me.move('up');
  31. } else if (player.getY() === 15) {
  32. me.move('down');
  33. }
  34. }
  35. });
  36.  
  37. map.getPlayer().setPhoneCallback(function () {
  38. if (1) {
  39.  
  40. map.setSquareColor(5, 16, '#f00');
  41. map.setSquareColor(4, 17, '#f00');
  42. map.setSquareColor(4, 15, '#f00');
  43. map.setSquareColor(3, 16, '#f00');
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50. }
  51. });
  52.  
  53. map.defineObject('barrier', {
  54. 'symbol': '░',
  55. 'color': 'purple',
  56. 'impassable': true,
  57. 'passableFor': ['robot']
  58. });
  59.  
  60. map.placeObject(map.getWidth() - 1, map.getHeight() - 1, 'exit');
  61. map.placeObject(1, 1, 'robot');
  62. map.placeObject(map.getWidth() - 2, 8, 'greenKey');
  63. map.placeObject(map.getWidth() - 2, 9, 'barrier');
  64.  
  65. for (var x = 0; x < map.getWidth(); x++) {
  66. map.placeObject(x, 0, 'block');
  67. if (x != map.getWidth() - 2) {
  68. map.placeObject(x, 9, 'block');
  69. }
  70. }
  71.  
  72. for (var y = 1; y < 9; y++) {
  73. map.placeObject(0, y, 'block');
  74. map.placeObject(map.getWidth() - 1, y, 'block');
  75. }
  76.  
  77. for (var i = 0; i < 4; i++) {
  78. map.placeObject(20 - i, i + 1, 'block');
  79. map.placeObject(35 - i, 8 - i, 'block');
  80. }
  81. }
  82.  
  83. function validateLevel(map) {
  84. map.validateExactlyXManyObjects(1, 'exit');
  85. map.validateExactlyXManyObjects(1, 'robot');
  86. map.validateAtMostXObjects(1, 'greenKey');
  87. }
  88.  
  89. function onExit(map) {
  90. if (!map.getPlayer().hasItem('greenKey')) {
  91. map.writeStatus("We need to get that key!");
  92. return false;
  93. } else {
  94. return true;
  95. }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement