The Dink Network

Reply to Re: Why Can't I Quit You, DinkC?

If you don't have an account, just leave the password field blank.
Username:
Password:
Subject:
Antispam: Enter Dink Smallwood's last name (surname) below.
Formatting: :) :( ;( :P ;) :D >( : :s :O evil cat blood
Bold font Italic font hyperlink Code tags
Message:
 
 
November 4th 2013, 12:35 AM
goblins.gif
Note that this specific code only works if the enemy is the only object with it's brain during the setup. It also requires &jug to be initialized or to be replaced with a local variable. It is probably possible to improve the code to make it less dependent on specific brains and to allow multiple enemies but I haven't gotten it to work that way yet.

The "head" (boss1a.c):

void main( void )
{
    int &body;
    //now set brain, touch damage, speed, timing, etc.
    sp_brain(&current_sprite, [brain]);
    sp_speed(&current_sprite, [speed]);
    sp_timing(&current_sprite, [timing]);
    sp_touch_damage(&current_sprite, [touch damage]);
    sp_base_walk(&current_sprite, [base_walk]);
    sp_target(&current_sprite, 1);
    //nohit so that arrows/fireballs and stuff don't hit him instead of the body.
    sp_nohit(&current_sprite, 1);
    
    //replace coordinates and sprite with the correct values
    //even though the body is invisible it still must use the same graphic so that
    //collisions can happen properly (unless you want to use a different collision sprite)
    &body = create_sprite([100],[100],[16],[100],[0]);
    sp_script(&body, "boss1b");
    //if you need to do anything with the body from here on out, you have the &body variable
}


The "body" (boss1b.c):

void main( void )
{
    int &head;
    //first set the stats
    //sp_hitpoints and such goes here
    //be careful to set the brain to a different brain than the "head"
    sp_brain(&current_sprite, [9 or 10]);
    sp_hitpoints(&current_sprite, [hp]);
    sp_defense(&current_sprite, [defense]);
    sp_base_walk(&current_sprite, [same as head]);
    //set nodraw so that the body can't be seen
    sp_nodraw(&current_sprite, 1);

    //then we must find the head and put it in a variable
    &head = get_sprite_with_this_brain([brainofhead], &current_sprite);

mainloop:
    //get same x as head
    &jug = sp_x(&head, -1);
    sp_x(&current_sprite, &jug);
	
    //get same y as head
    &jug = sp_y(&head, -1);
    sp_y(&current_sprite, &jug);

    //get same facing as head (for collisions sake)
    &jug = sp_dir(&head, -1);
    sp_dir(&current_sprite, &jug);

    //wait(0) will wait the minimum amount of time and update the position precisely
    wait(0);
	
    goto mainloop;
}

void hit( void )
{
    //then if you need a hit procedure (more than likely you do)
    //do whatever hit procedure should do, then at the end, return to mainloop like so
    goto mainloop;
}


Hopefully I got that all down right, let me know if you have any issues or need help trying to do something specific with it.