The Dink Network

Code trouble please help

April 7th 2007, 06:08 PM
wizardb.gif
Endy
Peasant He/Him United States
 
I'm trying to make a Dink enemy, just having trouble with animating his firing sequences. The arrows appear okay, but his actual firing sequence is way too fast.

Hope someone can help,

Endy

P.S. Coppied Arrow-05 to Arrow-09 for easier coding.

// "Enemy Shoot Deluxe 2.0" Moded
// Supposed to allow Dink to be your enemy, just doesn't work too great...

void main( void )
{
init("load_sequence_now graphics\dink\bow\walk\d-bw1- 71 43 30 84 -14 -10 14 10");
init("load_sequence_now graphics\dink\bow\walk\d-bw2- 72 43 29 86 -21 -10 19 10");
init("load_sequence_now graphics\dink\bow\walk\d-bw3- 73 43 35 79 -13 -9 13 9");
init("load_sequence_now graphics\dink\bow\walk\d-bw4- 74 43 41 79 -18 -12 20 12");

init("load_sequence_now graphics\dink\bow\walk\d-bw6- 76 43 47 78 -23 -10 23 10");
init("load_sequence_now graphics\dink\bow\walk\d-bw7- 77 43 46 71 -20 -10 20 10");
init("load_sequence_now graphics\dink\bow\walk\d-bw8- 78 43 35 76 -15 -12 15 12");
init("load_sequence_now graphics\dink\bow\walk\d-bw9- 79 43 46 78 -13 -9 13 9");

init("load_sequence_now graphics\dink\bow\idle\d-bi2- 12 250 35 87 -17 -12 16 9");
init("load_sequence_now graphics\dink\bow\idle\d-bi4- 14 250 37 77 -11 -12 16 10");
init("load_sequence_now graphics\dink\bow\idle\d-bi6- 16 250 35 83 -15 -9 11 9");
init("load_sequence_now graphics\dink\bow\idle\d-bi8- 18 250 33 70 -15 -12 15 9");

init("load_sequence_now graphics\dink\bow\hit\d-ba2- 102 75 27 89 -23 -12 24 11");
init("load_sequence_now graphics\dink\bow\hit\d-ba4- 104 75 76 79 -23 -13 23 14");
init("load_sequence_now graphics\dink\bow\hit\d-ba6- 106 75 37 81 -14 -10 14 10");
init("load_sequence_now graphics\dink\bow\hit\d-ba8- 108 75 31 89 -17 -16 17 10");

//bow weapon diags

init("load_sequence_now graphics\dink\bow\hit\d-ba1- 101 75 57 84 -20 -12 20 12");
init("load_sequence_now graphics\dink\bow\hit\d-ba3- 103 75 33 86 -19 -13 19 13");
init("load_sequence_now graphics\dink\bow\hit\d-ba7- 107 75 54 82 -19 -11 19 11");
init("load_sequence_now graphics\dink\bow\hit\d-ba9- 109 75 37 78 -21 -10 21 10");
preload_seq(25);

int &mcounter;
sp_brain(&current_sprite, 9);
sp_speed(&current_sprite, 3);
sp_range(&current_sprite, 45);
sp_distance(&current_sprite, 55);
sp_timing(&current_sprite, 33);
sp_exp(&current_sprite, 120);
sp_base_walk(&current_sprite, 70);
sp_base_death(&current_sprite, 436);
//This enemy just uses base_walk+5 as it's death frame.
sp_defense(&current_sprite, 3);
sp_strength(&current_sprite, 10);
sp_touch_damage(&current_sprite, 6);
sp_hitpoints(&current_sprite, 30);

sp_target(&current_sprite, 1);
// Attack right away.

//v and h stand for vertical and horizontal. a stands absolute.
//these are used to find what direction dink is from the monster.

int &h;
int &ah;
int &v;
int &av;

//this is used to hold the monster's X and Y (not at once of course)
int &myxy;
//This is the same for dink.
int &dixy;

int &mcounter;
int ⌖

int &basehit;
int &mholdx;
int &mholdy;
int &junk;
int &mshadow;
int &mydir;
int &delay = random(1500, 500);
// Adjust time before first shot.

mainloop:
wait(100);
&delay -= 100;
if (&delay > 0)
goto mainloop;
&delay = random(1500, 500);
// Adjust time before additonal shots.
goto shoot;
}

