Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.30 KB | None | 0 0
  1. /*
  2. * robotMaze.js
  3. *
  4. * The blue key is inside a labyrinth, and extracting
  5. * it will not be easy.
  6. *
  7. * It's a good thing that you're a AI expert, or
  8. * we would have to leave empty-handed.
  9. */
  10.  
  11. function startLevel(map) {
  12. // Hint: you can press R or 5 to "rest" and not move the
  13. // player, while the robot moves around.
  14.  
  15. map.getRandomInt = function(min, max) {
  16. return Math.floor(Math.random() * (max - min + 1)) + min;
  17. }
  18.  
  19. map.placePlayer(map.getWidth()-1, map.getHeight()-1);
  20. var player = map.getPlayer();
  21.  
  22. map.defineObject('robot', {
  23. 'type': 'dynamic',
  24. 'symbol': 'R',
  25. 'color': 'gray',
  26. 'onCollision': function (player, me) {
  27. me.giveItemTo(player, 'blueKey');
  28. },
  29. 'behavior': function (me) {
  30. // Available commands: me.move(direction)
  31. // and me.canMove(direction)
  32. if (player.atLocation(40-1, 20)) {
  33. me.move('left');
  34. }
  35. if (player.atLocation(40+1, 20)) {
  36. me.move('right');
  37. }
  38. if (player.atLocation(40, 20+1)) {
  39. me.move('down');
  40. }
  41. if (player.atLocation(40, 20-1)) {
  42. me.move('up');
  43. }
  44.  
  45.  
  46.  
  47.  
  48. }
  49. });
  50.  
  51.  
  52.  
  53.  
  54.  
  55. map.defineObject('v', {
  56. 'type': 'dynamic',
  57. 'symbol': 'v',
  58. 'color': 'red',
  59. 'onCollision': function (player, me) {
  60. player.setColor('#0ff');
  61. },
  62. });
  63.  
  64.  
  65. map.defineObject('>', {
  66. 'type': 'dynamic',
  67. 'symbol': '>',
  68. 'color': 'red'
  69. });
  70. map.defineObject('^', {
  71. 'type': 'dynamic',
  72. 'symbol': '^',
  73. 'color': 'red'
  74. });
  75. map.defineObject('<', {
  76. 'type': 'dynamic',
  77. 'symbol': '<',
  78. 'color': 'red'
  79. });
  80.  
  81. map.placeObject(40-1, 20, '<');
  82. map.placeObject(40+1, 20, '>');
  83. map.placeObject(40, 20+1, 'v');
  84. map.placeObject(40, 20-1, '^');
  85.  
  86. map.defineObject('X', {
  87. 'type': 'dynamic',
  88. 'symbol': 'X',
  89. 'color': 'red',
  90.  
  91. 'behavior': function (me) {
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130. }
  131. });
  132.  
  133. map.defineObject('barrier', {
  134. 'symbol': '░',
  135. 'color': 'purple',
  136. 'impassable': true,
  137. 'passableFor': ['robot']
  138. });
  139.  
  140. map.placeObject(0, map.getHeight() - 1, 'exit');
  141. map.placeObject(1, 1, 'robot');
  142. map.placeObject(map.getWidth() - 2, 8, 'blueKey');
  143. map.placeObject(map.getWidth() - 2, 9, 'barrier');
  144.  
  145. var autoGeneratedMaze = new ROT.Map.DividedMaze(map.getWidth(), 10);
  146. autoGeneratedMaze.create( function (x, y, mapValue) {
  147. // don't write maze over robot or barrier
  148. if ((x == 1 && y == 1) || (x == map.getWidth() - 2 && y >= 8)) {
  149. return 0;
  150. } else if (mapValue === 1) { //0 is empty space 1 is wall
  151. map.placeObject(x,y, 'block');
  152. } else {
  153. map.placeObject(x,y,'empty');
  154. }
  155. });
  156. }
  157.  
  158. function validateLevel(map) {
  159. map.validateExactlyXManyObjects(1, 'exit');
  160. map.validateExactlyXManyObjects(1, 'robot');
  161. map.validateAtMostXObjects(1, 'blueKey');
  162. }
  163.  
  164. function onExit(map) {
  165. if (!map.getPlayer().hasItem('blueKey')) {
  166. map.writeStatus("We need to get that key!");
  167. return false;
  168. } else {
  169. return true;
  170. }
  171. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement