Java-Gaming.org Hi !
 Featured games (84) games approved by the League of Dukes Games in Showcase (593) Games in Android Showcase (168) games submitted by our members Games in WIP (646) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 Easy lightning (and chunk system)  (Read 2490 times) 0 Members and 1 Guest are viewing this topic.
roseslayer

Junior Devvie

Medals: 2

 « Posted 2013-02-11 15:54:28 »

Hello there,

I'm currently working on a game that's using squares and it is in 2D. However I want to make it a bit more realistic and maybe larger... So I got some small questions how I can make some smooth lightning that isn't really flat and maps that aren't at maximum 200*200(blocks not pixels, 1 block = 13pixels.)

Lightning System
For the lightning system I tried to do something with variables and just a simple lightning from above. I made the lightning with the fillRec functie and the Color functie the color is basicly (0,0,0,lightning) and in the level tick I made the lightning system like this:

 1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16 `               try { //Lightning effect in the air and contact on ground.                  if(y != 0) {                     if(block[x][y].id == Tile.air && block[x][y - 1].id == Tile.air || block[x][y].id != Tile.air && block[x][y - 1].id == Tile.air) {                        block[x][y].lightning = block[x][y - 1].lightning;                     }                  }               } catch(Exception e) { }                              try { //Lightning effect spreading on blocks that aren't air.                  if(y != 0) {                     if(block[x][y].id != Tile.air && block[x][y - 1].id != Tile.air && block[x][y - 1].lightning != 250 || block[x][y].id == Tile.air && block[x][y - 1].id != Tile.air && block[x][y - 1].lightning != 250) {                        block[x][y].lightning = block[x][y - 1].lightning + 50;                     }                  }               } catch(Exception e) { }               `

As you can see, I basicly made it the if there's a block above the block and that block isn't equal to the id Tile.air that the lightning += 50. At my first opinion this was a great and easy idea to make a small but working lightning system. It now looks like this:

Some small things I saw and that were that the lightning on not fully squared blocks isn't the best and the lightning isn't really good when there's a platform like this image:

And hints of tips are welcome, I know lightning doesn't spread from top to bottom only but from left and right either.

Chunk System
Is there a good way to make your small chunks loop? like this small prototype map is 50*50 blocks and if you're on block x 30 that it makes a new chunk/level on that place with a looping map not that there's a mountain on that spot and 1 block left of it there are plains..

-RoseSlayer

Fundamentum W.I.P.
cheatsguy

Junior Devvie

Medals: 3

Gamer turned Pixel Artist turned Programmer

 « Reply #1 - Posted 2013-02-11 17:41:00 »

For lighting, the light should be determined by relation to an above-ground air block, and if it is not adjacent to one, add 50 to the alpha for the shadow-map.

Also, why 13 px? Seems kind of random, and making a power of 2 (8,16,32,etc.) makes it easier for the computer to understand and will cause less issues in the future.

As for the chunks, I'm not too sure what you're trying to accomplish. Are you tryin to repeat the same level, over and over again, infinitely? I'm not sure how to do that :/ anyway, hope this helps a little bit.

Also, nice terraria sprite

Busy between school, work, life, games, programming and general screwing around.
If you'd like some pixel art for your game, send me a PM, i'll see what I can do.
Current project: http://elementalwarblog.wordpress.com/
roseslayer

Junior Devvie

Medals: 2

 « Reply #2 - Posted 2013-02-11 20:45:03 »

Terraria sprites where for testing porpuse glad you like it! But I was already going to make it 14x14 because that is better for liquids either you can't do 13:2 so it isn't the greatest random number that I had choosen. and for the power, that is a great option. I'm going to add that aswell. I think I am going to create an extra class for the lightning aswell. For the chunk system it's great to make it all over again because it's random generated so the new chunck will also be random generated etc. so repeating it might be an excellent idea.

Fundamentum W.I.P.
HeroesGraveDev

JGO Kernel

Medals: 359
Projects: 11
Exp: 3 years

┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻

 « Reply #3 - Posted 2013-02-12 03:08:50 »

Regenuluz
 « Reply #4 - Posted 2013-02-12 10:00:36 »

But lightning is cool. And it emits light. xD
roseslayer

Junior Devvie

Medals: 2

 « Reply #5 - Posted 2013-02-12 15:59:20 »

But lightning is cool. And it emits light. xD

