Slick Forums

Discuss the Slick 2D Library
It is currently Thu May 23, 2013 9:29 am

All times are UTC




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: blue streak lightning
PostPosted: Mon Jan 09, 2012 2:13 pm 
Offline
Regular

Joined: Thu Sep 22, 2011 4:39 pm
Posts: 165
Location: Belgium
Hello,

Does anyone has an idea how to create a lightning effect from point A to point B?
i tried with the emmitters via pedigree but maybe somebody has a better idea?

tx,


Top
 Profile  
 
PostPosted: Mon Jan 09, 2012 4:48 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1469
The easiest thing to do would be to design several different lightning bolts in Photoshop or a similar program; by using a tutorial or downloading some free brushes.

Then, pack each bolt design into a transparent sprite sheet, have your game pick them at random, and render them atop your environment. Stretch and resize them as necessary to have them go from point A to point B.

Rendering lightning with OpenGL will be much more difficult and likely less efficient, but here are some tutorials on that:
http://www.gamedev.net/page/resources/_ ... ning-r1512
http://www.gamasutra.com/view/feature/3 ... ticle_.php
http://stackoverflow.com/questions/3578 ... ise-or-oth


Top
 Profile  
 
PostPosted: Mon Jan 09, 2012 5:26 pm 
Offline
Regular

Joined: Thu Sep 22, 2011 4:39 pm
Posts: 165
Location: Belgium
or maybe i could use the path class and add some particles on it?
can i let the path glow or something?


Top
 Profile  
 
PostPosted: Tue Jan 10, 2012 12:30 am 
Offline
User avatar

Joined: Fri Oct 07, 2011 11:05 pm
Posts: 97
Location: France, Nantes
Do you want it to be generated randomly (procedurally) or predefined? if 1st option sounds good to you, you'd better check the last link of what davedes sent to you. Path is to my mind not a good idea, as it is very restrictive. you'd better generate some point, and then do the stuff to draw the spark between them.

_________________
"The Keeper is aware. The Keeper understands. The Keeper has seen the enemy."


Top
 Profile  
 
PostPosted: Tue Jan 10, 2012 11:15 am 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1469
Your topic sparked my interest -- I wanted to see if I could generate a very simple lightning-like effect without delving into any complex algorithms or low-level OpenGL. :)

Image Image Image

The generated bolt is rendered to a Slick image: the resulting image can then be rendered/rotated/moved quickly and efficiently. If you wanted even more realism, you could use a "tree" structure to the bolts and create them recursively. Generation is not super fast, but it's efficient enough for most games.

If you're interested in the code: (only a couple hundred lines, including comments)
http://www.mediafire.com/?oanv5k5aro2oczb


Top
 Profile  
 
PostPosted: Tue Jan 10, 2012 12:56 pm 
Offline
Game Developer
User avatar

Joined: Thu Mar 03, 2011 6:22 pm
Posts: 534
That's cool! But what is soundly? (left in the import section of your test :))

_________________
Current Projects:
Image Mr. Hat I
Image Vegan Vs. Zombies
Projects:
RadicalFish Engine - Build on top of Slick2D, Ideas, Bugs? Open an Issue ticket!


Top
 Profile  
 
PostPosted: Tue Jan 10, 2012 2:13 pm 
Offline
Regular

Joined: Thu Sep 22, 2011 4:39 pm
Posts: 165
Location: Belgium
:) great, i'll try to see what i can do with it,

so what i want to do is to achieve a lightning effect to all "tiles" that need to break in my match 3 game
so they always start from a special button to an array of other positions

meaning the start point is always the same but the end point is different and it should give me a lightning effect
i've tried this script https://bitbucket.org/jimpurbrick/law/s ... gBolt.java which generates some
lines but it's difficult to skin, i tried to put emmitters on it or even put a texture but it doesn't look that great


Top
 Profile  
 
PostPosted: Tue Jan 10, 2012 2:52 pm 
Offline
Regular

Joined: Thu Sep 22, 2011 4:39 pm
Posts: 165
Location: Belgium
maybe take also a look at these
http://drilian.com/2009/02/25/lightning-bolts/
http://blog.gemserk.com/2011/03/19/ligh ... ts-effect/


Top
 Profile  
 
PostPosted: Tue Jan 10, 2012 5:20 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1469
R.D. wrote:
That's cool! But what is soundly? (left in the import section of your test :))

Ah, just a little OpenAL game sound engine I've been developing in my free time. Forgot to remove those. :)

mortias - So tile A might shoot a bolt to tile B, another bolt to tile C, and a third bolt to tile D? That should be fairly simple with my code.

You need to alter/remove the bending and replace the loop break with a final "lineTo(x, height)" (line 178) -- this ensures that the start and end of the bolt are on the same X plane. You can determine how tall to make the lightning using Pythagorean (point A to point B), then rotate and translate the image as necessary so that it appears to shoot from tile A to tile B. Repeat for tile A to tile C, tile A to tile D, etc.

From there, you can begin optimizing and adding more aesthetic elements: adding more bends and randomization throughout the bolt, only using a single Image instead of one for each tile connection, removing Path altogether and using your own iteration of lineTo, etc.


Top
 Profile  
 
PostPosted: Tue Jan 10, 2012 8:35 pm 
Offline
Regular

Joined: Thu Sep 22, 2011 4:39 pm
Posts: 165
Location: Belgium
tx for the code i'll take a look at it, i don't know if i understand all this but i'll try to do the blending also,
maybe you could work this a little bit out for me :) almost don't dare to ask.. it would be a great help

here a preview of the game itself, so the purple bolt is rotating and when you switch it, it breaks some tiles of the same color
of the tile you switched with, so in this case it would remove all blue items
but only the blue bolt effect is still missing to the blue items
Image


Top
 Profile  
 
PostPosted: Tue Jan 10, 2012 8:47 pm 
Offline
User avatar

Joined: Fri Oct 07, 2011 11:05 pm
Posts: 97
Location: France, Nantes
Woah! This look really nice! Good Job!

_________________
"The Keeper is aware. The Keeper understands. The Keeper has seen the enemy."


Top
 Profile  
 
PostPosted: Wed Jan 11, 2012 8:06 am 
Offline
Regular

Joined: Thu Sep 22, 2011 4:39 pm
Posts: 165
Location: Belgium
thank you :) first i did this in javafx but i'm very happy i moved to slick :)
i would like to release it this year somewhere on bigfish


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group