The Dink Network

scripting help needed

May 11th 2007, 11:32 PM
slayer.gif
rabidwolf9
Peasant He/Him United States
twitch.tv/rabidwolf9 
I had an idea today for a sort of spell/special that would be cool. I want to make it work but I'm not sure how to go about this...

The spell should summon axe(s) to swirl around Dink. That's easy, but here's the catch. As they swirl around Dink, they should get farther and farther away from Dink until they leave the screen. It would be kind of like a spiral or vortex.

Is there some sort of formula that would work for this?
May 12th 2007, 12:31 AM
goblinm.gif
Yeah, I did that with stars in VDC (I was inspired by the bone armor in Diablo 2.)

I did it the wrong way though. Here is the right way:

loophere:
int &dinkx = sp_x(1, -1);
int &dinky = sp_y(1, -1);
int &thisx = &dinkx;
int &thisy = &dinky;

&thisx += 0;
&thisy += -40;
sp_x(&current_sprite, &thisx);
sp_y(&current_sprite, &thisy);

wait(50);

int &dinkx = sp_x(1, -1);
int &dinky = sp_y(1, -1);
int &thisx = &dinkx;
int &thisy = &dinky;

&thisx += 10;
&thisy += -30;
sp_x(&current_sprite, &thisx);
sp_y(&current_sprite, &thisy);

wait(50);

int &dinkx = sp_x(1, -1);
int &dinky = sp_y(1, -1);
int &thisx = &dinkx;
int &thisy = &dinky;

&thisx += 20;
&thisy += -20;
sp_x(&current_sprite, &thisx);
sp_y(&current_sprite, &thisy);

wait(50);

int &dinkx = sp_x(1, -1);
int &dinky = sp_y(1, -1);
int &thisx = &dinkx;
int &thisy = &dinky;

&thisx += 30;
&thisy += -10;
sp_x(&current_sprite, &thisx);
sp_y(&current_sprite, &thisy);

wait(50);

int &dinkx = sp_x(1, -1);
int &dinky = sp_y(1, -1);
int &thisx = &dinkx;
int &thisy = &dinky;

&thisx += 40;
&thisy += 0;
sp_x(&current_sprite, &thisx);
sp_y(&current_sprite, &thisy);

wait(50);

int &dinkx = sp_x(1, -1);
int &dinky = sp_y(1, -1);
int &thisx = &dinkx;
int &thisy = &dinky;

&thisx += 30;
&thisy += 10;
sp_x(&current_sprite, &thisx);
sp_y(&current_sprite, &thisy);

wait(50);

int &dinkx = sp_x(1, -1);
int &dinky = sp_y(1, -1);
int &thisx = &dinkx;
int &thisy = &dinky;

&thisx += 20;
&thisy += 20;
sp_x(&current_sprite, &thisx);
sp_y(&current_sprite, &thisy);

wait(50);

int &dinkx = sp_x(1, -1);
int &dinky = sp_y(1, -1);
int &thisx = &dinkx;
int &thisy = &dinky;

&thisx += 10;
&thisy += 30;
sp_x(&current_sprite, &thisx);
sp_y(&current_sprite, &thisy);

wait(50);

int &dinkx = sp_x(1, -1);
int &dinky = sp_y(1, -1);
int &thisx = &dinkx;
int &thisy = &dinky;

&thisx += 0;
&thisy += 40;
sp_x(&current_sprite, &thisx);
sp_y(&current_sprite, &thisy);

wait(50);

int &dinkx = sp_x(1, -1);
int &dinky = sp_y(1, -1);
int &thisx = &dinkx;
int &thisy = &dinky;

&thisx += -10;
&thisy += 30;
sp_x(&current_sprite, &thisx);
sp_y(&current_sprite, &thisy);

wait(50);

int &dinkx = sp_x(1, -1);
int &dinky = sp_y(1, -1);
int &thisx = &dinkx;
int &thisy = &dinky;

&thisx += -20;
&thisy += 20;
sp_x(&current_sprite, &thisx);
sp_y(&current_sprite, &thisy);

wait(50);

int &dinkx = sp_x(1, -1);
int &dinky = sp_y(1, -1);
int &thisx = &dinkx;
int &thisy = &dinky;

&thisx += -30;
&thisy += 10;
sp_x(&current_sprite, &thisx);
sp_y(&current_sprite, &thisy);

wait(50);

int &dinkx = sp_x(1, -1);
int &dinky = sp_y(1, -1);
int &thisx = &dinkx;
int &thisy = &dinky;

&thisx += -40;
&thisy += 0;
sp_x(&current_sprite, &thisx);
sp_y(&current_sprite, &thisy);

wait(50);

int &dinkx = sp_x(1, -1);
int &dinky = sp_y(1, -1);
int &thisx = &dinkx;
int &thisy = &dinky;

&thisx += -30;
&thisy += -10;
sp_x(&current_sprite, &thisx);
sp_y(&current_sprite, &thisy);

wait(50);

int &dinkx = sp_x(1, -1);
int &dinky = sp_y(1, -1);
int &thisx = &dinkx;
int &thisy = &dinky;

&thisx += -20;
&thisy += -20;
sp_x(&current_sprite, &thisx);
sp_y(&current_sprite, &thisy);

wait(50);

int &dinkx = sp_x(1, -1);
int &dinky = sp_y(1, -1);
int &thisx = &dinkx;
int &thisy = &dinky;

&thisx += -10;
&thisy += -30;
sp_x(&current_sprite, &thisx);
sp_y(&current_sprite, &thisy);

wait(50);

goto loophere;
May 12th 2007, 12:41 AM
goblinm.gif
Obviously, you could do this with loops if you wanted, although it would take a few more variables. The point is, you should use sp_x and sp_y rather than sp_mx and sp_my (it looks much better.)

I guess an efficient loop might be:

int &dinkx;
int &dinky;
int &thisx;
int &thisy;
int &x_offset = 0;
int &y_offset = -40;
loophere:
&dinkx = sp_x(1, -1);
&dinky = sp_y(1, -1);
&thisx = &dinkx;
&thisy = &dinky;

if (&x_offset >= 0)
{
&y_offset += 10;
if (&y_offset == 50)
{
&y_offset = 30;
}
}
else
{
&y_offset -= 10;
}

if (&y_offset >= 0)
{
&x_offset -= 10;
if (&x_offset == -50)
{
&x_offset = -30;
}
}
else
{
&x_offset += 10;
}

&thisx += &x_offset;
&thisy += &y_offset;
sp_x(&current_sprite, &thisx);
sp_y(&current_sprite, &thisy);
wait(50);
goto loophere:
May 12th 2007, 01:00 AM
burntree.gif
Striker
Noble She/Her United States
Daniel, there are clowns. 
Since I've messed with using curving projectiles, I am quite certain this is possible to script, though it will take some time and tweaking. I would suggest using a modular script on each individual axe, perhaps passing the starting variables for the initial sp_mx() and sp_my() movement using the new features found in v1.08.

The first thing you need to do is figure out how to make them fly around in a set circle around Dink. The only thing I can think of is that on each runthrough of their loop, you have to increment or "de-inciment" the sp_mx() or sp_my() value... and to do that, you need to check how far they've gone. After they have reached that point, you flip the incremental value by multiplying by -1.

I suppose a visualization of the speed you want to achieve would be (this would be clockwise movement):

......................X=max,y=0
...................../.........\
..................../...........\
..............x=0,y=min.......x=0,y=max
....................\.........../
.....................\........./
......................x=min,y=0


Whenever a value meets it's max or min, the value for incrementing its speed needs to be flipped by multiplying it by -1. The object should then begin slowing down its movement along that axis until it reaches a point of no movement (ie. &variable=0), then it will begin moving in the opposite direction.

Now, making them spiral away from their point of origin is simply a matter of simply creating a loop where the wait() value is slowly increased with each iteration of the loop. After a certain number of iterations, you, of course, would want to kill the script and the sprite.
May 12th 2007, 01:07 AM
slayer.gif
rabidwolf9
Peasant He/Him United States
twitch.tv/rabidwolf9 
Good, but not what I was looking for (i think I could handle that much on my own ) I think you may have misunderstood me.

I know this is a very crude representation, but when words fail... This is what the axe is supposed to do.
May 12th 2007, 03:45 AM
wizardb.gif
Endy
Peasant He/Him United States
 
