Re: Blue Knight Ally
After seeing the post about having a useful ally Dink I managed to come up with this script for a blue knight ally that'll attack enemies based on proximity, cool to watch as the knight selectivly hunts down his enemies. Should be useful for giving allies additional smarts. Could even create a whole battle by employing several at once.
Anyways here's the code, still kinda rough... Any suggestions would be appreciated.
//Blue Knight Ally
//hunts down enemies based on proximity
//returns to standby mode afterwards
void main( void )
{
int &distA = 600;
int &mcounter;
int &sight;
int &enmy
sp_brain(¤t_sprite, 9);
sp_speed(¤t_sprite, 2);
sp_range(¤t_sprite, 45);
sp_distance(¤t_sprite, 55);
sp_timing(¤t_sprite, 33);
sp_base_walk(¤t_sprite, 280);
// sp_base_death(¤t_sprite, xxx);
// This enemy just uses base_walk+5 as it's death frame.
sp_defense(¤t_sprite, 4);
sp_strength(¤t_sprite, 10);
sp_hitpoints(¤t_sprite, 90);
set_smooth_follow(1);
goto sight;
}
void sight ( void )
{
sight:
int &sprite = 0;
//gotta compare 2 distances at a time higher distance loses, then goes on to next one
loop:
&sprite = get_next_sprite_with_this_brain(9, ¤t_sprite, &sprite);
if (&sprite > 0)
{
//others stuff
int &dx = sp_x(&sprite, -1 );
int &dy = sp_y(&sprite, -1 );
//self info
int &x = sp_x(¤t_sprite, -1);
int &y = sp_y(¤t_sprite, -1);
&x -= &dx;
&y -= &dy;
&x * &x;
&y * &y;
&y += &x;
int &dist = math_sqrt(&y);
//below finds the cloest enemy
if (&dist <= &distA)
{
&distA = &dist;
&enmy = &sprite;
}
&sight = get_rand_sprite_with_this_brain(9, ¤t_sprite);
if (&enmy == 0)
{
sp_target(¤t_sprite, &sight);
}
//say(" &distA &enmy &sprite ", &sprite);
//Increment &sprite so we start with the next sprite
&sprite += 1;
goto loop;
}
else
{
//very improtant to reset
//my knight was having spasms without it
int &distA = 600;
}
&sight = get_rand_sprite_with_this_brain(9, ¤t_sprite);
//goes to dink if no monsters; otherwise attacks random monster
if (&sight != 0)
{
sp_base_attack(¤t_sprite, 730);
sp_target(¤t_sprite, &enmy);
//say(" &distA &enmy &sprite ", ¤t_sprite);
}
if (&sight == 0)
{
sp_base_attack(¤t_sprite, -1);
sp_target(¤t_sprite, 1);
//Dinks stuff
int &dx = sp_x(1, -1 );
int &dy = sp_y(1, -1 );
//self info
int &x = sp_x(¤t_sprite, -1);
int &y = sp_y(¤t_sprite, -1);
//pythagorian's theorm, eternally handy
&x -= &dx;
&y -= &dy;
&x * &x;
&y * &y;
&y += &x;
int &dist = math_sqrt(&y);
if (&dist <= 65)
{
sp_brain(¤t_sprite, 16);
}
if (&dist >= 80)
{
sp_brain(¤t_sprite, 9);
}
}
}
wait(600);
goto sight;
}
void attack( void )
{
playsound(36, 22050,0,¤t_sprite, 0);
&mcounter = random(1000,0);
sp_attack_wait(¤t_sprite, &mcounter);
goto sight;
}
void hit( void )`
{
playsound(28, 22050,0,¤t_sprite, 0);
if (&enemy_sprite > 1)
{
sp_target(¤t_sprite, &enemy_sprite);
}
goto sight;
}
}
void die( void )
{
&save_x = sp_x(¤t_sprite, -1);
&save_y = sp_y(¤t_sprite, -1);
external("emake","large");
int &hold = sp_editor_num(¤t_sprite);
if (&hold != 0)
editor_type(&hold, 6);
}
Anyways here's the code, still kinda rough... Any suggestions would be appreciated.
//Blue Knight Ally
//hunts down enemies based on proximity
//returns to standby mode afterwards
void main( void )
{
int &distA = 600;
int &mcounter;
int &sight;
int &enmy
sp_brain(¤t_sprite, 9);
sp_speed(¤t_sprite, 2);
sp_range(¤t_sprite, 45);
sp_distance(¤t_sprite, 55);
sp_timing(¤t_sprite, 33);
sp_base_walk(¤t_sprite, 280);
// sp_base_death(¤t_sprite, xxx);
// This enemy just uses base_walk+5 as it's death frame.
sp_defense(¤t_sprite, 4);
sp_strength(¤t_sprite, 10);
sp_hitpoints(¤t_sprite, 90);
set_smooth_follow(1);
goto sight;
}
void sight ( void )
{
sight:
int &sprite = 0;
//gotta compare 2 distances at a time higher distance loses, then goes on to next one
loop:
&sprite = get_next_sprite_with_this_brain(9, ¤t_sprite, &sprite);
if (&sprite > 0)
{
//others stuff
int &dx = sp_x(&sprite, -1 );
int &dy = sp_y(&sprite, -1 );
//self info
int &x = sp_x(¤t_sprite, -1);
int &y = sp_y(¤t_sprite, -1);
&x -= &dx;
&y -= &dy;
&x * &x;
&y * &y;
&y += &x;
int &dist = math_sqrt(&y);
//below finds the cloest enemy
if (&dist <= &distA)
{
&distA = &dist;
&enmy = &sprite;
}
&sight = get_rand_sprite_with_this_brain(9, ¤t_sprite);
if (&enmy == 0)
{
sp_target(¤t_sprite, &sight);
}
//say(" &distA &enmy &sprite ", &sprite);
//Increment &sprite so we start with the next sprite
&sprite += 1;
goto loop;
}
else
{
//very improtant to reset
//my knight was having spasms without it
int &distA = 600;
}
&sight = get_rand_sprite_with_this_brain(9, ¤t_sprite);
//goes to dink if no monsters; otherwise attacks random monster
if (&sight != 0)
{
sp_base_attack(¤t_sprite, 730);
sp_target(¤t_sprite, &enmy);
//say(" &distA &enmy &sprite ", ¤t_sprite);
}
if (&sight == 0)
{
sp_base_attack(¤t_sprite, -1);
sp_target(¤t_sprite, 1);
//Dinks stuff
int &dx = sp_x(1, -1 );
int &dy = sp_y(1, -1 );
//self info
int &x = sp_x(¤t_sprite, -1);
int &y = sp_y(¤t_sprite, -1);
//pythagorian's theorm, eternally handy
&x -= &dx;
&y -= &dy;
&x * &x;
&y * &y;
&y += &x;
int &dist = math_sqrt(&y);
if (&dist <= 65)
{
sp_brain(¤t_sprite, 16);
}
if (&dist >= 80)
{
sp_brain(¤t_sprite, 9);
}
}
}
wait(600);
goto sight;
}
void attack( void )
{
playsound(36, 22050,0,¤t_sprite, 0);
&mcounter = random(1000,0);
sp_attack_wait(¤t_sprite, &mcounter);
goto sight;
}
void hit( void )`
{
playsound(28, 22050,0,¤t_sprite, 0);
if (&enemy_sprite > 1)
{
sp_target(¤t_sprite, &enemy_sprite);
}
goto sight;
}
}
void die( void )
{
&save_x = sp_x(¤t_sprite, -1);
&save_y = sp_y(¤t_sprite, -1);
external("emake","large");
int &hold = sp_editor_num(¤t_sprite);
if (&hold != 0)
editor_type(&hold, 6);
}
Looks good. I didn't read through it all, perhaps I'll do it later. Otherwise, keep up the good work.
I'm lovin' it!
