Skip to content

Instantly share code, notes, and snippets.

@omicr0n
Created March 9, 2016 17:14
Show Gist options
  • Save omicr0n/aa6d185d6557b47e8820 to your computer and use it in GitHub Desktop.
Save omicr0n/aa6d185d6557b47e8820 to your computer and use it in GitHub Desktop.
Tagpro Ground Effects
// ==UserScript==
// @name TagPro Ground Effects
// @description Adds a little ground effect on the tiles around players as they move.
// @author OmicroN
// @namespace http://www.reddit.com/user/-omicron-/
// @version 0.1
// @license GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html
// @include http://tagpro-*.koalabeast.com:*
// @include http://tangent.jukejuice.com:*
// @include http://maptest.newcompte.fr:*
// @include http://maptest2.newcompte.fr:*
// ==/UserScript==
tagpro.ready(function(){
var upsp = tagpro.renderer.updatePlayerSpritePosition;
var updatePlayer = tagpro.renderer.updatePlayer;
var effectsLayer;
tagpro.renderer.updatePlayerSpritePosition = function(ball) {
n = {x: 0, y: 0};
n.x = ball.x;
n.y = ball.y;
player = {x: 0, y: 0};
player.x = (n.x * tagpro.zoom);
player.y = (n.y * tagpro.zoom);
if (Math.abs(player.x - ball.x) <= 2 && Math.abs(player.y - ball.y) <= 2) {
if (typeof ball.sprites.groundEffects == 'undefined')
{
ball.sprites.groundEffects = []
}
anchor = {x : parseInt((player.x + 20) / 40) * 40, y : parseInt((player.y + 20) / 40) * 40};
drawPosition = {x : (anchor.x - player.x)/tagpro.zoom + n.x, y : (anchor.y - player.y)/tagpro.zoom + n.y };
player.x += 20;
player.y += 20;
function rect(xOffset, yOffset, alpha, index){
if (ball.dead) return;
var rectPos = {
x : parseInt((player.x + xOffset)/40),
y : parseInt((player.y + yOffset)/40),
drawX : drawPosition.x + xOffset / tagpro.zoom,
drawY : drawPosition.y + yOffset / tagpro.zoom
}
//console.log(rectPos);
if (tagpro.map[rectPos.x] && tagpro.map[rectPos.x][rectPos.y])
if ([0, 1].indexOf(parseInt(tagpro.map[rectPos.x][rectPos.y])) == -1)
{
if (effectsLayer == null) {
effectsLayer = new PIXI.DisplayObjectContainer();
tagpro.renderer.gameContainer.addChildAt(effectsLayer, tagpro.renderer.gameContainer.getChildIndex(tagpro.renderer.layers.midground) + 1);
}
tagproTint = new PIXI.Graphics();
tagproTint.beginFill(ball.flag ? 0x33E31D : (ball.team == 1 ? 0xff6f75 : 0x66adfd), alpha).drawRect(rectPos.drawX , rectPos.drawY , 40 / tagpro.zoom, 40 / tagpro.zoom);
ball.sprites.groundEffects[index] = effectsLayer.addChild(tagproTint);
}
}
for (var id in ball.sprites.groundEffects)
{
effectsLayer.removeChild(ball.sprites.groundEffects[id]);
}
rect(0,0, .2, 0);
rect(-40,0, .125, 1);
rect(40,0,.125,2);
rect(0,-40,.125,3);
rect(0,40,.125,4);
rect(-80,0,.05,5);
rect(80,0,.05,6);
rect(0,-80,.05,7);
rect(0,80,.05,8);
rect(-40,-40,.05,9);
rect(40,-40,.05,10);
rect(40,40,.05,11);
rect(-40,40,.05,12);
}
return upsp.apply(this, arguments);
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment