Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 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('right')){
  25. me.move('right');
  26. }
  27. else if(me.canMove("down")){
  28. me.move('down');
  29. }
  30. else{
  31. me.move('up');
  32. }
  33. }
  34. });
  35. for(var y=1;y<4;y++){
  36. map.placeObject(17,y,'block');
  37. }
  38. for(var y=6;y<9;y++){
  39. map.placeObject(32,y,'block');
  40. }
  41. for(var x=16;x<32;x++){
  42. map.placeObject(x,6,'block');
  43. }
  44. map.defineObject('delusion',{
  45. 'type': 'dynamic',
  46. 'symbol': 'R',
  47. 'color': 'gray',
  48. 'onCollision': function (player, me) {
  49. me.giveItemTo(player, 'greenKey');
  50. },
  51. 'behavior': function (me) {
  52. me.move('right');
  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