powerups.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. /*
  2. * ===========================================================================
  3. *
  4. * Wolf3D Browser Version GPL Source Code
  5. * Copyright (C) 2012 id Software LLC, a ZeniMax Media company.
  6. *
  7. * This file is part of the Wolf3D Browser Version GPL Source Code ("Wolf3D Browser Source Code").
  8. *
  9. * Wolf3D Browser Source Code is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation, either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * Wolf3D Browser Source Code is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License version 2
  20. * along with Wolf3D Browser Source Code. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. * If you have questions concerning this license, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  23. *
  24. * ===========================================================================
  25. */
  26. Wolf.Powerups = (function() {
  27. Wolf.setConsts({
  28. pow_gibs : 0, // 1% if <=10%; SLURPIESND
  29. pow_gibs2 : 1, // 1% if <=10%; SLURPIESND
  30. pow_alpo : 2, // 4% if <100%; HEALTH1SND
  31. pow_firstaid : 3, // 25% if <100%; HEALTH2SND
  32. pow_key1 : 4, // gold key; GETKEYSND
  33. pow_key2 : 5, // silver key; GETKEYSND
  34. pow_key3 : 6, // not used
  35. pow_key4 : 7, // not used
  36. pow_cross : 8, // 100pts; BONUS1SND
  37. pow_chalice : 9, // 500pts; BONUS2SND
  38. pow_bible : 10, // 1000pts; BONUS3SND
  39. pow_crown : 11, // 5000pts; BONUS4SND
  40. pow_clip : 12, // 8bul if <99bul; GETAMMOSND
  41. pow_clip2 : 13, // 4bul if <99bul; GETAMMOSND
  42. pow_machinegun : 14, // machine gun; GETMACHINESND
  43. pow_chaingun : 15, // gatling gun; GETGATLINGSND
  44. pow_food : 16, // 10% if <100%; HEALTH1SND
  45. pow_fullheal : 17, // 99%, 25bul; BONUS1UPSND
  46. pow_25clip : 18, // 25bul if <99bul; GETAMMOBOXSND
  47. pow_spear : 19, // spear of destiny!
  48. pow_last : 20
  49. // add new types <!only!> here (after last)
  50. });
  51. var texture = [
  52. Wolf.SPR_STAT_34, // pow_gibs
  53. Wolf.SPR_STAT_38, // pow_gibs2
  54. Wolf.SPR_STAT_6, // pow_alpo
  55. Wolf.SPR_STAT_25, // pow_firstaid
  56. Wolf.SPR_STAT_20, // pow_key1
  57. Wolf.SPR_STAT_21, // pow_key2
  58. // not used
  59. Wolf.SPR_STAT_20, // pow_key3
  60. Wolf.SPR_STAT_20, // pow_key4
  61. Wolf.SPR_STAT_29, // pow_cross
  62. Wolf.SPR_STAT_30, // pow_chalice
  63. Wolf.SPR_STAT_31, // pow_bible
  64. Wolf.SPR_STAT_32, // pow_crown
  65. Wolf.SPR_STAT_26, // pow_clip
  66. Wolf.SPR_STAT_26, // pow_clip2
  67. Wolf.SPR_STAT_27, // pow_machinegun
  68. Wolf.SPR_STAT_28, // pow_chaingun
  69. Wolf.SPR_STAT_24, // pow_food
  70. Wolf.SPR_STAT_33, // pow_fullheal
  71. // spear
  72. Wolf.SPR_STAT_49, // pow_25clip
  73. Wolf.SPR_STAT_51 // pow_spear
  74. ];
  75. function remove(level, powerup) {
  76. powerup.x = -1;
  77. powerup.y = -1;
  78. }
  79. function addNew(level) {
  80. /*
  81. for (var i = 0;i < level.state.numPowerups; i++ ) {
  82. if (level.state.powerups[i].x == -1 ) {
  83. return level.state.powerups[i];
  84. }
  85. }
  86. */
  87. /*
  88. if (level.state.numPowerups == Wolf.MAX_POWERUPS ) {
  89. return level.state.powerups[0];
  90. }
  91. */
  92. level.state.numPowerups++;
  93. var newp = {
  94. x : -1,
  95. y : -1,
  96. type : 0,
  97. sprite : null
  98. };
  99. level.state.powerups[level.state.numPowerups-1] = newp;
  100. return newp;
  101. }
  102. function reset(level) {
  103. level.state.numPowerups = 0;
  104. level.state.powerups = [];
  105. }
  106. // x,y are in TILES.
  107. function spawn(level, x, y, type) {
  108. var newp = addNew(level);
  109. newp.sprite = Wolf.Sprites.getNewSprite(level);
  110. newp.type = type;
  111. Wolf.Sprites.setPos(level, newp.sprite, Wolf.TILE2POS(newp.x = x), Wolf.TILE2POS(newp.y = y), 0);
  112. Wolf.Sprites.setTex(level, newp.sprite, -1, texture[type]);
  113. level.tileMap[x][y] |= Wolf.POWERUP_TILE;
  114. // good place to update total treasure count!
  115. }
  116. function give(level, player, type) {
  117. var keynames = ["Gold", "Silver", "?", "?"];
  118. switch (type) {
  119. // Keys
  120. case Wolf.pow_key1:
  121. case Wolf.pow_key2:
  122. case Wolf.pow_key3:
  123. case Wolf.pow_key4:
  124. type -= Wolf.pow_key1;
  125. Wolf.Player.giveKey(player, type);
  126. Wolf.Sound.startSound(null, null, 0, Wolf.CHAN_ITEM, "lsfx/012.wav", 1, Wolf.ATTN_NORM, 0);
  127. Wolf.Game.notify(keynames[type] + " key");
  128. break;
  129. // Treasure
  130. case Wolf.pow_cross:
  131. Wolf.Player.givePoints(player, 100);
  132. Wolf.Sound.startSound(null, null, 0, Wolf.CHAN_ITEM, "lsfx/035.wav", 1, Wolf.ATTN_NORM, 0);
  133. if ( ++level.state.foundTreasure == level.state.totalTreasure ) {
  134. Wolf.Game.notify("You found the last treasure!");
  135. }
  136. break;
  137. case Wolf.pow_chalice:
  138. Wolf.Player.givePoints(player, 500);
  139. Wolf.Sound.startSound(null, null, 0, Wolf.CHAN_ITEM, "lsfx/036.wav", 1, Wolf.ATTN_NORM, 0);
  140. if (++level.state.foundTreasure == level.state.totalTreasure) {
  141. Wolf.Game.notify("You found the last treasure!");
  142. }
  143. break;
  144. case Wolf.pow_bible:
  145. Wolf.Player.givePoints(player, 1000);
  146. Wolf.Sound.startSound(null, null, 0, Wolf.CHAN_ITEM, "lsfx/037.wav", 1, Wolf.ATTN_NORM, 0);
  147. if (++level.state.foundTreasure == level.state.totalTreasure) {
  148. Wolf.Game.notify("You found the last treasure!");
  149. }
  150. break;
  151. case Wolf.pow_crown:
  152. Wolf.Player.givePoints(player, 5000);
  153. Wolf.Sound.startSound(null, null, 0, Wolf.CHAN_ITEM, "lsfx/045.wav", 1, Wolf.ATTN_NORM, 0);
  154. if (++level.state.foundTreasure == level.state.totalTreasure) {
  155. Wolf.Game.notify("You found the last treasure!");
  156. }
  157. break;
  158. // Health
  159. case Wolf.pow_gibs:
  160. if (!Wolf.Player.giveHealth(player, 1, 11)) {
  161. return false;
  162. }
  163. Wolf.Sound.startSound(null, null, 0, Wolf.CHAN_ITEM, "lsfx/061.wav", 1, Wolf.ATTN_NORM, 0);
  164. break;
  165. case Wolf.pow_alpo:
  166. if (!Wolf.Player.giveHealth(player, 4, 0)) {
  167. return false;
  168. }
  169. Wolf.Sound.startSound(null, null, 0, Wolf.CHAN_ITEM, "lsfx/033.wav", 1, Wolf.ATTN_NORM, 0);
  170. break;
  171. case Wolf.pow_food:
  172. if (!Wolf.Player.giveHealth(player, 10, 0)) {
  173. return false;
  174. }
  175. Wolf.Sound.startSound(null, null, 0, Wolf.CHAN_ITEM, "lsfx/033.wav", 1, Wolf.ATTN_NORM, 0);
  176. break;
  177. case Wolf.pow_firstaid:
  178. if (!Wolf.Player.giveHealth(player, 25, 0)) {
  179. return false;
  180. }
  181. Wolf.Sound.startSound(null, null, 0, Wolf.CHAN_ITEM, "lsfx/034.wav", 1, Wolf.ATTN_NORM, 0);
  182. break;
  183. // Weapon & Ammo
  184. case Wolf.pow_clip:
  185. if (!Wolf.Player.giveAmmo(player, Wolf.AMMO_BULLETS, 8)) {
  186. return false;
  187. }
  188. Wolf.Sound.startSound(null, null, 0, Wolf.CHAN_ITEM, "lsfx/031.wav", 1, Wolf.ATTN_NORM, 0);
  189. break;
  190. case Wolf.pow_clip2:
  191. if (!Wolf.Player.giveAmmo(player, Wolf.AMMO_BULLETS, 4)) {
  192. return false;
  193. }
  194. Wolf.Sound.startSound(null, null, 0, Wolf.CHAN_ITEM, "lsfx/031.wav", 1, Wolf.ATTN_NORM, 0);
  195. break;
  196. case Wolf.pow_25clip:
  197. if (!Wolf.Player.giveAmmo(player, Wolf.AMMO_BULLETS, 25)) {
  198. return false;
  199. }
  200. Wolf.Sound.startSound(null, null, 0, Wolf.CHAN_ITEM, "lsfx/031.wav", 1, Wolf.ATTN_NORM, 0);
  201. break;
  202. case Wolf.pow_machinegun:
  203. Wolf.Player.giveWeapon(player, Wolf.WEAPON_AUTO );
  204. Wolf.Sound.startSound(null, null, 0, Wolf.CHAN_ITEM, "lsfx/030.wav", 1, Wolf.ATTN_NORM, 0);
  205. Wolf.Game.notify("Machinegun");
  206. break;
  207. case Wolf.pow_chaingun:
  208. Wolf.Player.giveWeapon(player, Wolf.WEAPON_CHAIN );
  209. Wolf.Sound.startSound(null, null, 0, Wolf.CHAN_ITEM, "lsfx/038.wav", 1, Wolf.ATTN_NORM, 0);
  210. Wolf.Game.notify("Chaingun");
  211. player.faceCount = -100;
  212. player.faceGotGun = true;
  213. break;
  214. // Artifacts
  215. case Wolf.pow_fullheal:
  216. // go to 150 health
  217. Wolf.Player.giveHealth(player, 99, 99 );
  218. Wolf.Player.giveAmmo(player, Wolf.AMMO_BULLETS, 25 );
  219. Wolf.Player.giveLife(player);
  220. if (++level.state.foundTreasure == level.state.totalTreasure) {
  221. Wolf.Game.notify("You found the last treasure!");
  222. } else {
  223. Wolf.Game.notify("Full Heal");
  224. }
  225. Wolf.Sound.startSound(null, null, 0, Wolf.CHAN_ITEM, "lsfx/034.wav", 1, Wolf.ATTN_NORM, 0);
  226. Wolf.log("Extra life!");
  227. break;
  228. default:
  229. Wolf.log("Warning: Unknown item type: " + type);
  230. break;
  231. }
  232. Wolf.Game.startBonusFlash();
  233. return true;
  234. }
  235. // x,y are in TILES.
  236. function pickUp(level, player, x, y) {
  237. var i, pow,
  238. p_left = false,
  239. p_pick = false;
  240. for (i=0; i<level.state.numPowerups; i++) {
  241. pow = level.state.powerups[i];
  242. if (pow.x == x && pow.y == y) {
  243. // got a powerup here
  244. if (give(level, player, pow.type)) { //FIXME script
  245. // picked up this stuff, remove it!
  246. p_pick = true;
  247. Wolf.Sprites.remove(level, pow.sprite);
  248. remove(level, pow);
  249. } else {
  250. // player do not need it, so may be next time!
  251. p_left = true;
  252. }
  253. }
  254. }
  255. if(p_left) {
  256. level.tileMap[x][y] |= Wolf.POWERUP_TILE;
  257. } else {
  258. level.tileMap[x][y] &= ~Wolf.POWERUP_TILE;
  259. }
  260. }
  261. return {
  262. spawn : spawn,
  263. reset : reset,
  264. pickUp : pickUp
  265. };
  266. })();