Advertisement
chrahunt

tagpro-ball-timer.user.js

May 19th, 2015
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name          Time On Ball
  3. // @version       0.2
  4. // @include       http://*.koalabeast.com:*
  5. // @include       http://*.jukejuice.com:*
  6. // @include       http://*.newcompte.*
  7. // @author        ballparts & Flail
  8. // ==/UserScript==
  9.  
  10.  
  11. ////////////////////////////
  12. // USER DEFINED VARIABLES //
  13. ////////////////////////////
  14.  
  15. // Color of text - can be hex value or color name (e.g., "white")
  16. var TEXT_COLOR = "white";
  17.  
  18. // Opacity of text - 0 is transparent, 1 is opaque
  19. var TEXT_OPACITY = 0.7;
  20.  
  21. // Size of the timer text font in pixels
  22. var TEXT_SIZE = 15;
  23.  
  24. // Whether to rotate with the player.
  25. var ROTATE = false;
  26.  
  27. ////////////////////////////////
  28. // END USER DEFINED VARIABLES //
  29. ////////////////////////////////
  30.  
  31. var TILE_SIZE = 40;
  32.  
  33. // Wait until the tagpro object exists, and add the function to tagpro.ready
  34. function addToTagproReady(fn) {
  35.     // Make sure the tagpro object exists.
  36.     if (typeof tagpro !== "undefined") {
  37.         tagpro.ready(fn);
  38.     } else {
  39.         // If not ready, try again after a short delay.
  40.         setTimeout(function() {
  41.             addToTagproReady(fn);
  42.         }, 0);
  43.     }
  44. }
  45.  
  46. function waitForId(fn) {
  47.     if (typeof tagpro !== "undefined" && tagpro.playerId) {
  48.         fn();
  49.     } else {
  50.         setTimeout(function() {
  51.             waitForId(fn);
  52.         });
  53.     }
  54. }
  55.  
  56. /**
  57.  * Get text for overlaying on center of tiles.
  58.  * @param {string} [color="#FFFFFF"] - The fill color to use for the text.
  59.  * @return {PIXI.Text} - The created text.
  60.  */
  61. function makeText() {
  62.     var text = new PIXI.Text("", {
  63.         font: "bold " + TEXT_SIZE + "pt Arial",
  64.         fill: TEXT_COLOR,
  65.         stroke: "#000000",
  66.         strokeThickness: 3,
  67.         alpha: TEXT_OPACITY,
  68.         align: "center"
  69.     });
  70.     text.anchor = new PIXI.Point(0.5, 0.5);
  71.     text.visible = false;
  72.     return text;
  73. }
  74.  
  75. addToTagproReady(function() {
  76.     waitForId(function() {
  77.         var text = makeText();
  78.         var sprites = tagpro.players[tagpro.playerId].sprites;
  79.         sprites.timer = text;
  80.         sprites.ball.addChild(sprites.timer);
  81.        
  82.  
  83.         var stdUpdate = tagpro.ui.update;
  84.         tagpro.ui.update = function() {
  85.             stdUpdate.apply(null, arguments);
  86.             var millis = Math.max(0, tagpro.gameEndsAt - Date.now());
  87.             var seconds = Math.floor((millis/1000))%60;
  88.             if (seconds >= 0 && seconds <= 9) {
  89.                 seconds = '0' + seconds;
  90.             }
  91.             text.setText(seconds);
  92.             sprites.timer.x = (TILE_SIZE / 2) - sprites.timer.textWidth / 2;
  93.             sprites.timer.y = (TILE_SIZE / 2) - sprites.timer.textHeight / 2;
  94.             if (ROTATE) {
  95.                 text.rotation = tagpro.players[tagpro.playerId].angle;
  96.             }
  97.         };
  98.     });
  99. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement