Guest User

Untitled

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