Slightly off topic:

RabidWolf, what's that tile used in your tile test graphic in your album?
Looks pretty cool
May 12th 2007, 10:33 AM
slayer.gif
rabidwolf9
Peasant He/Him United States
twitch.tv/rabidwolf9 
The mossy "ruins" tileset? I released it in Rabid's Toys II.
May 12th 2007, 11:23 AM
slayer.gif
rabidwolf9
Peasant He/Him United States
twitch.tv/rabidwolf9 
I'm kinda confused at the moment so let me know what I'm doing wrong... sorry for acting helpless

//testing spinning
void main( void )
{
sp_speed(&current_sprite, 1);
sp_timing(&current_sprite, 33);
sp_nohit(&current_sprite, 1);

int &x_max = 40;
int &x_min = -40;

int &y_max = 40;
int &y_min = -40;

int &my_x;
int &my_y;

int &x_val = 5;
int &y_val = -5;

sp_mx(&current_sprite, &x_val);
sp_my(&current_sprite, &y_val);

loop:
wait(1);

&my_x = sp_x(&current_sprite, -1);
&my_y = sp_y(&current_sprite, -1);

if (&my_x >= &x_max)
{
&x_val *= -1;
}

if (&my_x <= &x_min)
{
&x_val *= -1;
}

if (&my_y >= &y_max)
{
&y_val *= -1;
}

if (&my_y <= &y_min)
{
&y_val *= -1;
}

if (&x_val >= 0)
{

if (&y_val >= 0)
{
sp_dir(&current_sprite, 3);
}

if (&y_val < 0)
{
sp_dir(&current_sprite,9);
}
}

if (&x_val < 0)
{

if (&y_val >= 0)
{
sp_dir(&current_sprite, 1);
}

if (&y_val < 0)
{
sp_dir(&current_sprite, 7);
}
}

sp_mx(&current_sprite, &x_val);
sp_my(&current_sprite, &y_val);

goto loop;
}
May 12th 2007, 03:12 PM
burntree.gif
Striker
Noble She/Her United States
Daniel, there are clowns. 
Hmm... I'm not exactly sure that would work, especially since if I recall correctly, sp_speed() and sp_dir() are independent of sp_mx() and sp_my(). Really, if you want make curving movement, you absolutely have to use sp_mx() and/or sp_my() in conjunction with quick-running loops that change those values for the object. I tried to explain it using crappy ASCII, but I guess I didn't do a very good job. Try looking scripts for other objects that have curving movements... I know Paul's Aether magic in Crosslink has it, and I'm pretty sure there's stuff in FIAT as well.

Anyway, this is how I would see it for an individual axe, starting directly from the left of Dink:

//Assumes the missile properties were established in the code that spawned it
//Also assumes that the axe will be spawned from the left of Dink
//More will have to be done if you want it to detect where the axe was spawned
void_main()
{
int &mx = sp_x(&current_sprite, -1);
int &my = sp_y(&current_sprite, -1);
//For this example, 5 and -5 will be our max and min values
int &x_counter = 0;
int &y_counter = -5;
//These are important for changing the directions of the axe.
int &x_dir = 1;
int &y_dir = -1;
//Value will be what will make the object spiral away.
int &wait_time = 10;
//This just counts how many times the loop has run, so we have a place to stop it all.
int total_loops = 0;

daloop:
//Object will travel in the following directions
sp_mx(&current_sprite, &x_counter);
sp_my(&current_sprite, &y_counter);

//Check if object has reached the bounds we have set for it
//If so, begin changing the direction
if(&x_counter >= 5)
&x_dir *= -1;
if(&x_counter <= -5)
&x_dir *= -1;
if(&y_counter >= 5)
&y_dir *= -1;
if(&y_counter <= -5)
&y_dir *= -1;

&x_counter += &x_dir;
&y_counter += &y_dir;

//There will be a slightly large amount of time between each loop.
wait(&wait_time);
&wait_time += 10;

&total_loops += 1;

if(&total_loops < 50)
goto daloop;

//Kill it all
sp_active(&current_sprite, 0);
kill_this_task();
}

It should be noted that practically all the values in this script can be tweaked so that you can get the arcing effect you want.
May 12th 2007, 03:17 PM
goblinm.gif
Ah, I see. What you might want to do is something like:

int &starting_x = sp_x(&current_sprite, -1);
int &starting_y = sp_y(&current_sprite, -1);
int &my_x;
int &my_y;

loophere:
int &my_x = sp_x(&current_sprite, -1);
int &my_y = sp_y(&current_sprite, -1);
if (&my_x < &starting_x)
{
if (&my_y <= &starting_y)
{
sp_mx(&current_sprite, 5)
sp_my(&current_sprite, -10);
}
else
{
sp_mx(&current_sprite, -10)
sp_my(&current_sprite, -5);
}
}
else
{
if (&my_y <= &starting_y)
{
sp_mx(&current_sprite, 10)
sp_my(&current_sprite, 5);
}
else
{
sp_mx(&current_sprite, -5);
sp_my(&current_sprite, 10);
}
}
wait(50);
goto loophere;

Your script seems kind of weird. Keep in mind, when you compare my_x to x_max, you are comparing the x-coordinate of the sprite to the x-value 40, which is off the screen to the left.
May 12th 2007, 03:31 PM
goblinm.gif
Ok, I tested it, Striker's method looks best.
May 12th 2007, 05:09 PM
slayer.gif
rabidwolf9
Peasant He/Him United States
twitch.tv/rabidwolf9 
Thanks guys. I've got the basics working (what striker posted.) Now I just need to tweak the numbers and hopefully it'll turn out good. While I was waiting for help I did manage to make another cool spell
May 12th 2007, 09:26 PM
sob_scorpy.gif
DinkDude95
Peasant He/Him Australia
The guy with the cute D-Mod. 
Cool. What does that one do?
May 12th 2007, 09:38 PM
slayer.gif
rabidwolf9
Peasant He/Him United States
twitch.tv/rabidwolf9 
It's a sword "summoning" spell. It "summons" 1-4 swords to encircle Dink that can be shot at enemies.
May 12th 2007, 09:45 PM
sob_scorpy.gif
DinkDude95
Peasant He/Him Australia
The guy with the cute D-Mod. 
Cool! How's it work?
May 13th 2007, 08:38 AM
custom_magicman.gif
magicman
Peasant They/Them Netherlands duck
Mmmm, pizza. 
Voodoo.
May 13th 2007, 10:27 AM
slayer.gif
rabidwolf9
Peasant He/Him United States
twitch.tv/rabidwolf9 
Well I could send you the 3 scripts it uses, but it wouldn't do you much good since it uses new (borrowed) graphics.

Actually I was planning on making a spell pack to release later on.

They are going to feature different levels of spells. Things like fire, swords, and axes will have their own category
May 13th 2007, 03:43 PM
burntree.gif
Striker
Noble She/Her United States
Daniel, there are clowns. 
Heh, I just realized that you don't need the variable &total_loops and could just base the number of times run off the final wait value... not that it's a big difference.
May 14th 2007, 08:42 PM
slayer.gif
rabidwolf9
Peasant He/Him United States
twitch.tv/rabidwolf9 
I'm having a weird bug with my swords
I set the depth que for when the swords go behind Dink, but when I go up-screen (to about 119y) the swords go back in front of Dink. I guess I have to mess with sp_que() for the swords more. Fun.

Edit:
This becomes a problem because the highest I can set it and still have it behind Dink results in the sword getting drawn under everything else as well.
May 15th 2007, 05:55 PM
custom_king.png
redink1
King He/Him United States bloop
A mother ducking wizard 
What are you setting the depth que to? sp_que is not an offset, but makes the sprite pretend that its y-coordinate is the given que when it is drawn. You'll probably want to do something like this:

// Draw behind dink
int &tempy = sp_y(1, -1);
&tempy -= 5;
sp_que(1, &tempy);

If Dink is able to move while this is happening, there needs to be some sort of loop so the que is continually set.
May 16th 2007, 07:52 PM
slayer.gif
rabidwolf9
Peasant He/Him United States
twitch.tv/rabidwolf9 
Got it working now thanks. Just had to change it to change the sp_que() of the sprite and not Dink