drawing a lightning! how to?

You must understand the Game Editor concepts, before post here.

drawing a lightning! how to?

Postby sonicfire » Thu Jan 27, 2011 7:23 pm

so for example i have this:
Image
no problem using lineto.

but, what if i want to do this ?
Image

i´m simply not sure about the maths here. anyone could guide me?
i always have source and target coordinates but how would i go about "dividing" this
line into lets say 8 [img]lineto[/img]´s with slight random variations but still point to the target? :)

anybody could help me? would be much appreciated :) thanks!!
sonicfire
 
Posts: 425
Joined: Wed Nov 01, 2006 9:34 pm
Location: berlin germany
Score: 16 Give a positive score

Re: drawing a lightning! how to?

Postby Hblade » Thu Jan 27, 2011 7:27 pm

Hmm, thats a hard one.

You can always try:
Code: Select all
for(i=0;i<(distance(x,y,target.x,target.y)/2);i++) {
moveto(x, y);
lineto(i, i);
lineto(i, i);
lineto(target.x, target.y);
}


Untested, but might create a stagger in th emiddle.


There is another method but it's a long rout to take.
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: drawing a lightning! how to?

Postby sonicfire » Thu Jan 27, 2011 8:07 pm

Thank you :) Will give it a try!
sonicfire
 
Posts: 425
Joined: Wed Nov 01, 2006 9:34 pm
Location: berlin germany
Score: 16 Give a positive score

Re: drawing a lightning! how to?

Postby Game A Gogo » Thu Jan 27, 2011 10:03 pm

Here's my version :)
Code: Select all
int i,rx,ry;
int Crack=25,Force=25;
setpen(0,127,255,0,3);
moveto(0,0);
for(i=0;i<Crack;i++)
{
    rx=(rand(2)-1)*((float)i/Crack)*Force;
    ry=(rand(2)-1)*((float)i/Crack)*Force;
    lineto(((float)i/Crack)*width+rx,((float)i/Crack)*height+ry);
}

variable Crack is how many segment should crack and Force is the intensity of the cracking.
note, the cracking intensity is graduate, so it starts smoothly to more and more
Attachments
untitled.PNG
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Re: drawing a lightning! how to?

Postby Game A Gogo » Thu Jan 27, 2011 10:09 pm

exemple that follows the mouse (put in draw actor)
Code: Select all
int i,rx,ry;
int Crack=25,Force=25;
erase(0,0,0,1);
setpen(0,127,255,0,3);
moveto(320,240);
for(i=0;i<Crack;i++)
{
    rx=(rand(2)-1)*((float)i/Crack)*Force;
    ry=(rand(2)-1)*((float)i/Crack)*Force;
    lineto((((float)i/Crack)*(xmouse-320)+rx)+320,(((float)i/Crack)*(ymouse-240)+ry)+240);
}

or
Code: Select all
int i,rx,ry;
int Crack=10,Force=10;
erase(0,0,0,1);
setpen(0,127,255,0,3);
moveto(320,240);
for(i=0;i<Crack;i++)
{
    rx=(rand(2)-1)*min(1,((float)i/Crack)*3)*Force;
    ry=(rand(2)-1)*min(1,((float)i/Crack)*3)*Force;
    lineto((((float)i/Crack)*(xmouse-320)+rx)+320,(((float)i/Crack)*(ymouse-240)+ry)+240);
}
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Re: drawing a lightning! how to?

Postby sonicfire » Fri Jan 28, 2011 1:55 am

:shock: amazing, thanks very much!
thank you both :D
sonicfire
 
Posts: 425
Joined: Wed Nov 01, 2006 9:34 pm
Location: berlin germany
Score: 16 Give a positive score


Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 1 guest

cron