Guest User

Untitled

a guest
May 20th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 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.getX() < 20) {
  25. if (me.canMove('down')) {
  26. me.move('down');
  27. } else {
  28. me.move('right');
  29. }
  30. }
  31. else if (me.getX() < 35 ) {
  32. if (me.canMove('up')) {
  33. me.move('up');
  34. } else {
  35. me.move('right');
  36. }
  37. }
  38. else {
  39. if (me.canMove('down')) {
  40. me.move('down');
  41. } else {
  42. me.move('right');
  43. }
  44. }
  45.  
  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