Last active
September 19, 2022 00:24
-
-
Save KableM/a0ff93b44617ff5cd602 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name TagPro ProSplats | |
// @version 1.0.1 | |
// @description Animated directional splats | |
// @include http://tagpro-*.koalabeast.com:* | |
// @include http://tangent.jukejuice.com:* | |
// @include http://*.newcompte.fr:* | |
// @author Browncoat | |
// ==/UserScript== | |
tagpro.ready(function () { | |
// ---------- USER OPTIONS ---------- | |
var particlesPerSplat = 50; // Number of splat particles per splat. Cool kids use 1000 | |
var spread = 1; // Determines the size of the area a splat will cover | |
var particleScale = 1; // Size of an individual splat particle | |
var splatLifetime = 60; // Time in seconds before a splat is removed. Set to 0 for infinite lifetime | |
var fadeTime = 10; // Time in seconds before a splat fades out before being removed | |
var redTeamColor = 0xFF0000; // Color of the red team splats. Default = 0xFF0000 White = 0xFFFFFF. Borgen's seaweed green = 0x17A98C | |
var blueTeamColor = 0x0000FF; // Color of the blue team splats. Default = 0x0000FF Black = 0x000000. Borgen's seaweed blue = 0x3A6B9B | |
// ---------- END USER OPTIONS ---------- | |
var splats = []; | |
var splatsLayer; | |
tagpro.renderer.addSplat = function (x, y, team, showDeath) { | |
// don't draw default splat | |
}; | |
var updatePlayer = tagpro.renderer.updatePlayer; | |
tagpro.renderer.updatePlayer = function (player) { | |
updatePlayer(player); | |
if (player.deadLastFrame == undefined) { | |
player.deadLastFrame = player.dead; | |
} | |
if (!player.deadLastFrame && player.dead) { | |
createSplat(player); | |
} | |
player.deadLastFrame = player.dead; | |
if (!player.dead) { | |
player.lastAliveXSpeed = player.lx; | |
player.lastAliveYSpeed = player.ly; | |
} | |
}; | |
function createSplat(player) { | |
var x = player.x + 20; | |
var y = player.y + 20; | |
var xSpeed = player.lastAliveXSpeed; | |
var ySpeed = player.lastAliveYSpeed; | |
log(xSpeed + ", " + ySpeed); | |
var color = player.team == 1 ? redTeamColor : blueTeamColor; | |
var splat = new PIXI.DisplayObjectContainer(); | |
splat.time = splatLifetime; | |
for (var i = 0; i < particlesPerSplat; i++) { | |
var particle = new Particle(x, y, xSpeed, ySpeed, color); | |
splat.addChild(particle.sprite); | |
} | |
splats.push(splat); | |
if (splatsLayer == null) { | |
splatsLayer = new PIXI.DisplayObjectContainer(); | |
tagpro.renderer.gameContainer.addChildAt(splatsLayer, tagpro.renderer.gameContainer.getChildIndex(tagpro.renderer.layers.midground) + 1); | |
log("Splats layer created"); | |
} | |
splatsLayer.addChild(splat); | |
} | |
if (splatLifetime > 0) { | |
function tick() { | |
for (var i = 0; i < splats.length; i++) { | |
var splat = splats[i]; | |
if (--splat.time == 0) { | |
fadeOut(splat); | |
} | |
} | |
} | |
setInterval(tick, 1000); | |
} | |
function fadeOut(splat) { | |
var f = function () { | |
splat.alpha -= 16 / (fadeTime * 1000); | |
if (splat.alpha <= 0) { | |
splatsLayer.removeChild(splat); | |
splats.splice(splats.indexOf(splat), 1); | |
log("splat removed"); | |
} else { | |
setTimeout(f, 16); | |
} | |
}; | |
f(); | |
} | |
function log(message) { | |
console.log("[PROSPLATS] " + message); | |
} | |
// Particle class | |
var Particle = function (baseX, baseY, baseXSpeed, baseYSpeed, color) { | |
// pick random position within a ball | |
var x = baseX + Math.random() * 40 - 20; | |
var y = baseY + Math.random() * 40 - 20; | |
// angle determined by position | |
this.angle = -Math.atan2(x - baseX, y - baseY); | |
// speed determined by baseSpeed | |
var baseComponent = spread * dotProduct(x - baseX, y - baseY, baseXSpeed, baseYSpeed); | |
var speed = Math.random() * 5 + 5; | |
var minSpeed = 1; | |
if (speed + baseComponent < minSpeed) { | |
baseComponent = minSpeed - speed; | |
} | |
speed += baseComponent; | |
var this_ = this; | |
this.color = color; | |
this.sprite = createSprite(); | |
this.airTime = 2; | |
this.inAir = true; | |
this.xSpeed = -Math.sin(this.angle) * speed; | |
this.ySpeed = Math.cos(this.angle) * speed; | |
this.sprite.position.x = x; | |
this.sprite.position.y = y; | |
function createSprite() { | |
var sprite = new PIXI.Graphics(); | |
sprite.lineStyle(0); | |
sprite.beginFill(color, 0.5); | |
sprite.drawEllipse(0, 0, 4 * particleScale, 8 * particleScale); | |
sprite.endFill(); | |
sprite.rotation = this_.angle; | |
sprite.scale.x = Math.random() * 0.9 + 0.1; | |
sprite.scale.y = sprite.scale.x; | |
return sprite; | |
} | |
function update() { | |
if (this_.inAir) { | |
this_.airTime--; | |
if (this_.airTime <= 0) { | |
this_.inAir = false; | |
} | |
this_.sprite.position.x += this_.xSpeed; | |
this_.sprite.position.y += this_.ySpeed; | |
setTimeout(update, 16); | |
} | |
} | |
setTimeout(update, 16); | |
}; | |
function dotProduct(x1, y1, x2, y2) { | |
return (x1 * x2) + (y1 * y2); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment