Guest User

Untitled

a guest
Sep 17th, 2019
94
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. switch(state) {
  25. case 0:
  26. if (me.canMove('down'))
  27. me.move('down');
  28. else
  29. state = 1;
  30. break;
  31. case 1:
  32. if (me.canMove('right'))
  33. me.move('right');
  34. else if (me.canMove('down'))
  35. {
  36. me.move('down');
  37. state = 0;
  38. }
  39. else
  40. state = 2;
  41. break;
  42. case 2:
  43. if (me.canMove('up')) {
  44. me.move('up');
  45. state = 3;
  46. }
  47. else if (me.canMove('left'))
  48. me.move('left')
  49. break;
  50. case 3:
  51. if (me.canMove('right')) {
  52. me.move('right');
  53. state = 1;
  54. }
  55. else if (me.canMove('left')) {
  56. me.move('left')
  57. state = 2;
  58. }
  59. break;
  60. }
  61. }
  62. });
  63.  
  64. var state = 0;
  65.  
  66. ({'thing': {
  67. }
  68. });
  69.  
  70. map.defineObject('barrier', {
  71. 'symbol': '░',
  72. 'color': 'purple',
  73. 'impassable': true,
  74. 'passableFor': ['robot']
  75. });
  76.  
  77. map.placeObject(map.getWidth() - 1, map.getHeight() - 1, 'exit');
  78. map.placeObject(1, 1, 'robot');
  79. map.placeObject(map.getWidth() - 2, 8, 'greenKey');
  80. map.placeObject(map.getWidth() - 2, 9, 'barrier');
  81.  
  82. for (var x = 0; x < map.getWidth(); x++) {
  83. map.placeObject(x, 0, 'block');
  84. if (x != map.getWidth() - 2) {
  85. map.placeObject(x, 9, 'block');
  86. }
  87. }
  88.  
  89. for (var y = 1; y < 9; y++) {
  90. map.placeObject(0, y, 'block');
  91. map.placeObject(map.getWidth() - 1, y, 'block');
  92. }
  93.  
  94. for (var i = 0; i < 4; i++) {
  95. map.placeObject(20 - i, i + 1, 'block');
  96. map.placeObject(35 - i, 8 - i, 'block');
  97. }
  98. }
  99.  
  100. function validateLevel(map) {
  101. map.validateExactlyXManyObjects(1, 'exit');
  102. map.validateExactlyXManyObjects(1, 'robot');
  103. map.validateAtMostXObjects(1, 'greenKey');
  104. }
  105.  
  106. function onExit(map) {
  107. if (!map.getPlayer().hasItem('greenKey')) {
  108. map.writeStatus("We need to get that key!");
  109. return false;
  110. } else {
  111. return true;
  112. }
  113. }
RAW Paste Data