Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 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 (me.commands == null) {
  25. me.commands = [
  26. [ 'down', 4 ],
  27. [ 'right', 28 ],
  28. [ 'up', 1 ],
  29. [ 'right', 20 ],
  30. [ 'down', 20 ]
  31. ];
  32. }
  33.  
  34. if (me.currentCmd == null) {
  35. me.currentCmd = me.commands.shift();
  36. }
  37.  
  38. if (me.currentCmd == null)
  39. return;
  40.  
  41. me.move(me.currentCmd[0]);
  42. me.currentCmd[1] --;
  43. if (me.currentCmd[1] == 0)
  44. me.currentCmd = null
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement