Guest User

Untitled

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