Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.58 KB | None | 0 0
  1. /*****************
  2. * bossFight.js *
  3. *****************
  4. *
  5. * NO FARTHER, DR. EVAL!!!!
  6. * YOU WILL NOT GET OUT OF HERE ALIVE!!!!
  7. * IT'S TIME YOU SEE MY TRUE FORM!!!!
  8. * FACE MY ROBOT WRATH!!!!!
  9. */
  10.  
  11. function startLevel(map) {
  12. map.defineObject('boss', {
  13. 'type': 'dynamic',
  14. 'symbol': '⊙',
  15. 'color': 'red',
  16. 'interval': 200,
  17. 'onCollision': function (player) {
  18. player.killedBy('the boss');
  19. },
  20. 'behavior': function (me) {
  21. if (!me.direction) {
  22. me.direction = 'right';
  23. }
  24. if (me.canMove(me.direction)) {
  25. me.move(me.direction);
  26. } else {
  27. me.direction = (me.direction == 'right') ? 'left' : 'right';
  28. }
  29. if (Math.random() < 0.3) {
  30. map.placeObject(me.getX(), me.getY() + 2, 'bullet');
  31. }
  32. },
  33. 'onDestroy': function (me) {
  34. if (map.countObjects('boss') == 0) {
  35. map.placeObject(me.getX(), me.getY(), 'theAlgorithm');
  36. }
  37. }
  38. });
  39.  
  40. map.defineObject('bullet', {
  41. 'type': 'dynamic',
  42. 'symbol': '.',
  43. 'color': 'red',
  44. 'interval': 100,
  45. 'projectile': true,
  46. 'behavior': function (me) {
  47. me.move('down');
  48. }
  49. });
  50.  
  51. map.placePlayer(0, map.getHeight() - 3);
  52. map.placeObject(map.getWidth() - 1, map.getHeight() - 1, 'exit');
  53.  
  54. // Not so tough now, huh?
  55. map.getPlayer().removeItem('phone');
  56. map.placeObject(map.getWidth() - 1, map.getHeight() - 3, 'phone');
  57.  
  58. map.placeObject(0, map.getHeight() - 4, 'block');
  59. map.placeObject(1, map.getHeight() - 4, 'block');
  60. map.placeObject(2, map.getHeight() - 4, 'block');
  61. map.placeObject(2, map.getHeight() - 3, 'block');
  62. map.placeObject(map.getWidth() - 1, map.getHeight() - 4, 'block');
  63. map.placeObject(map.getWidth() - 2, map.getHeight() - 4, 'block');
  64. map.placeObject(map.getWidth() - 3, map.getHeight() - 4, 'block');
  65. map.placeObject(map.getWidth() - 3, map.getHeight() - 3, 'block');
  66.  
  67. for (var x = 0; x < map.getWidth(); x++) {
  68. map.placeObject(x, 4, 'block');
  69. }
  70.  
  71. map.placeObject(9, 5, 'boss');
  72. map.placeObject(11, 5, 'boss');
  73. map.placeObject(13, 5, 'boss');
  74. map.placeObject(15, 5, 'boss');
  75. map.placeObject(17, 5, 'boss');
  76. map.placeObject(19, 5, 'boss');
  77. map.placeObject(21, 5, 'boss');
  78. map.placeObject(23, 5, 'boss');
  79. map.placeObject(25, 5, 'boss');
  80. map.placeObject(27, 5, 'boss');
  81. map.placeObject(29, 5, 'boss');
  82. map.placeObject(31, 5, 'boss');
  83.  
  84. map.placeObject(10, 6, 'boss');
  85. map.placeObject(12, 6, 'boss');
  86. map.placeObject(14, 6, 'boss');
  87. map.placeObject(16, 6, 'boss');
  88. map.placeObject(18, 6, 'boss');
  89. map.placeObject(20, 6, 'boss');
  90. map.placeObject(22, 6, 'boss');
  91. map.placeObject(24, 6, 'boss');
  92. map.placeObject(26, 6, 'boss');
  93. map.placeObject(28, 6, 'boss');
  94. map.placeObject(30, 6, 'boss');
  95.  
  96.  
  97.  
  98.  
  99. player = map.getPlayer();
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108. function get_dir(mx, my, tx, ty){
  109. var leftd = mx - tx;
  110. var upd = my - ty;
  111. if (leftd == 0) {
  112. if (upd > 0) {
  113. return 'up';
  114. } else if (upd < 0) {
  115. return 'down';
  116. } else {
  117. return;
  118. }
  119. } else if (leftd < 0){
  120. return 'right';
  121. } else {
  122. return 'left';
  123. }
  124. };
  125.  
  126. map.defineObject('DragonUp', {
  127. 'type': 'none',
  128. 'symbol': '⇑',
  129. 'color': '#ff0',
  130. 'impassable': function(ap, bp) {
  131. map.placeObject(12, 10, 'Fire');
  132. return false;
  133. }
  134. });
  135.  
  136. map.defineObject('DragonDown', {
  137. 'type': 'none',
  138. 'symbol': 'l',
  139. 'color': '#ff0',
  140. });
  141. map.defineObject('DragonLeft', {
  142. 'type': 'none',
  143. 'symbol': '<',
  144. 'color': '#ff0',
  145. 'impassable': function(me, player) {return true}
  146. });
  147. map.defineObject('DragonRight', {
  148. 'type': 'none',
  149. 'symbol': '>',
  150. 'color': '#ff0',
  151. 'impassable': function() {return true}
  152. });
  153. map.defineObject('Dragon', {
  154. 'type': 'none',
  155. 'symbol': 'D',
  156. 'color': '#ff0',
  157. });
  158. map.defineObject("Fire", {
  159. 'type': 'dynamic',
  160. 'symbol': '🔥',
  161. 'color' : '#f80',
  162. 'interval': 100,
  163. 'projectile': true,
  164. 'behavior': function (me) {
  165. me.move('up');
  166. }
  167. });
  168.  
  169. map.defineObject('Wall', {
  170. 'type': 'none',
  171. 'symbol': 'W',
  172. 'color': '#ff0',
  173. // (prevents player from drowning in water)
  174. 'impassable': function(me, tagrget) {return true}
  175. });
  176. for (i = 10; i < 30; i++){
  177.  
  178. map.placeObject(i, 15, 'Wall');
  179. }
  180.  
  181. // player.setPhoneCallback(function(){
  182.  
  183. map.placeObject(10 +2, 10 + 2 - 1, 'DragonUp');
  184. map.placeObject(10 +2, 10 + 2 + 1, 'DragonDown');
  185. map.placeObject(10 + 2 - 1, 10 + 2, 'DragonLeft');
  186. map.placeObject(10 + 2 + 1, 10 + 2, 'DragonRight');
  187. map.placeObject(10 + 2, 10 + 2, 'Dragon');
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196. }
  197.  
  198. function validateLevel(map) {
  199. // called at start of level and whenever a callback executes
  200. map.validateAtMostXObjects(59, 'block');
  201. map.validateAtMostXObjects(1, 'phone');
  202.  
  203. if (map.countObjects('theAlgorithm') > 0 && map.countObjects('boss') > 0) {
  204. throw "The Algorithm can only be dropped by the boss!";
  205. }
  206.  
  207. // only called at start of level
  208. if (map.isStartOfLevel()) {
  209. map.validateAtMostXDynamicObjects(23);
  210. map.validateNoTimers();
  211. }
  212. }
  213.  
  214. function onExit(map) {
  215. if (!map.getPlayer().hasItem('theAlgorithm')) {
  216. map.writeStatus("You must take back the Algorithm!!");
  217. return false;
  218. } else if (!map.getPlayer().hasItem('phone')) {
  219. map.writeStatus("We need the phone!");
  220. return false;
  221. } else {
  222. return true;
  223. }
  224. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement