Guest User

Untitled

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