Flashlight: Difference between revisions

3,859 bytes added ,  21 November 2007
*>Monkey 05 06
mNo edit summary
*>Monkey 05 06
Line 1: Line 1:
{{Thread|30137.0|Flashlight module}} by [[monkey_05_06]].
{{Thread|30137.0|Flashlight module}} by [[monkey_05_06]].


[http://www.meleepta.com/file.php?dir=ags&file=Flashlight_2_0_BETA_2.rar Download v2.0 BETA 2]
[http://www.meleepta.com/file.php?dir=ags&file=Flashlight_2_0_BETA_3.rar Download v2.0 BETA 3]


[http://www.meleepta.com/file.php?dir=ags&file=Flashlight_1_9.rar Download v1.9]
[http://www.meleepta.com/file.php?dir=ags&file=Flashlight_1_9.rar Download v1.9]


==Description==
==Description==
Emulates the "flashlight" effect using a GUI or screen overlays.
Emulates the "flashlight" effect using a GUI or screen overlay.


==Macros (#define-s)==
==Macros (#define-s)==
====FLASHLIGHT_VERSION====
====FLASHLIGHT_VERSION====
Defines the current version of the module.
Defines the current version of the module.
====FLASHLIGHT_VERSION_200====
Defines version 2.0 of the module.


====FLASHLIGHT_VERSION_190====
====FLASHLIGHT_VERSION_190====
Line 24: Line 27:
Defines version 1.0 of the module.
Defines version 1.0 of the module.


====FLASHLIGHT_GUI====
==Functions and Properties==
Sets the module to {{link||GUI mode}}. If this macro is set, it must be defined to the script o-name of a GUI of which the first 5 controls are buttons. If not set the module will default to {{link||Overlay mode}}.
====Flashlight.BeamSprite====
''writeprotected DynamicSprite* Flashlight.BeamSprite''
 
Defines the DynamicSprite used as the 'beam' of the flashlight. This is essentially a black square with a transparent hole in the middle. You can use this property to delete the DynamicSprite before you quit the game and you can set the sprite using the Flashlight.SetBeamSprite method.
 
====Flashlight.Enabled====
''bool Flashlight.Enabled''
 
Sets whether or not the flashlight effect will be enabled. If no BeamSprite is set then this property will be set to false until the BeamSprite is properly set.
 
====Flashlight.FollowingCharacter====
''writeprotected Character* Flashlight.FollowingCharacter''
 
Returns the Character the flashlight beam is currently following (if any). If following the mouse or statically positioned this will return NULL. You can set the Character to follow using the Flashlight.SetFollowCharacter method.
 
====Flashlight.IsFollowingCharacter====
''writeprotected bool Flashlight.IsFollowingCharacter''
 
Returns whether the flashlight beam is following any character (this is the same as checking whether the FollowingCharacter property is NULL). You can lock the flashlight's beam to a Character's position using the Flashlight.SetFollowCharacter method.
 
====Flashlight.IsFollowingMouse====
''writeprotected bool Flashlight.IsFollowingMouse''


==Enumerated types==
Returns whether the flashlight beam is following the mouse. You can lock the flashlight's beam to the mouse position using the Flashlight.SetFollowMouse method.
====Flashlight_Vars====
=====eFlashlight_MaximumRadius=====
Defines the maximum radius of the flashlight beam.


=====eFlashlight_MinimumRadius=====
====Flashlight.IsFollowingPlayer====
Defines the minimum radius of the flashlight beam.
''writeprotected bool Flashlight.IsFollowingPlayer''


==Functions and Properties==
Returns whether the flashlight's beam is following the player Character. This will not actually test if the FollowingCharacter property is set to the current player Character; rather it simply determines whether the FollowingCharacter property will be updated if the player changes. You can lock the flashlight's beam to follow the player Character using the Flashlight.SetFollowCharacter method.
====Flashlight.CharacterToFollow====
''writeprotected int Flashlight.CharacterToFollow''


Defines the Character the flashlight will follow. If set to '''null''' the flashlight will follow the mouse instead.
====Flashlight.IsGUIMode====
''writeprotected bool Flashlight.IsGUIMode''


''See Also:'' {{link||Flashlight.FollowCharacter}}, {{link||Flashlight.FollowMouse}}
Returns whether the flashlight is using a GUI. The benefit of using a GUI is the ability to set transparency using the Flashlight.Transparency property. You can set the flashlight to GUI mode using the Flashlight.SetGUIMode method.


====Flashlight.FollowCharacter====
====Flashlight.IsOverlayMode====
''void Flashlight.FollowCharacter(Character* Char)''
''writeprotected bool Flashlight.IsOverlayMode''
''void Flashlight.SetCharacterToFollow(Character* Char)''


Sets the flashlight to follow Character CHAR. If CHAR is null then the flashlight will follow the mouse instead. If "Enforce object-based scripting" is turned off this function will be implemented as Flashlight.SetCharacterToFollow. The script autocomplete will automatically detect the correct version.
Returns whether the flashlight is using an Overlay. The draw-back to using an Overlay instead of a GUI is that you cannot set transparency. You can set the flashlight to Overlay mode using the Flashlight.SetOverlayMode method.


''See Also:'' {{link||Flashlight.CharacterToFollow}}, {{link||Flashlight.FollowMouse}}
====Flashlight.IsStatic====
''writeprotected bool Flashlight.IsStatic''


====Flashlight.FollowMouse====
Returns whether the flashlight's beam is statically positioned. This means that in order to move the flashlight you must manually modify the Flashlight.X and Flashlight.Y properties. You can lock the flashlight's beam to a static position using the Flashlight.SetStatic method.
''void Flashlight.FollowMouse()''


Sets the flashlight to follow the mouse instead of a Character. This is the same as passing '''null''' to {{link||Flashlight.FollowCharacter}}.
====Flashlight.Radius====
''float Flashlight.Radius''


''See Also:'' {{link||Flashlight.CharacterToFollow}}, {{link||Flashlight.FollowCharacter}}
Gets/sets the RADIUS (1/2 the diameter) of the flashlight beam. Cannot be set to less than 0.5 (it will be reset to 0.5 if set to less than this value).


====Flashlight.Enabled====
====Flashlight.ScaleBeam====
''bool Flashlight.Enabled''
''bool Flashlight.ScaleBeam''


Turns the flashlight effect on and off.
Controls whether the flashlight beam is scaled based on the scaling of the FollowingCharacter property. If not following a Character this does nothing. Note that the Flashlight.Radius property is NOT updated based upon any scaling, only the actual size of the beam will reflect this.


====Flashlight.IsFollowingCharacter====
====Flashlight.SetBeamSprite====
''writeprotected bool Flashlight.IsFollowingCharacter''
''void Flashlight.SetBeamSprite(DynamicSprite* beamSprite)''


Returns whether the flashlight is currently following a Character. This is the opposite of {{link||Flashlight.IsFollowingMouse}}.
Sets the sprite to use for the flashlight beam. NULL values will be rejected. It is possible to set an existing sprite as the beam sprite by passing DynamicSprite.CreateFromExistingSprite as the parameter. See Flashlight.BeamSprite for more information.


''See Also:'' {{link||Flashlight.FollowCharacter}}, {{link||Flashlight.IsFollowingMouse}}
====Flashlight.SetFollowCharacter====
''void Flashlight.SetFollowCharacter(Character*, optional bool followPlayer)''


====Flashlight.IsFollowingMouse====
Locks the flashlight's beam to the Character's position. If (and only if) the Character passed is the current player AND followPlayer is TRUE (the default) the FollowingCharacter property will be locked to the PLAYER Character, updating if the player is changed; otherwise the beam will be locked exclusively to the position of the passed Character. Note that the Character MUST be in the current room or the beam will be locked to the mouse position instead.
''writeprotected bool Flashlight.IsFollowingMouse''


Returns whether the flashlight is currently following the mouse. This is the opposite of {{link||Flashlight.IsFollowingCharacter}}.
====Flashlight.SetFollowMouse====
''void Flashlight.SetFollowMouse()''


''See Also:'' {{link||Flashlight.FollowMouse}}, {{link||Flashlight.IsFollowingCharacter}}
Locks the flashlight's beam to the mouse's position.


====Flashlight.Radius====
====Flashlight.SetGUIMode====
''float Flashlight.Radius''
''void Flashlight.SetGUIMode(GUI*)''


Gets/sets the radius of the flashlight beam.
Sets the flashlight to use the passed GUI (if valid, otherwise defaults to Overlay mode).


''Note that this is the '''radius''', not the diameter. This means that this property is half the width of the entire beam.''
====Flashlight.SetOverlayMode====
''void Flashlight.SetOverlayMode()''


====Flashlight.SetSprite====
Sets the flashlight to use an Overlay.
''void Flashlight.SetSprite(DynamicSprite* sprite)''


Allows you to set the sprite to use for the flashlight beam. To pass an existing sprite you can use {{link|DynamicSprite functions and properties|DynamicSprite.CreateFromExistingSprite}} as the parameter. This function will reject null pointers.
====Flashlight.SetStatic====
''void Flashlight.SetStatic()''


''See Also:'' {{link||Flashlight.Sprite}}
Locks the flashlight's beam to its current (X,Y) position. You can move it manually by modifying the X/Y properties, or lock it back to the mouse (Flashlight.SetFollowMouse) or a Character (Flashlight.SetFollowCharacter) using the appropriate functions.


====Flashlight.Sprite====
====Flashlight.ScreenSprite====
''writeprotected DynamicSprite* Flashlight.Sprite''
''writeprotected DynamicSprite* Flashlight.ScreenSprite''


The sprite used for the flashlight beam. You can use this property to delete the sprite before exiting your game, however you '''must''' ensure that {{link||Flashlight.Enabled}} is set to '''false''' first or your game will crash. This sprite is automatically loaded from "flashlight.bmp" in your game's Compiled folder if the file exists. If the file does not exist you '''must''' set this property with {{link||Flashlight.SetSprite}} '''before''' setting {{link||Flashlight.Enabled}} to true or your game will crash.
The DynamicSprite used to cover the screen. You can use this property to delete the DynamicSprite before you quit the game.


====Flashlight.Transparency====
====Flashlight.Transparency====
''int Flashlight.Transparency''
''int Flashlight.Transparency''


Sets the overall transparency for the darkened areas of the screen. This property can only be used in {{link||GUI mode}}. In {{link||Overlay mode}} this property will remain at 100 as Overlays cannot currently have transparency.
Sets the transparency for the (dark areas of the) flashlight effect. This is only valid if the flashlight is in GUI mode. This property is also passed through a bounding function similar to the way AGS's CHAR type works such that -1 will loop back around to 100, -2 to 99, -3 to 98, and 101 to 0, 102 to 1, 103 to 2, etc.
 
====Flashlight.X====
''int Flashlight.X''
 
Gets the X co-ordinate of the center of the flashlight beam. If the beam is statically positioned (Flashlight.SetStatic) you can also use this to set the X co-ordinate.
 
====Flashlight.Y====
''int Flashlight.Y''
 
Gets the Y co-ordinate of the center of the flashlight beam. If the beam is statically positioned (Flashlight.SetStatic) you can also use this to set the Y co-ordinate.


==Setup==
==Setup==
===Modes===
===Modes===
====GUI Mode====
====GUI mode====
To activate GUI mode you must put the following in the Flashlight module header:
GUI mode allows you to use {{link||Flashlight.Transparency|transparency}} in the darkened areas of the screen when applying the flashlight effect.
 
To activate GUI mode you can put the following in the Flashlight module header:


   #define FLASHLIGHT_GUI gFlashlight
   #define FLASHLIGHT_GUI gFlashlight


Where ''gFlashlight'' is the script o-name of your GUI. The first 5 controls of this GUI '''must''' be buttons or the module will crash.
Where ''gFlashlight'' is the script o-name of your GUI. The GUI no longer requires any controls (''Flashlight module v2.0 BETA 3''). Alternately you can set GUI mode at any time throughout the game by calling {{link||Flashlight.SetGUIMode}}.


====Overlay Mode====
====Overlay mode====
Overlay mode is the default mode for the module. You cannot use {{link||Flashlight.Transparency|transparency}} in Overlay mode. If you want to use transparency, use {{link||GUI mode}} instead. Overlay mode depends on the ability to create 5 Overlays, so if you use background speech or are creating your own overlays be aware of this as the Overlays may fail to be created (though under normal circumstances this should not happen).
Overlay mode is the default mode for the module. You cannot use {{link||Flashlight.Transparency|transparency}} in Overlay mode. If you want to use transparency, use {{link||GUI mode}} instead.


===Other Setup===
===Other Setup===
In order for the Flashlight module to work, you must either:
In order for the Flashlight module to work, you must:


a) include a "flashlight.bmp" file in your game's Compiled folder OR
a) include a "flashlight.bmp" file in your game's Compiled folder ''and/or''


b) call Flashlight.SetSprite on a valid DynamicSprite '''before''' turning the Flashlight effect on.
b) call {{link||Flashlight.SetBeamSprite}} on a valid {{link|DynamicSprite functions and properties||DynamicSprite}} '''before''' turning the Flashlight effect on.


Failure to do this will cause your game to crash.
Failure to do this will prevent the module from working properly and prevent the {{link||Flashlight.Enabled}} property from being set (it will reset to '''false''' every loop until the {{link||Flashlight.BeamSprite|BeamSprite}} is properly set.


==Licensing==
==Licensing==
Line 142: Line 176:


==Changelog==
==Changelog==
====Version 2.0 BETA 3====
Date:        21 November 2007, 2:57 P.M. GMT -6:00
Author:      monkey_05_06
Description: Uses RawDraw methods to only require two sprites instead of six,
              and only one Overlay instead of five. Also GUI no longer
              requires ANY controls as opposed to previous requisite of five.
              Designed to be forward-compatible with AGS 3.0 while remaining
              compatible with AGS 2.72.
              Renamed:
              Flashlight.CharacterToFollow to Flashlight.FollowingCharacter,
              Flashlight.FollowCharacter to Flashlight.SetFollowCharacter,
              Flashlight.FollowMouse to Flashlight.SetFollowMouse,
              Flashlight.SetSprite to Flashlight.SetBeamSprite, and
              Flashlight.Sprite to Flashlight.BeamSprite.
              Added:
              Flashlight.IsFollowingPlayer, Flashlight.IsGUIMode,
              Flashlight.IsOverlayMode, Flashlight.IsStatic,
              Flashlight.ScaleBeam, Flashlight.SetGUIMode,
              Flashlight.SetOverlayMode, Flashlight.SetStatic, and
              Flashlight.ScreenSprite.
====Version 2.0 BETA 2====
====Version 2.0 BETA 2====
   Date:        16 February 2007, 2:32 P.M. GMT -6:00
   Date:        16 February 2007, 2:32 P.M. GMT -6:00
Anonymous user