Advertisement
Guest User

Browncoat's Mod for Tagpro v3

a guest
Jan 12th, 2015
2,317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.56 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Browncoat's TagPro Mod
  3. // @version 2.0.0
  4. // @description Better particles, drop shadows, spinning options (ball, flair, overlay)
  5. // @include http://*.koalabeast.com:*
  6. // @include http://*.jukejuice.com:*
  7. // @include http://*.newcompte.fr:*
  8. // @author Browncoat
  9. // ==/UserScript==
  10.  
  11. tagpro.ready(function () {
  12.  
  13. // ignore this, options are below
  14. var SpinType = {OFF: 0, WHOLE_BALL: 1, OVERLAY: 2};
  15.  
  16. // OPTIONS
  17.  
  18. // Show a shine image on top of the ball, which won't spin
  19. var showBallShine = true;
  20. var shineUrl = "http://i.imgur.com/YsZccQv.png";
  21.  
  22. /**
  23. * How to handle the ball spinning.
  24. * SpinType.OFF - no spinning
  25. * SpinType.WHOLE_BALL - spin the entire ball as it is on your texture pack
  26. * SpinType.OVERLAY - spin the specified overlay image url.
  27. */
  28. var spinType = SpinType.OVERLAY;
  29.  
  30. // 40x40 image
  31. var spinOverlayUrl = "http://i.imgur.com/yT42PHy.png";
  32.  
  33. // Puts the flair in the middle of the ball
  34. var centerFlair = true;
  35.  
  36. // Spins the flair (only if centered)
  37. var spinFlair = true;
  38.  
  39. // Drop shadows under each ball
  40. var drawDropShadows = true;
  41. var dropShadowUrl = "http://i.imgur.com/0q3VhuI.png";
  42.  
  43. // Ball transparency. 0 = invisible, 100 = opaque
  44. var ballTransparency = 100;
  45.  
  46. // Team colors. Affects speed particles, death particles, score colors. Change if your texture pack is not red/blue
  47. var redTeamColor = "ff0000";
  48. var blueTeamColor = "0000ff";
  49. var redTeamName = "Red";
  50. var blueTeamName = "Blue";
  51.  
  52.  
  53. // END OPTIONS. Only the bravest dare go on.
  54.  
  55.  
  56. var tr = tagpro.renderer;
  57.  
  58. var redColorHex = "#" + redTeamColor;
  59. var blueColorHex = "#" + blueTeamColor;
  60.  
  61. // Team score colors
  62. tagpro.ui.scores = function () {
  63. var n = tagpro.score.r ? tagpro.score.r.toString() : "0";
  64. var r = tagpro.score.b ? tagpro.score.b.toString() : "0";
  65. if (tagpro.ui.sprites.redScore) {
  66. tagpro.ui.sprites.redScore.text != n && tagpro.ui.sprites.redScore.setText(n);
  67. tagpro.ui.sprites.blueScore.text != r && tagpro.ui.sprites.blueScore.setText(r);
  68. } else {
  69.  
  70. var redStroke = "#000000";
  71. if (redColorHex == "#000000") {
  72. redStroke = "#FFFFFF"
  73. }
  74. var blueStroke = "#000000";
  75. if (blueColorHex == "#000000") {
  76. blueStroke = "#FFFFFF"
  77. }
  78.  
  79. tagpro.ui.sprites.redScore = new PIXI.Text(n, {fill: redColorHex, stroke: redStroke, strokeThickness: 2, font: "bold 40pt Arial"});
  80. tagpro.ui.sprites.blueScore = new PIXI.Text(r, {fill: blueColorHex, stroke: blueStroke, strokeThickness: 2, font: "bold 40pt Arial"});
  81. tagpro.ui.sprites.redScore.alpha = .5;
  82. tagpro.ui.sprites.blueScore.alpha = .5;
  83. tagpro.ui.sprites.redScore.anchor.x = 1;
  84. tagpro.ui.sprites.blueScore.anchor.x = 0;
  85. tagpro.renderer.layers.ui.addChild(tagpro.ui.sprites.redScore);
  86. tagpro.renderer.layers.ui.addChild(tagpro.ui.sprites.blueScore);
  87. }
  88. };
  89.  
  90.  
  91. // Particles
  92.  
  93. // https://cloudkidstudio.github.io/PixiParticlesEditor/
  94. tr.particleFireTexture = tr.particleTexture;
  95.  
  96.  
  97. tagpro.particleDefinitions.tagproSparks = {
  98. "alpha": {
  99. "start": 0.98,
  100. "end": 0
  101. },
  102. "scale": {
  103. "start": 0.25,
  104. "end": 0.25,
  105. "minimumScaleMultiplier": 1
  106. },
  107. "color": {
  108. "start": "#7cf575",
  109. "end": "#7cf575"
  110. },
  111. "speed": {
  112. "start": 0,
  113. "end": 0
  114. },
  115. "acceleration": {
  116. "x": 0,
  117. "y": 0
  118. },
  119. "startRotation": {
  120. "min": 0,
  121. "max": 360
  122. },
  123. "rotationSpeed": {
  124. "min": 0,
  125. "max": 0
  126. },
  127. "lifetime": {
  128. "min": 0.1,
  129. "max": 0.9
  130. },
  131. "blendMode": "normal",
  132. "frequency": 0.01,
  133. "emitterLifetime": -1,
  134. "maxParticles": 50,
  135. "pos": {
  136. "x": 20,
  137. "y": 20
  138. },
  139. "addAtBack": true,
  140. "spawnType": "circle",
  141. "spawnCircle": {
  142. "x": 0,
  143. "y": 0,
  144. "r": 20
  145. }
  146. };
  147.  
  148. var redPlayerEmitter = {
  149. "alpha": {
  150. "start": 0.1,
  151. "end": 0
  152. },
  153. "scale": {
  154. "start": 1,
  155. "end": 1,
  156. "minimumScaleMultiplier": 1
  157. },
  158. "color": {
  159. "start": redColorHex,
  160. "end": redColorHex
  161. },
  162. "speed": {
  163. "start": 0,
  164. "end": 0
  165. },
  166. "acceleration": {
  167. "x": 0,
  168. "y": 0
  169. },
  170. "startRotation": {
  171. "min": 0,
  172. "max": 0
  173. },
  174. "rotationSpeed": {
  175. "min": 0,
  176. "max": 0
  177. },
  178. "lifetime": {
  179. "min": 1,
  180. "max": 1
  181. },
  182. "blendMode": "normal",
  183. "frequency": 0.02,
  184. "emitterLifetime": -1,
  185. "maxParticles": 100,
  186. "pos": {
  187. "x": 20,
  188. "y": 20
  189. },
  190. "addAtBack": false,
  191. "spawnType": "point"
  192. };
  193.  
  194. var bluePlayerEmitter = {
  195. "alpha": {
  196. "start": 0.1,
  197. "end": 0
  198. },
  199. "scale": {
  200. "start": 1,
  201. "end": 1,
  202. "minimumScaleMultiplier": 1
  203. },
  204. "color": {
  205. "start": blueColorHex,
  206. "end": blueColorHex
  207. },
  208. "speed": {
  209. "start": 0,
  210. "end": 0
  211. },
  212. "acceleration": {
  213. "x": 0,
  214. "y": 0
  215. },
  216. "startRotation": {
  217. "min": 0,
  218. "max": 0
  219. },
  220. "rotationSpeed": {
  221. "min": 0,
  222. "max": 0
  223. },
  224. "lifetime": {
  225. "min": 1,
  226. "max": 1
  227. },
  228. "blendMode": "normal",
  229. "frequency": 0.02,
  230. "emitterLifetime": -1,
  231. "maxParticles": 100,
  232. "pos": {
  233. "x": 20,
  234. "y": 20
  235. },
  236. "addAtBack": false,
  237. "spawnType": "point"
  238. };
  239.  
  240. tagpro.particleDefinitions.death = {
  241. "alpha": {
  242. "start": 0.6,
  243. "end": 0.3
  244. },
  245. "scale": {
  246. "start": 0.3,
  247. "end": 0.001,
  248. "minimumScaleMultiplier": 1
  249. },
  250. "color": {
  251. "start": "#ffffff",
  252. "end": "#ffffff"
  253. },
  254. "speed": {
  255. "start": 300,
  256. "end": 300
  257. },
  258. "acceleration": {
  259. "x": 0,
  260. "y": 0
  261. },
  262. "startRotation": {
  263. "min": 0,
  264. "max": 360
  265. },
  266. "rotationSpeed": {
  267. "min": 0,
  268. "max": 0
  269. },
  270. "lifetime": {
  271. "min": 0.001,
  272. "max": 0.4
  273. },
  274. "blendMode": "normal",
  275. "frequency": 0.001,
  276. "emitterLifetime": 0.02,
  277. "maxParticles": 50,
  278. "pos": {
  279. "x": 0,
  280. "y": 0
  281. },
  282. "addAtBack": false,
  283. "spawnType": "circle",
  284. "spawnCircle": {
  285. "x": 0,
  286. "y": 0,
  287. "r": 0
  288. }
  289. };
  290.  
  291. tagpro.particleDefinitions.rollingBomb = {
  292. "alpha": {
  293. "start": 0.45,
  294. "end": 0
  295. },
  296. "scale": {
  297. "start": 0.5,
  298. "end": 0.2,
  299. "minimumScaleMultiplier": 1
  300. },
  301. "color": {
  302. "start": "#85888d",
  303. "end": "#100f0c"
  304. },
  305. "speed": {
  306. "start": 0,
  307. "end": 0
  308. },
  309. "acceleration": {
  310. "x": 0,
  311. "y": 0
  312. },
  313. "startRotation": {
  314. "min": 0,
  315. "max": 360
  316. },
  317. "rotationSpeed": {
  318. "min": 0,
  319. "max": 0
  320. },
  321. "lifetime": {
  322. "min": 0.5,
  323. "max": 2
  324. },
  325. "blendMode": "normal",
  326. "frequency": 0.001,
  327. "emitterLifetime": -1,
  328. "maxParticles": 50,
  329. "pos": {
  330. "x": 0,
  331. "y": 0
  332. },
  333. "addAtBack": false,
  334. "spawnType": "circle",
  335. "spawnCircle": {
  336. "x": 20,
  337. "y": 20,
  338. "r": 20
  339. }
  340. };
  341.  
  342. // Override this to have different player emitters for red and blue
  343. tagpro.renderer.createPlayerEmitter = function (player) {
  344. if (tr.options.disableParticles) {
  345. return;
  346. }
  347. var emitter = player.team == 1 ? redPlayerEmitter : bluePlayerEmitter;
  348. player.sprites.emitter = new cloudkid.Emitter(tr.layers.midground, [tr.particleTexture], emitter);
  349. player.sprites.emitter.keep = true;
  350. tr.emitters.push(player.sprites.emitter);
  351. player.sprites.emitter.emit = false;
  352. };
  353.  
  354. // Ensures emitter color is changed if a ball swaps teams
  355. var defaultUpdatePlayerColor = tr.updatePlayerColor;
  356. tr.updatePlayerColor = function (player) {
  357. var color = player.team == 1 ? "red" : "blue";
  358. var tileId = color + "ball";
  359. if (player.sprites.actualBall.tileId != tileId) {
  360. // remove old emitter
  361. tr.emitters.splice(tr.emitters.indexOf(player.sprites.emitter), 1);
  362.  
  363. // create new one
  364. tr.createPlayerEmitter(player);
  365. }
  366.  
  367. defaultUpdatePlayerColor(player);
  368. };
  369.  
  370. // Use custom red/blue colors for the death emitter
  371. var defaultStartDeathEmitter = tr.startDeathEmitter;
  372. tr.startDeathEmitter = function (startColor, stopColor, x, y) {
  373. var isRed = startColor == "ff0000";
  374. var color = isRed ? redTeamColor : blueTeamColor;
  375. defaultStartDeathEmitter(color, stopColor, x, y);
  376. };
  377.  
  378.  
  379. // Override this to add tagpro particles to the foreground, meaning they leave a trail instead of following the player
  380. tr.updateTagpro = function (player) {
  381. /* Updates whether a player should have tagpro. */
  382. if (player.tagpro) {
  383. if (!player.sprites.tagproTint) {
  384. var tint = player.sprites.tagproTint = new PIXI.Graphics();
  385. tint.beginFill(0x00FF00, .35).lineStyle(2, 0x00FF00).drawCircle(20, 20, 19);
  386. player.sprites.ball.addChild(tint);
  387. if (!tr.options.disableParticles) {
  388. player.sprites.tagproSparks = new cloudkid.Emitter(
  389. tr.layers.foreground,
  390. [tr.particleTexture],
  391. tagpro.particleDefinitions.tagproSparks);
  392. player.sprites.tagproSparks.player = player.id;
  393. player.sprites.tagproSparks.keep = true;
  394. tr.emitters.push(player.sprites.tagproSparks);
  395. }
  396. }
  397. if (player.sprites.tagproSparks) {
  398. var emit = !player.dead && player.sprite.visible;
  399. if (emit && !player.sprites.tagproSparks.emit) {
  400. player.sprites.tagproSparks.emit = true;
  401. } else if (!emit && player.sprites.tagproSparks.emit) {
  402. player.sprites.tagproSparks.emit = false;
  403. }
  404. player.sprites.tagproSparks.updateSpawnPos(player.x+20, player.y+20);
  405. }
  406. } else {
  407. if (player.sprites.tagproTint) {
  408. player.sprites.ball.removeChild(player.sprites.tagproTint);
  409. player.sprites.tagproTint = null;
  410. }
  411. if (player.sprites.tagproSparks) {
  412. player.sprites.tagproSparks.emit = false;
  413. }
  414. }
  415. };
  416.  
  417. // Override this to add rb particles to the foreground, meaning they leave a trail instead of following the player
  418. tr.updateRollingBomb = function (player) {
  419. /* Updates whether a player should have rolling bomb.*/
  420. if (player.bomb) {
  421. if (!player.sprites.bomb) {
  422. if (!tr.options.disableParticles) {
  423. player.sprites.rollingBomb = new cloudkid.Emitter(
  424. tr.layers.foreground,
  425. [tr.particleTexture],
  426. tagpro.particleDefinitions.rollingBomb);
  427. tr.emitters.push(player.sprites.rollingBomb);
  428. player.sprites.rollingBomb.keep = true;
  429. }
  430.  
  431.  
  432. var bomb = player.sprites.bomb = new PIXI.Graphics();
  433. bomb.beginFill(0xFFFF00, .6).drawCircle(20, 20, 19);
  434. player.sprites.ball.addChild(bomb);
  435. } else {
  436. player.sprites.bomb.alpha = Math.abs(.6 * Math.sin(performance.now() / 150));
  437. if (player.sprites.rollingBomb) {
  438. var emit = !player.dead && player.sprite.visible;
  439. if (emit && !player.sprites.rollingBomb.emit) {
  440. player.sprites.rollingBomb.emit = true;
  441. } else if (!emit && player.sprites.rollingBomb.emit) {
  442. player.sprites.rollingBomb.emit = false;
  443. }
  444. player.sprites.rollingBomb.updateSpawnPos(player.x, player.y);
  445. }
  446. }
  447. } else {
  448. if (player.sprites.bomb) {
  449. player.sprites.ball.removeChild(player.sprites.bomb);
  450. player.sprites.bomb = null;
  451. }
  452. if (player.sprites.rollingBomb) {
  453. if (player.sprites.rollingBomb instanceof cloudkid.Emitter) {
  454. player.sprites.rollingBomb.emit = false;
  455. } else {
  456. player.sprites.rollingBomb.visible = false;
  457. }
  458. }
  459. }
  460. };
  461.  
  462. // Transparency
  463. if (ballTransparency < 100 && ballTransparency > 0) {
  464. var defaultCreateBallSprite = tr.createBallSprite;
  465. tr.createBallSprite = function (player) {
  466. defaultCreateBallSprite(player);
  467. player.sprites.actualBall.alpha = ballTransparency/100;
  468. };
  469. }
  470.  
  471. // Large alerts (match
  472. tr.largeText = function (text, color) {
  473. if (color == "#ff0000" || color == "#FF0000") {
  474. color = redColorHex;
  475. } else if (color == "#0000ff" || color == "#0000FF") {
  476. color = blueColorHex;
  477. }
  478.  
  479. var stroke = "#000000";
  480. if (color == "#000000") {
  481. stroke = "#FFFFFF";
  482. }
  483.  
  484. if (text == "Red Wins!") {
  485. text = redTeamName + " Wins!";
  486. } else if(text == "Blue Wins!") {
  487. text = blueTeamName + " Wins!";
  488. }
  489.  
  490. return new PIXI.Text(text,
  491. {
  492. font: "bold 48pt arial",
  493. fill: color || "#ffffff",
  494. stroke: stroke,
  495. strokeThickness: 2
  496. });
  497. };
  498.  
  499. // Ball shine & spin
  500.  
  501. var shineTexture = PIXI.Texture.fromImage(shineUrl);
  502. var spinOverlay = PIXI.Texture.fromImage(spinOverlayUrl);
  503. var dropShadow = PIXI.Texture.fromImage(dropShadowUrl);
  504.  
  505. function ensureShadowsLayer() {
  506. if (!tr.layers.shadowLayer) {
  507. tr.layers.shadowLayer = new PIXI.DisplayObjectContainer();
  508. var foregroundIndex = tr.gameContainer.getChildIndex(tr.layers.foreground);
  509. tr.gameContainer.addChildAt(tr.layers.shadowLayer, foregroundIndex);
  510. }
  511. }
  512.  
  513. var defaultUpdatePlayerSpritePosition = tr.updatePlayerSpritePosition;
  514. tr.updatePlayerSpritePosition = function (player) {
  515. // Create shine
  516. if (showBallShine && !player.sprites.shine) {
  517. player.sprites.shine = new PIXI.Sprite(shineTexture);
  518. player.sprites.ball.addChild(player.sprites.shine);
  519. }
  520.  
  521. // Create drop shadow
  522. if (drawDropShadows) {
  523. ensureShadowsLayer();
  524. if (!player.sprites.dropShadow) {
  525. player.sprites.dropShadow = new PIXI.Sprite(dropShadow);
  526. tr.layers.shadowLayer.addChild(player.sprites.dropShadow);
  527. }
  528. player.sprites.dropShadow.x = player.x - 10;
  529. player.sprites.dropShadow.y = player.y - 10;
  530. }
  531.  
  532. if (spinType == SpinType.WHOLE_BALL) {
  533. // Set rotation anchor
  534. if (!player.sprites.actualBall.anchor.x) {
  535. player.sprites.actualBall.anchor.x = 0.5;
  536. player.sprites.actualBall.anchor.y = 0.5;
  537. player.sprites.actualBall.x = 20;
  538. player.sprites.actualBall.y = 20;
  539. }
  540.  
  541. // Set rotation
  542. player.sprites.actualBall.rotation = player.angle;
  543. } else if (spinType == SpinType.OVERLAY) {
  544. if (!player.sprites.spinOverlay) {
  545. player.sprites.spinOverlay = new PIXI.Sprite(spinOverlay);
  546. player.sprites.ball.addChild(player.sprites.spinOverlay);
  547. player.sprites.spinOverlay.anchor.x = 0.5;
  548. player.sprites.spinOverlay.anchor.y = 0.5;
  549. player.sprites.spinOverlay.x = 20;
  550. player.sprites.spinOverlay.y = 20;
  551. }
  552. player.sprites.spinOverlay.rotation = player.angle;
  553. }
  554.  
  555. defaultUpdatePlayerSpritePosition(player);
  556. };
  557.  
  558. // Flair
  559. if (centerFlair) {
  560. tr.drawFlair = function (player) {
  561. /* Draws the player's flair if it doesn't exist.
  562. * @param player {object} The player object.
  563. * */
  564. if (player.flair) {
  565. if (!player.sprites.flair) {
  566. var cacheKey = "flair-" + player.flair.x + "," + player.flair.y;
  567. var flairTexture = tr.getFlairTexture(cacheKey, player.flair);
  568. player.sprites.flair = new PIXI.Sprite(flairTexture);
  569. player.sprites.flair.x = 20;
  570. player.sprites.flair.y = 20;
  571. player.sprites.flair.anchor.x = 0.5;
  572. player.sprites.flair.anchor.y = 0.5;
  573. player.sprites.info.addChild(player.sprites.flair);
  574. }
  575. if (spinFlair) {
  576. player.sprites.flair.rotation = player.angle;
  577. }
  578. }
  579. if (!player.flair && player.sprites.flair) {
  580. player.sprites.info.removeChild(player.sprites.flair);
  581. }
  582. };
  583. }
  584.  
  585. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement