I have 2 ships with visible energy bars that reduce when they collide with objects. They bars change colour according to the damage.
The problem is I can't seem to get the energy bars to work independantly of each other. They won't move until one of the ships is destroyed. When there is one ship on screen it works fine
I have been working with the example code I got from DilloDude in my thread about AI. I thought I understood it but clearly I've misunderstood something
First I have a trigger for the ships which gives them full energy
- Code: Select all
Actor * SHIP;
//make a ship, and store it so we can adjust its values
SHIP = CreateActor("ship", "ship1", "(none)", "(none)", 0, 0, false);
SHIP->energy = 100; //energy is declared as Actor Integer )
DestroyActor("Event Actor");
In the ships CREATE code I create the energy bar which uses a CANVAS actor
- Code: Select all
//make energy bar
Actor * NRG = CreateActor("nrgbar", "icon", "Event Actor", "(none)", 0,80, true); //positioned slightly below ship
strcpy(Fleetnrg, NRG->clonename);
stats = _fleet; //set type
xvelocity = plyrspeed;
For the collision I have a simple energy - value command which works as the ships do get destroyed when they are supposed to. It's just the first one will have a full energy bar before it goes
In the energy bars draw code I have the following
- Code: Select all
int i = 0 ;
int xstart =parent.x;
int xend = parent.energy
//check if alive
if (parent.cloneindex < 0)
{
DestroyActor("Event Actor");
}
//First clear bar
r=0;g=0;b=0;i=0;
fleetnrg : setpen(r,g,b,0,i);
for (i=0; i<=5; i++)
{
moveto(xstart,i);
lineto(100, i);
}
//Check energy status and change colour accordingly
if (xend > 50)
{
r=0; g =255; b= 0;i=0;
}
if (xend <= 50)
{
r=255; g =255; b= 0;i=0;
}
if (xend <=25 )
{
r=255; g =0; b= 0;i=0;
}
// Draw Energy
setpen(r,g,b,0,i);
for (i=0; i<=5; i++)
{
moveto(xstart,i);
lineto(xend, i);
}