- Joined
- Jul 10, 2006
- Messages
- 3,315
I was requested to make a JASS version of my http://www.hiveworkshop.com/forums/spells-569/gui-camera-shake-system-1-03-a-227421/
I didn't really have the patience for the unnecessarily long JASS tutorials, so I mainly reverse engineered this from triggers and various JASS systems.
Also please point out anything that should be replaced with more efficient code. It is, after all, a GUI system.
-- UPDATED --
- It is now a library
- Removed locations, using sqrt and coords for distance
-- UPDATED 2 --
- Removed BJs
Thanks!
I didn't really have the patience for the unnecessarily long JASS tutorials, so I mainly reverse engineered this from triggers and various JASS systems.
Also please point out anything that should be replaced with more efficient code. It is, after all, a GUI system.
-- UPDATED --
- It is now a library
- Removed locations, using sqrt and coords for distance
-- UPDATED 2 --
- Removed BJs
JASS:
//-------------------------------------------------------------------
//---- Camera Shake System ----
//by rulerofiron99
//
// Functions:
// RCSS_NewEventLoc takes real TargetX, real TargetY, real Magnitude, real MaxRange
// TargetX/Y location of origin of shake
// Magnitude the magnitude of the camera shake at origin point
// MaxRange the maximum range at which players are added
//
// RCSS_NewEventPlayer takes player TargetPlayer, real Magnitude
// TargetPlayer the player to be shaken, not stirred
// Magnitude the amount of camera shake to be added to the player
//
// Configurables:
// LOOP_PERIOD the time between loops - how often the loop will run
// SHAKE_REDUCE_FLAT flat shake magnitude lost per loop
// SHAKE_REDUCE_PERCENT percent of current shake magnitude lost per loop
// SHAKE_THRESHOLD when shakiness goes below the threshold, it stops completely
// RICHTER_MAX the maximum magnitude of the shaking
// RICHTER_MIN the minimum magnitude of the shaking
// Note: The shake variable still goes above,
// and is then just to determine duration.
//-------------------------------------------------------------------
library CameraShakeSystem initializer Init
globals
//---- Camera Shake System ----
//Configurables
private constant real LOOP_PERIOD = 0.10
private constant real SHAKE_REDUCE_FLAT = 0.50
private constant real SHAKE_REDUCE_PERCENT = 0.05
private constant real SHAKE_THRESHOLD = 0.50
private constant real RICHTER_MAX = 5.0
private constant real RICHTER_MIN = 2.0
//System Variables
private trigger Setup = null
private force ShakingPlayers = CreateForce()
private real array PlayerCurrentShake
private real EventShake
private real EventRange
private real EventX
private real EventY
//-----------------------------
endglobals
//-------------------------------------
//Loop through players for camera shake
//-------------------------------------
private function LoopPerPlayer takes nothing returns nothing
local player p = GetEnumPlayer()
local integer i = GetPlayerId(p)
local real richter = PlayerCurrentShake[i]
if (richter > RICHTER_MAX) then
set richter = RICHTER_MAX
endif
if (richter < RICHTER_MIN) then
set richter = RICHTER_MIN
endif
if (GetLocalPlayer() == p) then
call CameraSetTargetNoiseEx(PlayerCurrentShake[i]*2.0, PlayerCurrentShake[i]*Pow(10,richter),true)
call CameraSetSourceNoiseEx(PlayerCurrentShake[i]*2.0, PlayerCurrentShake[i]*Pow(10,richter),true)
endif
set PlayerCurrentShake[i] = ( PlayerCurrentShake[i] - ( PlayerCurrentShake[i] * SHAKE_REDUCE_PERCENT ) )
set PlayerCurrentShake[i] = ( PlayerCurrentShake[i] - SHAKE_REDUCE_FLAT )
if ( PlayerCurrentShake[i] < SHAKE_THRESHOLD ) then
if (GetLocalPlayer() == p) then
call CameraSetSourceNoise(0, 0)
call CameraSetTargetNoise(0, 0)
endif
call ForceRemovePlayer(ShakingPlayers, p)
endif
endfunction
//---------------------------------------
//Loop through players for location event
//---------------------------------------
private function NewEventLocPerPlayer takes nothing returns nothing
local player p = GetEnumPlayer()
local integer i = GetPlayerId(p)
local real x
local real y
local real dist
local real add
if GetLocalPlayer() == p then // Get enum player's camera location
set x = GetCameraTargetPositionX()
set y = GetCameraTargetPositionY()
endif
set dist = SquareRoot(Pow((x-EventX), 2) + Pow((y-EventY), 2) )
if ( dist <= EventRange ) then // Check if it is in range of point
set add = ( EventShake * ( ( EventRange - dist ) / ( EventRange + dist ) ) )
set PlayerCurrentShake[i] = ( PlayerCurrentShake[i] + add ) //add shakiness
if ( IsPlayerInForce(p, ShakingPlayers) == false ) then
call ForceAddPlayer(ShakingPlayers, p) //add player to shaking group
endif
endif
endfunction
//----------------------------------
//Register new location shake event
//----------------------------------
function RCSS_NewEventLoc takes real x, real y, real m, real r returns nothing
set EventX = x
set EventY = y
set EventShake = m
set EventRange = r
call ForForce( bj_FORCE_ALL_PLAYERS, function NewEventLocPerPlayer )
endfunction
//-------------------------------
//Register new player shake event
//-------------------------------
function RCSS_NewEventPlayer takes player p, real m returns nothing
local integer i = GetPlayerId(p)
set PlayerCurrentShake[i] = (PlayerCurrentShake[i] + m)
if (IsPlayerInForce(p, ShakingPlayers) == false) then
call ForceAddPlayer(ShakingPlayers, p)
endif
endfunction
//----------------------------
//Main loop for camera shaking
//----------------------------
private function Loop takes nothing returns nothing
call ForForce(ShakingPlayers, function LoopPerPlayer)
endfunction
//--------------------
//Intialize the system
//--------------------
private function Init takes nothing returns nothing
set Setup = CreateTrigger( )
call TriggerRegisterTimerEvent( Setup, LOOP_PERIOD, true )
call TriggerAddAction( Setup, function Loop )
endfunction
endlibrary
//------------------------------------------
//End of camera shake system
//------------------------------------------
Thanks!
Last edited: