Advertisement
Guest User

Untitled

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