Animation Code

Started by
4 comments, last by Fred304 17 years, 11 months ago
ok well it's not really a keyword, but i need help putting the algorithm together. basically in my head the code should go like this:

else if (!facing_left) 
        {
            //change the animation from standing to shooting
            sprite_index = PMbackLBlast; 
            //speed at which animation should cycle; < 1 means slower cycle
            image_speed = 0.75;
            //image_index holds the animation cell index of the current one shown
            when (image_index == 11) 
            {
                PMBB = instance_create(x-5, y-32, PMBackBullet);
                PMBB.sprite_index = PMBackRBullet;
                PMBB.direction = 0;
            }
        }
        //keeps gun from firing before it's time
        backBlastReady = false;
        //sets timer for variable above to be true.
        //in this case every 20 frames or 3 bullets a second. 
        alarm[1] = 20;
} //ending outer if block
any ideas? edit: i solved the problem. i had to make it so it got a range of indexes namely:
if (image_index >= 11 && image_index <= 21) ... 
those are the cells of the animation that show the arm raised. but any suggestions to prove on this is more than welcomed. cuz i'm pretty sure this isn't the best way. edit2: added shooting animation code for PharaohMan. edit3: thread formerly: "coming up with an equivalent to the when keyword" [Edited by - Alpha_ProgDes on May 7, 2006 2:11:21 PM]

Beginner in Game Development?  Read here. And read here.

 

Advertisement
I'm sorry, I'm not understanding you. What is the difference between "when" and "if"? What should be the functionality of the code?
Maybe he wants the operation in the block to be queued and triggered asynchronously when the condition becomes true.

Spawn a new thread, poll the variable.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
@Sneftel: well the animation is in two parts. basically the sprite has his arm lowered then raises it and then a blast (bullet) is supposed to shoot out. putting an if in place of the when shows the shooting animation but no bullets are coming out.

so i want it so when the animation cycle gets to the cell that shows the character's arm raised, the bullet is created and then shot out. also synched so the bullet only shoots when the arm is raised.

i hope that made my situation clearer.

@Fruny: I'm using Game Maker's scripting language so no threads [sad]

@at everybody: there is no when keyword, i'm just using it as pseudo code to express what i want to happen in the code.

Beginner in Game Development?  Read here. And read here.

 

ok. here's the code for my bad guy sprite when he needs to shoot.
if (abs(x-MegaMegaMan.x) <= 256) {         var PMB;    if (readyToShoot)     {        if (facing_left)         {            if (instance_exists(PMbullet))            {                image_index = 11;            }            else             {                sprite_index = PMfrontLBlast;            }            if (image_index >= 11 && image_index <= 22)            {                PMB = instance_create(x+9, y+14, PMbullet);                PMB.direction = 180;            }                    }        else if (!facing_left)         {            if (instance_exists(PMbullet))            {                image_index = 11;            }            else             {                sprite_index = PMfrontRBlast;            }            if (image_index >= 11 && image_index <= 22)            {                PMB = instance_create(x+22, y+14, PMbullet);                PMB.direction = 0;            }        }                readyToShoot = false;        alarm[0] = 10;               }}else {     var PMBB;    if (backBlastReady)     {        if (facing_left)         {            sprite_index = PMbackRBlast;            image_speed = 0.75;            if (image_index >= 0 && image_index <= 10)            {                PMBB = instance_create(x+5, y-32, PMBackBullet);                PMBB.sprite_index = PMBackLBullet;                PMBB.direction = 180;            }        }        else if (!facing_left)         {            sprite_index = PMbackLBlast;            image_speed = 0.75;            if (image_index >= 11 && image_index <=21)             {                PMBB = instance_create(x-5, y-32, PMBackBullet);                PMBB.sprite_index = PMBackRBullet;                PMBB.direction = 0;            }        }        backBlastReady = false;        alarm[1] = 20;            }} 

Granted this is using the Game Maker Scripting Language but it should be to easy to follow if you program in C or C++. So my question is: "is this ugly"? if yes, what can I do to clean it up?

Beginner in Game Development?  Read here. And read here.

 

replace "else if (!facing_left)" by "else".

This topic is closed to new replies.

Advertisement