Guest User

Untitled

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