Haha! that's true.. I don't know why I had called it lightning but lighting is a better word for it (probably because I'm horrible at my English).. Thanks but for my lightning question I solved it almost all. Is there only a way to set the "mask" of the rectangle as example you got a character and you can color it in with 1 color, how is this possible? also here's a small picture:

The question: It's a rec... Is there anyway how the rectangle can "fit" the sprite?
Cause this looks awfull..

-RoseSlayer
(P.S: It's darker because it's the back layer!)

Fundamentum W.I.P.
StumpyStrust
 « Reply #6 - Posted 2013-02-12 18:08:39 »

It looks like you are just drawing a semi transparent black square over the tiles.

If this is not with java2d you can just give it a color value of like .5f, .5f, .5f Basically, scaling down rgb.

If it is with java2d then there are many hacks with AlphaComposites you can use to get fast lighting.

I actually found a way to almost colorize a sprite like opengl without losing acceleration.

roseslayer

Junior Devvie

Medals: 2

 « Reply #7 - Posted 2013-02-12 20:41:49 »

It looks like you are just drawing a semi transparent black square over the tiles.

If this is not with java2d you can just give it a color value of like .5f, .5f, .5f Basically, scaling down rgb.

If it is with java2d then there are many hacks with AlphaComposites you can use to get fast lighting.

I actually found a way to almost colorize a sprite like opengl without losing acceleration.

Thanks for your reaction, I'm fearly new to programming but I know the basics etc. but however could your give me some more information about the .5f? how I use it as a code etc.

Thanks!
-RoseSlayer

Fundamentum W.I.P.

JGO Ninja

Medals: 26
Projects: 3
Exp: 6 years

One for all!

 « Reply #8 - Posted 2013-02-12 20:42:54 »

It looks like you are just drawing a semi transparent black square over the tiles.

It does look that way! Stop doing that, though. You can tint the sprite in Slick2d using
 1 `Color.grey.bind();`

and in LibGDX using
 1 `spriteBatch.setColor(Color.grey);`

JGO Ninja

Medals: 26
Projects: 3
Exp: 6 years

One for all!

 « Reply #9 - Posted 2013-02-12 20:50:03 »

Thanks!
-RoseSlayer

It's a floating point. You can (in most API's) specify a color using three or four floating point values, representing the red, green, blue and sometimes alpha component of a color. They range between 0 and 1. 1 means full blown power of that color, and 0 means no color.

For instance,
 1 `0f, 0f, 1f`
gives a nice blue color.

 1 `0f, 1f, 1f`
gives a margenta color.

The last floating point (the alpha one), specifies how transparent the color is - also ranging between 0 and 1. 1 for no transparency, and 0 for full transparency.
 1 `0f, 0f, 1f, 0.5f`
gives a nice see-through blue color.

This is just a way to specify color though. If you tint your images like I described above, it'll tint everything you draw thereafter with the color you specified.

The same call again, with parameters
 1 `0f, 0f, 0f`

will reset this, and you can continue drawing your sprites without having to worry about tinting.

StumpyStrust
 « Reply #10 - Posted 2013-02-13 00:33:32 »

Good explanation but to reset it do not set it to (0,0,0) as this should kill all color. It would be (1,1,1) to keep what ever the color of the sprite is. At least that is opengl, I do not know how slick does things under the covers.

Any time you render anything you can specify a tint or color. The default I always thought was (1,1,1,1) which is basically whatever the texture is. Note that I am referring to rendering textured quads/triangle Strips (sprites) in opengl and this does not all extend to 3D graphics.

roseslayer

Junior Devvie

Medals: 2

 « Reply #11 - Posted 2013-02-14 19:56:09 »

It looks like you are just drawing a semi transparent black square over the tiles.

It does look that way! Stop doing that, though. You can tint the sprite in Slick2d using
 1 `Color.grey.bind();`

and in LibGDX using
 1 `spriteBatch.setColor(Color.grey);`

This maybe sounds really stupid to you, but how to install Slick2d properly? I used: http://code.google.com/p/gate541/wiki/SlickAndEclipse but it doesn't seems to work, still gives an error at importing Slick2D..

Thanks
-RoseSlayer

Fundamentum W.I.P.
Pages: [1]
 ignore  |  Print

You cannot reply to this message, because it is very, very old.

 Riven (20 views) 2015-07-03 11:22:16 deepthought (45 views) 2015-06-30 15:39:44 deepthought (49 views) 2015-06-30 15:39:09 deepthought (62 views) 2015-06-30 15:36:52 Za\'Anzabar (30 views) 2015-06-29 05:44:54 TritonDreyja (45 views) 2015-06-24 17:10:40 CopyableCougar4 (44 views) 2015-06-23 00:34:45 BurntPizza (47 views) 2015-06-21 20:36:46 cookiecompiler (89 views) 2015-06-11 15:42:53 cookiecompiler (53 views) 2015-06-11 15:41:14
 princec 30x wessles 23x BurntPizza 19x CopyableCougar4 19x opiop65 18x Riven 15x nsigma 15x EgonOlsen 14x KaiHH 12x ags1 11x SauronWatchesYou 11x theagentd 11x KevinWorkman 11x sunburn 11x NegativeZero 10x DavidBVal 10x
 How Do I Expand My Game?by bashfrog2015-06-14 11:34:43List of Learning Resources2015-05-31 05:37:30Intersection Methodsby Roquen2015-05-29 08:19:33List of Learning Resources2015-05-05 10:20:32How to: JGO Wikiby Mac702015-02-17 20:56:162D Dynamic Lighting2015-01-01 20:25:42How do I start Java Game Development?by gouessej2014-12-27 19:41:21Resources for WIP gamesby kpars2014-12-18 10:26:14
 java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org