• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Status effect cooldown icons on UI.

R

Ratatosk

Guest
Hello there,

[edit]: i actually found the error while posting the code. it seems to work now. anyone interested feel free to watch over it anyways and tell me if you like the approach. :D

for my top down shooter project i would like to have temporary effects shown in the UI so that the player knows when a cloaking ability wears off and the ship is gonna be uncloaked or otherwise when a debuff on his speed will wear or something similar.
I would like the icons to appear in order of occurrence and sort themselves automatically once a buff/debuff wears off (so that there are no gaps).
I have come up with a method im not sure if it really works. i have a small bug with icons sometimes not leaving properly or overwriting other ones which should still be in place.

maybe some of the more experienced programmers can watch over my code and give some advice or a link to a more simple and established method. huge thanks in advance:

1. when the player enters cloak, this data is passed to the object that should control the status effect icons

Code:
var loc;
loc=ds_list_size(obj_Control_Player_Status.status_effects)

if loc<7  //just limits the number of icons that can be shown for now
    {
    if ds_list_find_index(obj_Control_Player_Status.status_effects,0)=-1  //if there is not yet a buff of type 0 (cloak) active in the list
        {
           
        ds_list_add(obj_Control_Player_Status.status_effects,0); //add the effect 0 (the cloak) to the next list position
        obj_Control_Player_Status.alarm[0]=duration;  //set the cloak alarm to its duration
        obj_Control_Player_Status.duration[0]=duration; //set the cloak duration in the control obj for reference to the cooldown drawing code (is needed for percentage-calculation for the cooldown wheel, or clock thingy)
        }
    }
2. the creation code of the obj_Control_Player_Status

Code:
xx=128;
yy=684;

status_effects=ds_list_create()

width=sprite_get_width(spr_Status_Effect)/2;


duration[9]=0; // duration 0 is the appropriate duration of the cloaking device, corresponding with alarm[0]
3. this is the Draw UI event of obj_Control_Player_Status

Code:
if !ds_list_empty(status_effects)
    {
    for (i=0;i<ds_list_size(status_effects);i++)
        {
        if ds_list_find_value(status_effects,i)=0 // if on list slot i there is the CLOAK buff
            {
            draw_sprite_ext(spr_Status_Effect,0,xx+(width*i),yy,0.5,0.5,0,c_white,1);
   
            draw_set_color(c_dkgray)
            draw_set_alpha(0.5)
            scr_draw_rectangle_cd(xx+(width*i),yy,xx+(width*i)+24,yy+24,1/duration[0]*alarm[0]) //a custom script by YellowAfterlife if i remember well, that draws a cooldown circle using vectors
            draw_set_color(c_white)
            draw_set_alpha(1)
            }
        if ds_list_find_value(status_effects,i)=1 // if on list slot i there is the SHOCK debuff
            {
            draw_sprite_ext(spr_Status_Effect,1,xx+(width*i),yy,0.5,0.5,0,c_white,1);
   
            draw_set_color(c_dkgray)
            draw_set_alpha(0.5)
            scr_draw_rectangle_cd(xx+(width*i),yy,xx+(width*i)+24,yy+24,1/duration[1]*alarm[1])
            draw_set_color(c_white)
            draw_set_alpha(1)
            }   
        }

    }
4. alarm[0] of obj_Control_Player_Status, this is the CLOAK

Code:
if !ds_list_empty(status_effects)
    {
    for (i=0;i<7;i++)
        {
   
        if ds_list_find_value(status_effects,i)=0 //if we find a CLOAK buff on this list spot
            {
            ds_list_delete(status_effects,i); //delete it so it is not longer drawn
            }
   
        }
    }

lol dudes this is so funny ....

writing this i actually found the mistake in the alarm event ... i didnt check for which list slot i should actually delete the buff/debuff from the list... i formerly just deleted position 0 from the list if alarm 0 would end. well thats awesome. anyways i leave this material here for anyone who is interested and continue testing it myself.

thanks for the spirits who helped me in advance! :D
 
Last edited by a moderator:
Top