Enemy Color Health Example!!!
![]()
Many people have been asking for enemy health examples. Enemy health is basically variable manipulation. Many times people have not asked for something that expands enemy health, which is enemy coloring. Enemy coloring can be a sign of how close the enemy is near to death. Enemy coloring depends on enemy health. Today we are going to present an easy example on how to make some good enemy health!
First we must create our enemy. all we need in our creation code is:
Creation code:
enhealth=10 /// sets the health
color=c_lime; /// sets the original color
Now here is our step code, the most important code:
//sets the color based on health
if
enhealth>8
{
if
enhealth <10
{
/// sets the health
color=c_lime; /// sets the original color
}}
if
enhealth>6
{
if
enhealth <7.9
{
/// sets the health
color=c_green; /// sets the original color
}}
if
enhealth>4
{
if
enhealth <5.99
{
/// sets the health
color=c_orange; /// sets the original color
}}
if
enhealth>2
{
if
enhealth <3.499
{
/// sets the health
color=c_red; /// sets the original color
}}
if
enhealth>0
{
if
enhealth <1.99
{
/// sets the health
color=c_maroon; /// sets the original color
}}
if
enhealth<.1
{
//if no more health the enemy dies
effect_create_above(ef_explosion,x,y,1,c_red);
instance_destroy();
}
The next to the last code is the collision code with a bullet!
enhealth-=1; ///subtracts health
with other instance_destroy(); ///destroys the bullets
The last code is the Draw Event:
draw_sprite_ext(sprite_index,image_index,x,y,image_xscale,image_yscale,image_angle,color,image_alpha);
//the color is the variable that is the color seen in the step event.
Now thats all you need. This code works with gm7 registered and lite if you tweak it right. The example can be downloaded from one of the link below:
Hopefully this helps whoever is making a game with enemies.
5 Comments »
Leave a comment
-
Archives
- December 2008 (1)
- July 2008 (1)
- June 2008 (12)
- May 2008 (12)
-
Categories
-
RSS
Entries RSS
Comments RSS

You could just change enhealth to Health
It would be better with this…
I know its also about style but it “DOES” make your code more accurate.
if enhealth > 8
and enhealth 6
and enhealth 4
and enhealth 2
and enhealth 0
and enhealth <= 2
{color=c_maroon}
if enhealth <= 0
{
effect_create_above(ef_explosion,x,y,1,c_red)
instance_destroy()
}
I havent read over it yet, hope I can edit after post :p
Yeah great it did fuck up, stupid signs
Ill try a post, but if it wont read all, Ill go crazy:
if enhealth > 8
and enhealth 6
and enhealth < 7.9
{color=c_green}
wtf, it wont post like I type it, jesus kill me