Making a Health Bar - Tutorial

Learn how to make certain types of games and use gameEditor.

GMGE

Postby diduknow » Sat Aug 27, 2005 8:11 am

You can make a healthbar in one line of code in GM
GEISGOODANDSOISGM
WHYAREYOUSOANTIGM?
diduknow
 
Posts: 8
Joined: Sat Aug 27, 2005 7:37 am
Score: 0 Give a positive score

Re: GMGE

Postby Joshua Worth » Sat Aug 27, 2005 9:14 am

diduknow wrote:You can make a healthbar in one line of code in GM
Quit it about GM. And besides, GE looks nicer, and uses a extremely good programming language called C, and it is obviously much better than whatever :cry: GM :cry: uses!
Stay sweet
User avatar
Joshua Worth
 
Posts: 515
Joined: Tue Jul 19, 2005 12:00 am
Location: Stralia
Score: 5 Give a positive score

Postby diduknow » Sat Aug 27, 2005 9:56 am

the scripting language GM uses is very very close to C, same syntax. but you dont have to write miles of code to make a healthbar.
Game Editor implements a C-like script language

that is from the documentation. so i guess the script isnt quite C now, is it?
GEISGOODANDSOISGM
WHYAREYOUSOANTIGM?
diduknow
 
Posts: 8
Joined: Sat Aug 27, 2005 7:37 am
Score: 0 Give a positive score

Postby ondy1985 » Sat Aug 27, 2005 11:01 am

GE's scripting language is very very similar to the C syntax too. One could say they are almost identical, except for minor differencies. I have both GE and GM installed on my computer. Both tools are great and I admire their creators. But I would probably never use either of them to create Win32 game, because I like to do my own game engines in DirectX 9.0 with Visual C++. I don't know anything about creating games for PocketPC. And that's where it comes to GE as it can export games for PocketPC as well. PocketPC market is growing fast and GE is the easiest way to 'jump in'.

I bet all GE users know about GM but they decided to use GE for some reason. I wonder how many GM users know GE and still use GM...
User avatar
ondy1985
 
Posts: 99
Joined: Thu May 05, 2005 7:43 pm
Location: Slovakia
Score: 1 Give a positive score

Postby Joshua Worth » Sat Aug 27, 2005 11:04 am

Replacement
Last edited by Joshua Worth on Thu Jan 26, 2006 11:25 pm, edited 1 time in total.
Stay sweet
User avatar
Joshua Worth
 
Posts: 515
Joined: Tue Jul 19, 2005 12:00 am
Location: Stralia
Score: 5 Give a positive score

Postby Game A Gogo » Sat Aug 27, 2005 11:33 am

Joshua Worth wrote:Your signature should say "GERULES GMSUX". And this forum is for game editor only, so get out!

you said it man :wink:
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Postby bkelynch » Wed Jan 25, 2006 10:06 pm

I gotta problem here...when I typed in the code in script editor, and clicked on immediete action, an error window came up with this in it:

error

Error line 2: Illegal function definition in ex371229927689
Error line 17: Undeclared Identifier UpdateHealthBar
Error line 24: Undeclared Identifier UpdateHealthBar
Error line 26: Expected ;

I copied the code you had written and pasted it onto script editor, so it is exactly the same as the code you had posted.
bkelynch
 
Posts: 73
Joined: Sun Dec 04, 2005 7:48 pm
Score: 0 Give a positive score

Postby makslane » Wed Jan 25, 2006 11:45 pm

You need put this functions in the Global Code editor
Game Editor is an open source game creator software that's wants to pay it's developers to keep evolving.
If you like Game Editor, make a review!
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby Diana Kennedy » Thu Jan 26, 2006 10:40 am

Game a Gogo wrote:
Joshua Worth wrote:Your signature should say "GERULES GMSUX". And this forum is for game editor only, so get out!

you said it man :wink:


Yup: I don't think it is very respectful to carry ones like for the concurrent in this forum.
User avatar
Diana Kennedy
 
Posts: 257
Joined: Wed Dec 07, 2005 12:34 am
Location: France, where Presidents who got shot in Texas do exile ;-)
Score: 0 Give a positive score

Postby Game A Gogo » Thu Jan 26, 2006 8:39 pm

now, im a change man, and i know every corner of GM, and its pretty good, but i tink GE is way better, for me eventully.
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Postby next2sin » Thu Apr 20, 2006 4:06 am

how would you make the health bar change when it actor collides with another actor?
next2sin
 
Posts: 3
Joined: Tue Apr 11, 2006 1:01 am
Score: 0 Give a positive score

