Advertisement
Guest User

Untitled

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