Guest User

Untitled

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