Postby DilloDude » Thu Apr 20, 2006 4:20 am

Use
Code: Select all
ChangeHealth(-5);
(or whatever value you want)
on collision.
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Re: Making a Health Bar - Tutorial

Postby DarkParadox » Thu Mar 01, 2007 12:26 am

ondy1985 wrote:The idea
I found several threads here discussing health bars (or health meters, call it whatever you want) with no satysfying answers on how to do this, so here is my answer.
The aim is to create a bar that will reflect the players health, ammunition or whatever you want, and not have dozens of actors to do that. I'm going to introduce the way I used in my upcoming space shooting game.

1)
It may sound a bit strange, but we will use one text actor for this. First, we need a bitmap "font" that will make the health bar.
Like this one that I have created: Image

2)
Now we have to create the actor in GE. Let's name it "health_bar". Don't add any animations. Click on the Text button in Actor Properties. Now click the New Font button. We find the file with our "font" and set it's properties. The initial character will be 0 and the number of characters is 3. You can write some text into the actor (but remember to use only 0, 1 and 2 characters) to see if it works fine.

3)
Now we need the bar to reflect the player's health. Create "g_PlayerHealth" variable in 'Variables' and make it Global Integer. We will write som simple functions in 'Global Code' to easily change the g_PlayerHealth value and show it via the health bar at the same time.

Code: Select all
void UpdateHealthBar()
{
    int i;
    strcpy(health_bar.text,"");
    for (i=0; i<g_PlayerHealth; i++)
        {
            if (i<=5) strcat(health_bar.text, "0");
            if ((i>5)&&(i<=15)) strcat(health_bar.text, "1");
            if (i>15) strcat(health_bar.text, "2");
        }
}

void ChangeHealth(int modifier)
{
    g_PlayerHealth += modifier;
    if (g_PlayerHealth > 25) g_PlayerHealth = 25;
    if (g_PlayerHealth < 0) g_PlayerHealth = 0;
    UpdateHealthBar();
}

void SetHealth(int value)
{
    g_PlayerHealth = value;
    if (g_PlayerHealth > 25) g_PlayerHealth = 25;
    if (g_PlayerHealth < 0) g_PlayerHealth = 0;
    UpdateHealthBar();
}


We will now have a closer look on this three functions;
SetHealth function sets the player health to the value passed as it's parameter (int value). If the value is higher than maximum allowed (25 in my case), players health is set to the maximum. If it is lower that allowed minimum, it is set to the minimum (0 in my case). Then the UpdateHealthBar function is called.

ChangeHealth function works the same way the SetHealth function works, but instead of setting the g_PlayerHealth variable to have the value of the passed parameter (int modifier), it just adds the modifier to the current g_PlayerHealth value. Be the modifier -1, it substracts 1 point of health, be it 2, it adds 1 to the health value, but will never cross behind the minimum and maximum allowed values. Then UpdateHealthBar function is called.

UpdateHealthBar is the most important part, as it makes the health bar show the value of our g_PlayerHealth variable. You can see, there is a simple FOR cycle running g_PlayerHealth-times (so if we have g_PlayerHealth = 3, the loop will run 3 times). Just before the cycle, we erase everything in the text property of our "health_bar" actor. Than in each cycle, we write new character to the string so in the end, so be the g_PlayerHealth variable set to 3, we would have 3 characters in 'health_bar.text' string. As you can see, I use 3 different characters, so the bar will be red on one end, yellow in the middle and green on the other end, so it looks cool.

4)
We now have everything set up. In the game, we can just call ChangeHealth(modifier) or SetHealth(value) function and the health bar will react. Now, when the g_PlayerHealth variable has the value of 25, the bar looks like this:Image

Last words
Although my english is poor I hope you have understood the basics of creating a health bar. If not, just post here and I will try to explain it better.

I don't say that this is the best way how to do that, it's just the best I came up with.

it says to me
    illegal function definition in ex87926354810920
    undeclared indentifier UpdateHealthBar
[/list]
User avatar
DarkParadox
 
Posts: 457
Joined: Mon Jan 08, 2007 11:32 pm
Location: USA, Florida.
Score: 84 Give a positive score

Postby makslane » Thu Mar 01, 2007 12:34 am

Put the code for the UpdateHealthBar function in the Global Code editor.
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby diablos-bud » Thu Aug 16, 2007 5:13 pm

So does this health bar when you collide with another actor take away some health (and if it does how much health)?
diablos-bud
 
Posts: 10
Joined: Wed Aug 15, 2007 2:07 am
Score: 0 Give a positive score

PreviousNext

Return to Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest