Guest User

Untitled

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