Guest User

Untitled

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