Guest User

Untitled

a guest
May 21st, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 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 truc = 0;
  25.  
  26. if(me.getX() < 21){
  27. if (me.canMove('down')) {
  28. me.move('down');
  29. } else {
  30. me.move('right');
  31. }
  32. }
  33. else if (me.getX() < map.getWidth()-2) {
  34. if (me.canMove('up'))
  35. me.move('up');
  36. else
  37. me.move('right');
  38. }
  39. else
  40. me.move('down');
  41.  
  42.  
  43.  
  44.  
  45. /* else {
  46. if (me.canMove('up')) {
  47. me.move('up');
  48. } else if(me.canMove('right')){
  49. me.move('right');
  50. }
  51. }
  52. else if(truc == 2) {
  53. me.move('down');
  54.  
  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