Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.30 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. map.defineObject('bridge', {
  100. 'symbol': String.fromCharCode(0x2297),
  101. 'color': 'brown',
  102. 'impassable': function (player) {
  103. return false;
  104. }
  105. });
  106. map.defineObject('laser', {
  107. 'type': 'dynamic',
  108. 'symbol': '.',
  109. 'color': 'green',
  110. 'interval': 100,
  111. 'projectile': true,
  112. 'behavior': function (me) {
  113. me.move('right');
  114. }
  115. });
  116.  
  117.  
  118.  
  119.  
  120. map.placeObject(10,12,'bridge');
  121. map.placeObject(11,12,'bridge');
  122. map.placeObject(12,12,'bridge');
  123. map.placeObject(13,12,'bridge');
  124. map.placeObject(14,12,'bridge');
  125. map.placeObject(15,12,'bridge');
  126. map.placeObject(16,12,'bridge');
  127. map.placeObject(17,12,'bridge');
  128. map.placeObject(18,12,'bridge');
  129. map.placeObject(19,12,'bridge');
  130.  
  131. map.placeObject(20,12,'bridge');
  132. map.placeObject(21,12,'bridge');
  133. map.placeObject(22,12,'bridge');
  134. map.placeObject(23,12,'bridge');
  135. map.placeObject(24,12,'bridge');
  136. map.placeObject(25,12,'bridge');
  137. map.placeObject(26,12,'bridge');
  138. map.placeObject(27,12,'bridge');
  139. map.placeObject(28,12,'bridge');
  140. map.placeObject(29,12,'bridge');
  141.  
  142. map.placeObject(30,12,'bridge');
  143. map.placeObject(31,12,'bridge');
  144. map.placeObject(32,12,'bridge');
  145. map.placeObject(33,12,'bridge');
  146. map.placeObject(34,12,'bridge');
  147. map.placeObject(35,12,'bridge');
  148. map.placeObject(36,12,'bridge');
  149. map.placeObject(37,12,'bridge');
  150. map.placeObject(38,12,'bridge');
  151. map.placeObject(39,12,'bridge');
  152.  
  153. player=map.getPlayer();
  154.  
  155. player.setPhoneCallback(function(p)
  156. {
  157. player = map.getPlayer();
  158. map.placeObject(player.getX()+1, player.getY(), 'laser');
  159. });
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167. }
  168.  
  169. function validateLevel(map) {
  170. // called at start of level and whenever a callback executes
  171. map.validateAtMostXObjects(59, 'block');
  172. map.validateAtMostXObjects(1, 'phone');
  173.  
  174. if (map.countObjects('theAlgorithm') > 0 && map.countObjects('boss') > 0) {
  175. throw "The Algorithm can only be dropped by the boss!";
  176. }
  177.  
  178. // only called at start of level
  179. if (map.isStartOfLevel()) {
  180. map.validateAtMostXDynamicObjects(23);
  181. map.validateNoTimers();
  182. }
  183. }
  184.  
  185. function onExit(map) {
  186. if (!map.getPlayer().hasItem('theAlgorithm')) {
  187. map.writeStatus("You must take back the Algorithm!!");
  188. return false;
  189. } else if (!map.getPlayer().hasItem('phone')) {
  190. map.writeStatus("We need the phone!");
  191. return false;
  192. } else {
  193. return true;
  194. }
  195. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement