daily pastebin goal
20%
SHARE
TWEET

Untitled

a guest Jan 21st, 2019 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.             player = map.getPlayer();
  31.             if (me.canMove('right') && player.getX() > me.getX()) {
  32.                 me.move('right')
  33.             } else if (me.canMove('left') && player.getX() < me.getX()) {
  34.                 me.move('left')
  35.             }
  36.            
  37.             if (me.canMove('down') && player.getY() > me.getY()+10) {
  38.                 me.move('down')
  39.             } else if (me.canMove('up') && player.getY() < me.getY()+10) {
  40.                 me.move('up')
  41.             }
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.         }
  84.     });
  85.  
  86.     map.defineObject('barrier', {
  87.         'symbol': '░',
  88.         'color': 'purple',
  89.         'impassable': true,
  90.         'passableFor': ['robot']
  91.     });
  92.  
  93.     map.placeObject(0, map.getHeight() - 1, 'exit');
  94.     map.placeObject(1, 1, 'robot');
  95.     map.placeObject(map.getWidth() - 2, 8, 'blueKey');
  96.     map.placeObject(map.getWidth() - 2, 9, 'barrier');
  97.  
  98.     var autoGeneratedMaze = new ROT.Map.DividedMaze(map.getWidth(), 10);
  99.     autoGeneratedMaze.create( function (x, y, mapValue) {
  100.         // don't write maze over robot or barrier
  101.         if ((x == 1 && y == 1) || (x == map.getWidth() - 2 && y >= 8)) {
  102.             return 0;
  103.         } else if (mapValue === 1) { //0 is empty space 1 is wall
  104.             map.placeObject(x,y, 'block');
  105.         } else {
  106.             map.placeObject(x,y,'empty');
  107.         }
  108.     });
  109. }
  110.  
  111. function validateLevel(map) {
  112.     map.validateExactlyXManyObjects(1, 'exit');
  113.     map.validateExactlyXManyObjects(1, 'robot');
  114.     map.validateAtMostXObjects(1, 'blueKey');
  115. }
  116.  
  117. function onExit(map) {
  118.     if (!map.getPlayer().hasItem('blueKey')) {
  119.         map.writeStatus("We need to get that key!");
  120.         return false;
  121.     } else {
  122.         return true;
  123.     }
  124. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top