Guest User

Untitled

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