void hit( void )`
{
playsound(28, 22050,0,&current_sprite, 0);
//sp_target(&current_sprite, 1);
//uncomment to prevent this guy from attacking other enemies that hit him
goto mainloop;
}

void die( void )
{
&save_x = sp_x(&current_sprite, -1);
&save_y = sp_y(&current_sprite, -1);
external("emake","large");
int &hold = sp_editor_num(&current_sprite);
if (&hold != 0)
editor_type(&hold, 6);
}

void attack( void )
{
playsound(36, 22050,0,&current_sprite, 0);

&mcounter = random(5000,1000);
sp_attack_wait(&current_sprite, &mcounter);
goto mainloop;
}

void shoot( void )
{
shoot:

&target = sp_target(&current_sprite, -1)
if (&target < 1)
goto mainloop;
// No target, no point in shooting.

&av = sp_y(&current_sprite, -1)
&ah = sp_x(&current_sprite, -1)
&v = sp_y(&target, -1)
&h = sp_x(&target, -1)
// aim at whoever the enemy is, not just dink.
// One quirk to be aware of, if this guy shoots another monster
// that monster will respond by getting mad at dink, as if he fired the shot.

//Substract monster's absolute v and h from dink's to get relative v and h
&v -= &av
&h -= &ah

//now the confusing part, copy the relative v&h into &av and &ah so that
//it can be reused to save memory and make the program make less sense.
&av = &v
&ah = &h

//if true, dink is above the lich.
if(&v < 0)
{
&av *= -1;
//if true, dink is to the lich's left.
if(&h < 0)
{
&ah *= -1;
&av *= 2;
//If true, dink is much more left then up.
if(&av < &ah)
{
sp_dir(&current_sprite,4);
goto done;
}
&ah *= 4;
//If true, dink is much more up then left.
if(&ah < &av)
{
sp_dir(&current_sprite,8);
goto done;
}
//if neither of the last to were true,
//then dink is about equally up and left.
sp_dir(&current_sprite,7);
goto done;
}
//Dink wasn't to the lich's left, so he must be to the right!

&av *= 2;
//If true, dink is much more right then up.
if(&av < &ah)
{
sp_dir(&current_sprite,6);
goto done;
}
&ah *= 4;
//If true, dink is much more up then right.
if(&ah < &av)
{
sp_dir(&current_sprite,8);
goto done;
}
//if neither of the last to were true,
//then dink is about equally up and left.
sp_dir(&current_sprite,9);
goto done;
}
//if dink wasn't above the lich, he must be below it!
//I trust you have the idea now.

if(&h < 0)
{
&ah *= -1;
&av *= 2;
if(&av < &ah)
{
sp_dir(&current_sprite,4);
goto done;
}
&ah *= 4;
if(&ah < &av)
{
sp_dir(&current_sprite,2);
goto done;
}
sp_dir(&current_sprite,1);
goto done;
}
&av *= 2;
if(&av < &ah)
{
sp_dir(&current_sprite,6);
goto done;
}
&ah *= 4;
if(&ah < &av)
{
sp_dir(&current_sprite,2);
goto done;
}
sp_dir(&current_sprite,3);

//Now that the lich is facing the right way, it works almost like dink's
//fireball spell. In my d-mod the fireball looks the same from evrey side
//so it doesn't add the fireballs direction to the base seq.

done:
&mydir = sp_dir(&current_sprite, -1);

//disallow diagonal fireballs for now

if (sp_dir(&current_sprite, -1) == 1)
sp_dir(&current_sprite, 4);
if (sp_dir(&current_sprite, -1) == 3)
sp_dir(&current_sprite, 6);
if (sp_dir(&current_sprite, -1) == 7)
sp_dir(&current_sprite, 4);
if (sp_dir(&current_sprite, -1) == 9)
sp_dir(&current_sprite, 6);

// &basehit = sp_dir(&current_sprite, -1);
// &basehit += xxx;
// sp_seq(&current_sprite, &basehit);
// sp_frame(&current_sprite, 1);
// sp_kill_wait(&current_sprite);
// sp_nocontrol(&current_sprite, 1);
// This is where you make this enemy play some kind of animation
// Probably casting a spell or firing a weapon.
// xxx would be the "base" sequence number (like sp_base_walk)
&basehit = sp_dir(&current_sprite, -1);
&basehit += 100;
sp_seq(&current_sprite, &basehit);
sp_frame(&current_sprite, 1); //reset seq to 1st frame
//sp_kill_wait(1); //make sure dink will punch right away
//sp_nocontrol(1, 1); //dink can't move until anim is done!
//&magic_level = 0;
//draw_status();
&mholdx = sp_x(&current_sprite, -1);
&mholdy = sp_y(&current_sprite, -1);

wait(300);


playsound(44, 22050,0,0,0);

if (&mydir == 6)
{
&mholdx += 30;
}

if (&mydir == 4)
{
&mholdx -= 30;
}
//modified graphics to have arrow-09 instead arrow-05, to make coding easier
&junk = create_sprite(&mholdx, &mholdy, 11, 25, &mydir);
sp_dir(&junk, &mydir);

//sp_seq(&junk, 163);

//create fake shadow effect
playsound(17, 3000, 0, &junk, 0);

sp_timing(&junk, 0);
sp_speed(&junk, 4);
sp_strength(&junk, 5);
sp_range(&junk, 10);
//this makes it easier to hit stuff
sp_flying(&junk, 1);
sp_script(&junk, "dam-a1");
sp_nohit(&junk, 1);
//when the fireball hits something, it will look to this script, this way
//we can burn trees when appropriate
&mshadow = create_sprite(&mholdx, &mholdy, 15, 432, 3);
sp_brain_parm(&mshadow, &junk);
sp_nohit(&mshadow, 1);
sp_que(&mshadow, -500);
//will be drawn under everything

//set fireball to not be able to damage the shooting enemy
sp_brain_parm(&junk, &current_sprite);

// Note, I took out the sp_brain_parm2 line.
// It was useless since the shadow is sp_nohit anyway.

goto mainloop;
}
April 7th 2007, 06:19 PM
goblinm.gif
2 ideas:

1. Play with sp_frame_delay in main() (make it 200 or so).

2. Change the 75 to a 200 in the lines that look like:
init("load_sequence_now graphics\dink\bow\hit\d-ba2- 102 75 27 89 -23 -12 24 11");
April 9th 2007, 12:52 AM
wizardb.gif
Endy
Peasant He/Him United States
 
Worked perfectly,
thanks