|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object wyvern.lib.properties.SimpleLightSource
This class provides a simple light that you can place in a map. It's not as sophisticated as the MovableLightSource, which keeps track of its owner/carrier as it moves around.
If you want to implement a custom light source, you'd be wise to subclass SimpleLightSource or MovableLightSource to leverage its existing behavior.
Field Summary | |
protected wyvern.kernel.lighting.RayShadowCaster |
caster_
|
static int |
DEFAULT_LIGHT_SOURCE_INTENSITY
The default intensity to use for light sources. |
protected int |
intensity_
|
protected int[][] |
localIntensity_
|
protected Point |
location_
|
protected GameMap |
map_
|
protected int[][] |
matrix_
|
Fields inherited from interface wyvern.lib.properties.LightingConstants |
DARKNESS, DAYLIGHT, DIM, DUSK, GLOOM, NUM_SHADES, SHADED, TWILIGHT |
Constructor Summary | |
SimpleLightSource()
Constructs a new SimpleLightSource with the default intensity. |
|
SimpleLightSource(int intensity)
Constructs a new SimpleLightSource |
Method Summary | |
void |
computeLocalIntensity()
This method fills the local light array. |
void |
computeMatrix()
Recomputes the intensity matrix by invoking the raycaster. |
static int |
getAlphaForLightLevel(int level)
Returns the percent opacity for a shading tile, given the lighting level. |
static int |
getDistance(int x,
int y)
Returns the integer distance from (0, 0) to the passed point. |
int |
getIntensity()
Returns the current intensity of this light source. |
int[][] |
getLightMatrix()
Returns the location list for the light source. |
Point |
getLocation()
Returns the location at the center of our lighting array. |
GameMap |
getMap()
Returns the map we're currently illuminating, if any. |
Point |
getMatrixLocation()
Returns the (x,y) location of the upper-left corner of the LightSource's local light matrix returned by calling getLightMatrix(). |
static int |
getShadingTile(int intensity)
Returns the database tile number of the tile to use for the passed lighting level. |
static void |
main(java.lang.String[] args)
Used for testing only. |
void |
recompute()
Tells the light source to recompute its intensity matrix. |
void |
remove()
Removes this light from its current map, if any. |
void |
setIntensity(int intensity)
Sets the intensity of the light source. |
void |
setLocation(Point loc)
Sets the location at the center of the area we should be illuminating. |
void |
setMap(GameMap map)
Tells us which map we're illuminating. |
void |
setMap(GameMap map,
int x,
int y)
Tells the light which map to illuminate. |
java.lang.String |
toString()
Returns a String representation of the object for debugging. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final int DEFAULT_LIGHT_SOURCE_INTENSITY
protected int[][] localIntensity_
protected int[][] matrix_
protected int intensity_
protected GameMap map_
protected Point location_
protected wyvern.kernel.lighting.RayShadowCaster caster_
Constructor Detail |
public SimpleLightSource(int intensity)
public SimpleLightSource()
Method Detail |
public static int getAlphaForLightLevel(int level)
level
- the lighting level at some point in the map
public static int getShadingTile(int intensity)
This method really ought to be in a LightManager class or something; right now it's living here because this is the only class that has any light-related code in it.
intensity
- the total lighting level in the map at
the desired location
public static int getDistance(int x, int y)
x
- local x coordinatey
- local y coordinatepublic int[][] getLightMatrix()
getLightMatrix
in interface LightSource
public Point getMatrixLocation()
getMatrixLocation
in interface LightSource
public void recompute()
This method is called by the map when a square becomes opaque or non-opaque within the radius illuminated by the light. The light removes itself from the map, computes its new lighting matrix, and re-adds itself at the same location.
recompute
in interface LightSource
public GameMap getMap()
public void setMap(GameMap map)
map
- the map to put the light inpublic void setMap(GameMap map, int x, int y)
setMap
in interface LightSource
map
- the map to put the light inx
- map x locationy
- map y locationpublic void remove()
remove
in interface LightSource
public int getIntensity()
public void setIntensity(int intensity)
intensity
- the radius of the light source.public Point getLocation()
public void setLocation(Point loc)
loc
- the new map (x, y) locationpublic void computeLocalIntensity()
0 0 1 1 1 0 0 0 1 2 2 2 1 0 1 2 3 3 3 2 1 1 2 3 4 3 2 1 1 2 3 3 3 2 1 0 1 2 2 2 1 0 0 0 1 1 1 0 0The light source is at the center, and intensity drops off as a linear function of distance. (N^2 is too harsh.) We use the computed intensity values to index into a table to select a dither pattern to draw. Any intensity above "daylight" gets no dither pattern; any intensity below some threshold (probably zero) gets complete darkness.
public void computeMatrix()
This method is called whenever the light is added to a map or moves within a map. It should also be called whenever any of the map's opaque squares change transparency status within reach of the light source.
public static void main(java.lang.String[] args)
public java.lang.String toString()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |