Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mfranzs/4c0928a987977e6fa77f to your computer and use it in GitHub Desktop.
Save mfranzs/4c0928a987977e6fa77f to your computer and use it in GitHub Desktop.
Powerup/Boost/Bomb Countdowns Userscript
// ==UserScript==
// @name Powerup/Boost/Bomb Countdowns Userscript
// @include http://tagpro-*.koalabeast.com:*
// @include http://maptest.newcompte.fr:*
// @author GingrbredMan
// @version 1.0
// ==/UserScript==
/*
This userscript will overlay a countdown timer on powerups, boosts, and bombs to let you know when they will respawn.
Due to a limitation in tagpro (to prevent cheating), the system cannot accuractly countdown items that were grabbed more than 10-16 tiles away from the player.
These items appear in red. RED NUMBERS ARE INNACURATE AND ARE ONLY AN ESTIMATE.
Color codes
Number:
Black: Guaranteed to be accurate
Red: Innacurate, but probably will reappear before the counter hits 0
Circles:
White: Powerup
Yellow: Neutral boost
Red: Red boost
Blue: Blue boost
Black: Bomb
Before someone calls me out on it: This code could have been made slightly more concise/efficient... too bad! Time is valuable, efficiency here is less so. :P
*/
tagpro.ready(function () {
var PUP_RESPAWN_TIME=60;
var BOMB_RESPAWN_TIME=30;
var BOOST_RESPAWN_TIME=10;
var TILESIZE=40;
var X_VIEW_DISTANCE=16;
var Y_VIEW_DISTANCE=10;
var PICKUPSIZE=30;
var foundInterests=false;
var tapgroDraw=tagpro.ui.draw;
var interests = [];
var offset = {
x: 0,
y: 0
};
function seconds(){
return (new Date().getTime())/1000;
}
function findInterests(){
foundInterests=true;
for(var x=0;x<tagpro.map.length;x++){
for(var y=0;y<tagpro.map[x].length;y++){
if(isTile(x,y,6)||isTile(x,y,15)||isTile(x,y,14)||isTile(x,y,5)||isTile(x,y,10)){
interests.push(new Tile(x,y));
}
}
}
}
tagpro.ui.draw = function(context) {
if(!foundInterests){
findInterests();
}else{
updateOffset();
checkInterests(context);
tapgroDraw(context);
}
};
function checkInterests(context){
for (var i = 0; i < interests.length; i++) {
var w = interests[i];
if(isTaken(w.x,w.y)&&!w.taken){
w.sure=w.visible;
w.start=seconds();
}
w.taken=isTaken(w.x,w.y);
w.visible=isVisible(w.x,w.y);
w.draw(context, offset);
}
}
function isVisible(x,y){
var px=Math.round(player().x/TILESIZE);
var py=Math.round(player().y/TILESIZE);
if(Math.abs(px-x)>X_VIEW_DISTANCE)return false;
if(Math.abs(py-y)>Y_VIEW_DISTANCE)return false;
return true;
}
function isTaken(x,y){
if(tagpro.map[x][y]==6)return true;
if(isTile(x,y,5)&&tagpro.map[x][y]!=5)return true;
if(isTile(x,y,14)&&tagpro.map[x][y]!=14)return true;
if(isTile(x,y,15)&&tagpro.map[x][y]!=15)return true;
if(isTile(x,y,10)&&tagpro.map[x][y]!=10)return true;
return false;
}
function isTile(x,y,tile){
if(tagpro.map[x][y]==tile){
return true;
}
if ((""+tagpro.map[x][y]).indexOf(".")>-1){
if(parseInt((""+tagpro.map[x][y]).substring(0,(""+tagpro.map[x][y]).indexOf(".")))==tile){
return true;
}
}
return false;
}
function player(){
return tagpro.players[tagpro.playerId];
}
function updateOffset(){
offset.x = viewPort.width/2 - player().x/tagpro.zoom ;
offset.y = viewPort.height/2 - player().y/tagpro.zoom ;
}
//TILE CLASS
var Tile = function (x, y) {
this.x = x;
this.y = y;
this.visible=false;
this.taken=true;
this.sure=false;
this.start=-999;
};
var Timer = function (x, y) {
this.x = x;
this.y = y;
};
Tile.prototype.respawnTime=function(){
if(isTile(this.x,this.y,6)){
return PUP_RESPAWN_TIME;
}else if(isTile(this.x,this.y,10)){
return BOMB_RESPAWN_TIME;
}else{
return BOOST_RESPAWN_TIME;
}
}
Tile.prototype.timeLeft = function(){
return this.respawnTime()-Math.floor(seconds()-this.start);
}
Tile.prototype.displayX=function(){
return this.x*TILESIZE-TILESIZE/2;
}
Tile.prototype.displayY=function(){
return this.y*TILESIZE-TILESIZE/2;
}
Tile.prototype.display=function(){
return (parseInt(this.timeLeft())>0 && isTaken(this.x,this.y));
}
Tile.prototype.draw = function (context, offset) {
if(this.display()){
context.save();
context.translate(this.displayX()/tagpro.zoom+offset.x,this.displayY()/tagpro.zoom+offset.y);
context.scale(1/tagpro.zoom,1/tagpro.zoom);
var radius=(this.respawnTime()-this.timeLeft())/this.respawnTime()*PICKUPSIZE/2;
context.beginPath();
context.arc(TILESIZE/2, TILESIZE/2, radius, 0, 2 * Math.PI, false);
if(isTile(this.x,this.y,6))context.fillStyle="#FFFFFF";
if(isTile(this.x,this.y,5))context.fillStyle="#FFFF00";
if(isTile(this.x,this.y,14))context.fillStyle="#FF0000";
if(isTile(this.x,this.y,15))context.fillStyle="#0000FF";
if(isTile(this.x,this.y,10))context.fillStyle="#000000";
context.fill();
if(this.sure){
if(isVisible(this.x,this.y)){
context.fillStyle = "#000000";
}else{
context.fillStyle = "#666666";
}
}else{
if(isVisible(this.x,this.y)){
context.fillStyle = "#FF0000";
}else{
context.fillStyle = "#AA0000";
}
}
context.strokeStyle = 'white';
context.font="bold 30px Arial";
context.textBaseline="middle";
context.textAlign="center";
context.fillText(this.timeLeft(), TILESIZE/2,TILESIZE/2);
context.strokeText(this.timeLeft(), TILESIZE/2,TILESIZE/2);
context.restore();
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment