Skip to content

Instantly share code, notes, and snippets.

@nabbynz
Last active July 21, 2020 04:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nabbynz/2069ebc0fa085f82539c15595c425cd4 to your computer and use it in GitHub Desktop.
Save nabbynz/2069ebc0fa085f82539c15595c425cd4 to your computer and use it in GitHub Desktop.
Trails
// ==UserScript==
// @name Trails
// @version 0.0.3
// @description Adds particle trails to all players all the time (you need to enable Particles & WebGL in your Settings)
// @author nabby
// @include https://*.koalabeast.com/game
// @include https://*.koalabeast.com/game?*
// @updateURL https://gist.github.com/nabbynz/2069ebc0fa085f82539c15595c425cd4/raw/Trails.user.js
// @downloadURL https://gist.github.com/nabbynz/2069ebc0fa085f82539c15595c425cd4/raw/Trails.user.js
// @grant none
// ==/UserScript==
console.log('START: ' + GM_info.script.name + ' (v' + GM_info.script.version + ' by ' + GM_info.script.author + ')');
//--- start options ---
const showTrails = true;
const showTrails_AllPlayers = true; //if `false` trails will only show on your ball (`true` may crash the game - untested!)
const showSpeedTrails = true;
const showSpeedTrails_Threshold = 1.4; //e.g. 0.8 = @ 80% of your max speed the trail will show. 1.1 = when you're going 10% faster than your normal max speed.
//--- end options ---
tagpro.ready(function() {
const tr = tagpro.renderer;
if (showSpeedTrails) {
tr.createPlayerEmitter = function(player) {
if (tr.options.disableParticles) return;
player.sprites.emitter = new PIXI.particles.Emitter(tr.layers.midground, [tr.particleTexture], tagpro.particleDefinitions.playerEmitter);
player.sprites.emitter.keep = true;
tr.emitters.push(player.sprites.emitter);
player.sprites.emitter.emit = false;
};
tr.updatePlayerEmitter = function(player) {
const t = player.sprite.visible && !player.dead && ((player.speed || 0) > player.ms * showSpeedTrails_Threshold);
const n = t && !player.sprites.emitter.emit;
player.sprites.emitter.emit = t;
player.sprites.emitter.updateOwnerPos(player.x, player.y);
if (n) player.sprites.emitter.resetPositionTracking();
};
tagpro.particleDefinitions.playerEmitter = {
"alpha": {
"start": 0.5,
"end": 0.1
},
"scale": {
"start": 0.2,
"end": 0.1,
"minimumScaleMultiplier": 1
},
"color": {
"start": "#fff700",
"end": "#ff5500"
},
"speed": {
"start": 0,
"end": 0,
"minimumSpeedMultiplier": 1
},
"acceleration": {
"x": 0,
"y": 0
},
"maxSpeed": 0,
"startRotation": {
"min": 0,
"max": 0
},
"noRotation": false,
"rotationSpeed": {
"min": 0,
"max": 0
},
"lifetime": {
"min": 0.2,
"max": 0.8
},
"blendMode": "normal",
"frequency": 0.008,
"emitterLifetime": -1,
"maxParticles": 30,
"pos": {
"x": 20,
"y": 20
},
"addAtBack": false,
"spawnType": "point"
};
}
if (showTrails) {
tagpro.particleDefinitions.trailRed = {
"alpha": {
"start": 0.5,
"end": 0.5
},
"scale": {
"start": 0.2,
"end": 0.15,
"minimumScaleMultiplier": 1
},
"color": {
"start": "#b30000",
"end": "#8a2c2c"
},
"speed": {
"start": 10,
"end": 10,
"minimumSpeedMultiplier": 1
},
"acceleration": {
"x": 0,
"y": 0
},
"maxSpeed": 0,
"startRotation": {
"min": 0,
"max": 0
},
"noRotation": true,
"rotationSpeed": {
"min": 0,
"max": 0
},
"lifetime": {
"min": 0.5,
"max": 1
},
"blendMode": "normal",
"frequency": 0.04,
"emitterLifetime": -1,
"maxParticles": 20,
"pos": {
"x": 20,
"y": 20
},
"addAtBack": false,
"spawnType": "burst",
"particlesPerWave": 1,
"particleSpacing": 0,
"angleStart": 0
};
tagpro.particleDefinitions.trailBlue = {
"alpha": {
"start": 0.5,
"end": 0.5
},
"scale": {
"start": 0.2,
"end": 0.15,
"minimumScaleMultiplier": 1
},
"color": {
"start": "#3333ff",
"end": "#0077ff"
},
"speed": {
"start": 10,
"end": 10,
"minimumSpeedMultiplier": 1
},
"acceleration": {
"x": 0,
"y": 0
},
"maxSpeed": 0,
"startRotation": {
"min": 0,
"max": 0
},
"noRotation": true,
"rotationSpeed": {
"min": 0,
"max": 0
},
"lifetime": {
"min": 0.5,
"max": 1
},
"blendMode": "normal",
"frequency": 0.04,
"emitterLifetime": -1,
"maxParticles": 20,
"pos": {
"x": 20,
"y": 20
},
"addAtBack": false,
"spawnType": "burst",
"particlesPerWave": 1,
"particleSpacing": 0,
"angleStart": 0
};
let dP = tagpro.renderer.drawPlayer;
tr.drawPlayer = function(player) {
if (showTrails_AllPlayers || !showTrails_AllPlayers && (player.id === tagpro.playerId)) {
if (!tr.options.disableParticles && !player.trailEmitter) {
let i = new PIXI.particles.Emitter(tr.layers.midground, [tr.particleTexture], (player.team === 1 ? tagpro.particleDefinitions.trailRed : tagpro.particleDefinitions.trailBlue));
tr.emitters.push(i);
player.trailEmitter = i;
player.trailEmitter.keep = !0;
}
if (player.sprites.actualBall.tileId !== (player.team === 1 ? "redball" : "blueball")) {
let emitterIndex = tr.emitters.indexOf(player.trailEmitter);
if (emitterIndex !== -1) {
tr.emitters.splice(emitterIndex, 1);
}
if (player.trailEmitter) {
player.trailEmitter.destroy();
player.trailEmitter = null;
}
}
if (player.trailEmitter) {
const t = player.sprite.visible && !player.dead;
const n = t && !player.trailEmitter.emit;
player.trailEmitter.emit = t;
player.trailEmitter.updateOwnerPos(player.x, player.y);
if (n) player.trailEmitter.resetPositionTracking();
}
return dP.apply(this, arguments);
} else {
return dP.apply(this, arguments);
}
};
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment