This site requires JavaScript, please enable it in your browser!
Greenfoot back

Report as inappropriate.

FlyingRabidUnicornPig
FlyingRabidUnicornPig presents ...

2013/5/27

Dynamic Lighting

*Now with shorter description*
Controls:
Arrow Keys to move
"1" to set the light back to the torch flickering.
"2"-"5" to control the different aspects of the light. Press "w" to increase the value, and "s" to decrease, while pressing the number.
"2" is range, "3" is spread, "4" is intensity, "5" is background intensity.

This scenario has the LightActor class, which will look at specific objects that implement the AffectedByLight & StoresImage interfaces and "light" depending on how far away each pixel in the image is from the centerl

This scenario has some more handy classes:
- There is a Background actor subclass, which will automatically place itself in the center of the screen, and than create an image for itself that is as big as the world, and then will fill it up with a specific color. I created this because I had a weird glitch when I tried to implement that into a world.
- There is a Distance class, which will find distances from Actors, coordinates, and Points (java.awt.Point).
- There is also the TruePoint class, which will find what I like to call, the "True Point" of a specific spot on an Actor's image. To explain better: The GreenfootImage class will let you go through each pixel of the image, from (0,0) to (img.getWidth(), img.getHeight()). However, for this scenario, I needed the coordinates of each spot from the WORLD's perspective (to work correctly with the Distance class). So the TruePoint class will find that "True Point" in the world according to a "Normal Point" in an Actor's image. It may come very handy for others who want to work on projects like this, where you need to find the WORLD location of a point on an image.

Plans for the future:
- Accessibility with multiple LightActors (it gets real glitchy with more than one LightActor)
- Make different shades of light
- Better performance with more objects (gets laggy when there are a lot of objects in range)-
- The ability to make ovals and other shapes with the light, instead of a circle.

If you have any suggestions or tips, or find any bugs with the system, please write a comment below. I'll try to get more work into this after I get my big AP Computer Science final project done.
Yes, you can use this code. The "Open in Greenfoot" button is there for a reason. Please credit me if you do use this code.

5022 views / 1053 in the last 7 days

1 vote | 0 in the last 7 days

Tags: with-source

open in greenfoot
Your browser does not support the canvas tag.
JetLennitJetLennit

2013/5/27

I thought that was purposeful
A new version of this scenario was uploaded on Mon May 27 14:12:46 UTC 2013 Fixed a bug. Made scenario start by itself.
Yes, the images flicker because that's how I set the torch to work, I wanted it to be more realistic. I'm going to update it in a few minutes where you can have a solid image, and can change the intensity and other features.
Game/maniacGame/maniac

2013/5/27

shouldn't the flickering be more delayed then and be more random
I just wanted to create a quick example of the LightActor class to show what it could do. I wasn't thinking when I made it that that people might want to see just a normal LightActor without flickering, or a more realistic torch, with better flickering.
A new version of this scenario was uploaded on Mon May 27 15:07:46 UTC 2013 - Added way to make your own lighting. Press 1 to go back to the default torch flicker. Press 2 and "w" or "s" to increase/decrease the light range. Press 3 and "w" or "s" to increase/decrease the spread. Press 4 and "w" or "s" to increase/decrease the Intensity. Press 5 and "w" or "s" to increase/decrease the background intensity. - Handy counters in the top left tell you the current stats about the light
Note: After changing the background intensity, you need to move the range of the light to include or un-include a new block, then the affect will take place.
A new version of this scenario was uploaded on Mon May 27 15:38:00 UTC 2013 Updated setBackgroundIntensity() to update all the objects outside the range.
A new version of this scenario was uploaded on Sun Jun 09 23:14:55 UTC 2013 Increased performance when working with big, scrolling worlds, or other kinds of unbounded worlds.
A new version of this scenario was uploaded on Sun Jun 09 23:20:19 UTC 2013 Fixed Background class to automatically move itself back to the center if it was moved while paused or some other way.

See all comments

Want to leave a comment? You must first log in.

Who likes this?

sametguzelgun