Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (536)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Easy lightning (and chunk system)  (Read 1727 times)
0 Members and 1 Guest are viewing this topic.
Offline roseslayer

Junior Member


Medals: 1



« Posted 2013-02-11 16: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..

thanks for reading it already.
-RoseSlayer

Fundamentum W.I.P.
Offline cheatsguy

Junior Member


Medals: 3


Gamer turned Pixel Artist turned Programmer


« Reply #1 - Posted 2013-02-11 18: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 Wink

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/
Offline roseslayer

Junior Member


Medals: 1



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

Terraria sprites where for testing porpuse Cheesy 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.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline HeroesGraveDev

JGO Kernel


Medals: 238
Projects: 11
Exp: 2 years


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


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

Please, Please, PLEASE! spell it lighting.

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

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

Junior Member


Medals: 1



« Reply #5 - Posted 2013-02-12 16: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..

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

Fundamentum W.I.P.
Offline StumpyStrust
« Reply #6 - Posted 2013-02-12 19: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.

Offline roseslayer

Junior Member


Medals: 1



« Reply #7 - Posted 2013-02-12 21: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.
Offline Mads

JGO Ninja


Medals: 26
Projects: 3
Exp: 6 years


One for all!


« Reply #8 - Posted 2013-02-12 21: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);


Offline Mads

JGO Ninja


Medals: 26
Projects: 3
Exp: 6 years


One for all!


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

Could your give me some more information about the .5f?

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.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline StumpyStrust
« Reply #10 - Posted 2013-02-13 01: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.


Offline roseslayer

Junior Member


Medals: 1



« Reply #11 - Posted 2013-02-14 20: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.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Riven (18 views)
2014-07-29 18:09:19

Riven (13 views)
2014-07-29 18:08:52

Dwinin (12 views)
2014-07-29 10:59:34

E.R. Fleming (31 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (42 views)
2014-07-24 01:59:36

Riven (41 views)
2014-07-23 21:16:32

Riven (28 views)
2014-07-23 21:07:15

Riven (29 views)
2014-07-23 20:56:16

ctomni231 (60 views)
2014-07-18 06:55:21
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!