Thread: Gauge thingie
View Single Post
  #1  
Old 04-19-2004, 08:59 PM
Loriel Loriel is offline
Somewhat rusty
Loriel's Avatar
Join Date: Mar 2001
Posts: 5,059
Loriel is a name known to allLoriel is a name known to allLoriel is a name known to allLoriel is a name known to all
Gauge thingie

A nifty analogous display of percentages, pretty customisable I hope. Comments?

The functions:
NPC Code:
function show_scale() {
range = this.ANGLES[1] - this.ANGLES[0];
dist = this.POINTERLENGTH * 1.2;
for (i = this.MIN; i <= this.MAX; i += this.SCALE) {
angle = this.ANGLES[0] + i * range / (this.MAX - this.MIN);
showpoly index, {
sx + sin(angle) * dist * 1.4, sy + cos(angle) * dist * 1.4,
sx + sin(angle+pi*0.01) * dist * 1.3, sy + cos(angle+pi*0.01) * dist * 1.3,
sx + sin(angle) * dist * 1.1, sy + cos(angle) * dist * 1.1,
sx + sin(angle-pi*0.01) * dist * 1.3, sy + cos(angle-pi*0.01) * dist * 1.3
};
changeimgvis index, 4;

colouredness = 1 - abs(gauge - i) / (this.MAX - this.MIN) * this.SCALEFADE;
changeimgcolors index, this.SCALECOLOURS[0]*colouredness,
this.SCALECOLOURS[1]*colouredness,
this.SCALECOLOURS[2]*colouredness,
this.SCALECOLOURS[3];
index ++;
}
}
function show_gauge() {
range = this.ANGLES[1] - this.ANGLES[0];
angle = this.ANGLES[0] + gauge * range / (this.MAX - this.MIN);
showpoly index, {
sx, sy,
sx + sin(angle+pi*0.05) * dist * 0.2, sy + cos(angle+pi*0.05) * dist * 0.2,
sx + sin(angle) * dist * 1.0, sy + cos(angle) * dist * 1.0,
sx + sin(angle-pi*0.05) * dist * 0.2, sy + cos(angle-pi*0.05) * dist * 0.2
};
changeimgvis index, 4;
changeimgcolors index, this.POINTERCOLOURS[0],
this.POINTERCOLOURS[1],
this.POINTERCOLOURS[2],
this.POINTERCOLOURS[3];
index ++;
}



Example usage:
NPC Code:
if (created) {
this.MAX = 100;
this.MIN = 0;
this.SCALE = 10;
this.ANGLES = {pi * 0.5, pi * 1.5};
this.POINTERLENGTH = 32;
this.POINTERCOLOURS = {0.8, 1, 0.2, 1};
this.SCALECOLOURS = {0.8, 1, 0.5, 0.8};
this.SCALEFADE = 0.5;

timeout = 0.05;
}
if (created || timeout) {
index = 200;

sx = 140;
sy = 140;
gauge = abs(mousex - playerx-1.5) * 5;
if (gauge > this.MAX) gauge = this.MAX;
else if (gauge < this.MIN) gauge = this.MIN;

// Calling the magic functions
show_scale();
show_gauge();

hideimgs index, this.lastimgindex;
this.lastimgindex = index;

timeout = 0.05;
}



I figure the api sucks, and how I use gauge as variable name but this.OMGCAPITALS for most things, but dunno.
Reply With Quote