Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   Cooldown display. (https://forums.graalonline.com/forums/showthread.php?t=134267206)

DrakilorP2P 10-04-2012 08:11 PM

Cooldown display.
 
1 Attachment(s)
Looks like this:
Attachment 55119
Imagine that the chest is a skill icon and has the number of seconds left on the cooldown on it.

The code plus example of use (weapon script):
PHP Code:

//#CLIENTSIDE

function onCreated()
{
  
this.skillIconImg findimg(200);
  
with (this.skillIconImg) {
    
this.image "chest.png";
    
this.int(screenwidth 16);
    
this.int(screenheight 16);
    
this.layer 4;
  }
  
  
this.cooldownImg findimg(201);
  
with (this.cooldownImg) {
    
this.red 1;
    
this.green 1;
    
this.blue 1;
    
this.alpha 0.75;
    
this.mode 2;
    
this.layer 5;
  }
  
  
this.trigger("onTimeout"null);
}

function 
onTimeout()
{
  
this.cooldownProgress -= 0.01;
  if (
this.cooldownProgress 0this.cooldownProgress += 1;
  
  
this.cooldownImg.polygon this.getCooldownPolygon(this.cooldownProgress);
  for (
temp.0temp.this.cooldownImg.polygon.size(); temp.+= 2) {
    
this.cooldownImg.polygon[temp.0] *= 32;
    
this.cooldownImg.polygon[temp.0] += this.skillIconImg.x;
    
    
this.cooldownImg.polygon[temp.1] *= 32;
    
this.cooldownImg.polygon[temp.1] += this.skillIconImg.y
  }
  
  
setTimer(0.05);
}

//temp.progress goes from 0.0 to 1.0, where 0.0 is no cooldown and 1.0 is full cooldown.
//Returns an array compatible with TShowImg.polygon with coordinates ranging from (0, 0) to (1, 1).
function getCooldownPolygon(temp.progress)
{
  
temp.angleInDegrees temp.progress 360;
  
  if (
temp.angleInDegrees <= 0) return null;
  if (
temp.angleInDegrees >= 360) return {0.00.01.00.01.01.00.01.0};
  
  
temp.polygon = {
    
0.50.5,
    
0.50.0
  
};
  
  
temp.degtorad(90 temp.angleInDegrees);
  
temp.dx = +cos(temp.a);
  
temp.dy = -sin(temp.a);
  
  if (
temp.angleInDegrees 0) {
    if (
temp.angleInDegrees 45) {
      
temp.polygon.add(0.5 - (temp.dx/temp.dy) * 0.5);
      
temp.polygon.add(0);
    }
    else {
      
temp.polygon.add(0.0);
      
temp.polygon.add(0.0);
    }
  }
  
  if (
temp.angleInDegrees >= 45) {
    if (
temp.angleInDegrees 135) {
      
temp.polygon.add(0.0);
      
temp.polygon.add(0.5 - (temp.dy/temp.dx) * 0.5);
    }
    else {
      
temp.polygon.add(0.0);
      
temp.polygon.add(1.0);
    }
  }
  
  if (
temp.angleInDegrees >= 135) {
    if (
temp.angleInDegrees 225) {
      
temp.polygon.add(0.5 + (temp.dx/temp.dy) * 0.5);
      
temp.polygon.add(1.0);
    }
    else {
      
temp.polygon.add(1.0);
      
temp.polygon.add(1.0);
    }
  }
  
  if (
temp.angleInDegrees >= 225) {
    if (
temp.angleInDegrees 315) {
      
temp.polygon.add(1.0);
      
temp.polygon.add(0.5 + (temp.dy/temp.dx) * 0.5);
    }
    else {
      
temp.polygon.add(1.0);
      
temp.polygon.add(0.0);
    }
  }
  
  if (
temp.angleInDegrees >= 315) {
    if (
temp.angleInDegrees 360) {
      
temp.polygon.add(0.5 - (temp.dx/temp.dy) * 0.5);
      
temp.polygon.add(0.0);
    }
    else {
      
temp.polygon.add(0.5);
      
temp.polygon.add(0.0);
    }
  }
  
  return 
temp.polygon;


The important code with all the math in it is the getCooldownPolygon function.
Assembly required. "Batteries not included."

cbk1994 10-04-2012 09:39 PM

Tig did something almost identical for Kingdoms iPhone. A neat effect.

Crow 10-04-2012 10:39 PM

At some point, Blizzard added a very helpful line to this concept, which was being used in WoW before already. Kind of like the hand of a clock. Helps with visibility on some icons/backgrounds. Would work well on this, too, I believe. Nice work regardless, though.

Crono 10-04-2012 11:22 PM

Lovely.

smirt362 10-05-2012 12:22 AM

Neato!

Cloven 10-05-2012 01:38 AM

Yeah, I dig it. Clean, logical, effective...

Tigairius 10-05-2012 03:47 AM

Nice work.

Quote:

Originally Posted by Crow (Post 1705115)
At some point, Blizzard added a very helpful line to this concept, which was being used in WoW before already. Kind of like the hand of a clock. Helps with visibility on some icons/backgrounds. Would work well on this, too, I believe. Nice work regardless, though.

Cool idea.


All times are GMT +2. The time now is 05:42 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.