Guest User

Untitled

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