Advertisement
Guest User

Untitled

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