GEuser's CUSTOMIZABLE GUI LIBRARY: vertical bar

How to find or create sprites, graphics, sounds and music.

GEuser's CUSTOMIZABLE GUI LIBRARY: vertical bar

Postby GEuser » Wed Oct 24, 2012 8:48 pm

Here's the vertical bar (vBar) version. See horizontal version for adding code & user instructions (just replace hbar with vBar in codes and when adding global code).

BASIC INFORMATION

Image

GLOBAL CODE

Code: Select all
void vBar (int barValue, int barMax, int barWidth, int border_R, int border_G, int border_B, int back_R, int back_G, int back_B, int fill_R, int fill_G, int fill_B)
{

    int bar_i=0;

    // Check valid bar values
    if (barValue <0)
    {
            barValue=0; // if value negative set to 0
    }
    else
    {
        if (barValue>barMax)
        {
            barValue=barMax; // if value larger then barMax set to barMax
        }
    }

   // Clear old display
    erase(0,0,0,1);

// --------------------  Create Background ----------------------

    setpen(back_R, back_G, back_B, 0.0, 1);
    moveto(0, barMax+1);

    for(bar_i = barMax+1; bar_i >0; bar_i--)
    {
        moveto(barWidth, bar_i);
        lineto (0, bar_i );
    }

// -------------------- Create Border ---------------------------

    setpen(border_R, border_G, border_B, 0.0, 1);
    moveto (0, 0);
    lineto (barWidth, 0);
    lineto (barWidth, barMax+1);
    lineto (0, barMax+1);
    lineto (0, 0);

// -------------------- Create Value Bar ------------------------------

    setpen(fill_R, fill_G, fill_B, 0.0, 1);
    moveto(1,  barMax);
 
   for(bar_i = 0; bar_i < barValue; bar_i++)
   {
        moveto (1,  barMax-bar_i);
        lineto (barWidth-1, barMax-bar_i);
 
   }
 
}




POSITIONING BAR

For example, if playerShip is your player's ship actor & healthBar is the canvas actor containing your vBar, then:-

Code: Select all

// THIS CODE WOULD GO IN YOUR CANVAS ACTOR'S CREATE EVENT.
// For this positioning to work as intended make sure you resize the canvas as close as possible to dimensions of your bar.

// Place bar CENTRED ABOVE player ship
x=playerShip.x + playerShip.width/2 - healthBar.width/2 - offSet; // you would enter offset manually to fine tune positioning
y=playerShip.y - playerShip.height/2 - healthBar.height/2 - offSet; // you would enter offset manually to fine tune positioning

// ALTERNATIVELY Place bar CENTRED BELOW player ship
x=playerShip.x + playerShip.width/2 - healthBar.width/2 - offSet; // you would enter offset manually to fine tune positioning
y=playerShip.y - playerShip.height/2 + healthBar.height/2 + offSet; // you would enter offset manually to fine tune positioning

// ALTERNATIVELY Place bar  CENTRED LEFT of player ship
x=playerShip.x - playerShip.width/2 - healthBar.width/2;
y=playerShip.y + playerShip.height/2 - healthBar.height/2 - offSet; // you would enter offset manually to fine tune positioning

// ALTERNATIVELY Place bar CENTRED RIGHT of player ship
x=playerShip.x + playerShip.width/2 + healthBar.width/2;
y=playerShip.y + playerShip.height/2 - healthBar.height/2 + offSet; // you would enter offset manually to fine tune positioning



See my hBar post for information on how to get the bars working and change with your game.
http://game-editor.com/forum/viewtopic.php?f=8&t=12376

Now onto next widget, arcBar ( a curved bar, looks much better on sides then vBars). This will keep me busy for awhile.

Goodnight all & happy Game-Editoring!
GEuser
 
Posts: 204
Joined: Thu Jan 05, 2012 3:08 pm
Score: 19 Give a positive score

Return to Game Resources

Who is online

Users browsing this forum: No registered users and 1 guest