Moderator
M
Moderator
18:12, 7th Jan 2013
Magtheridon96: Approved.
vJASS version
GUI version
Magtheridon96: Approved.
vJASS version
GUI version
library RCSS initializer Init
//-------------------------------------------------------------------
//---- 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.
//-------------------------------------------------------------------
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 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]
local real temprichter
if (richter > RICHTER_MAX) then
set richter = RICHTER_MAX
endif
if (richter < RICHTER_MIN) then
set richter = RICHTER_MIN
endif
if (GetLocalPlayer() == p) then
set temprichter = playerCurrentShake[i] * Pow(10, richter)
call CameraSetTargetNoiseEx(playerCurrentShake[i] * 2.0, temprichter, true)
call CameraSetSourceNoiseEx(playerCurrentShake[i] * 2.0, temprichter, 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
set p = null
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
if GetLocalPlayer() == p then // Get enum player's camera location
set x = GetCameraTargetPositionX()
set y = GetCameraTargetPositionY()
endif
set dist = (x - eventX)*(x - eventX) + (y - eventY)*(y - eventY)
if (dist <= eventRange*eventRange) then // Check if it is in range of point
set playerCurrentShake[i] = ( playerCurrentShake[i] + ( eventShake * ( ( eventRange - dist ) / ( eventRange + dist ) ) ) ) //add shakiness
if not (IsPlayerInForce(p, shakingPlayers)) then
call ForceAddPlayer(shakingPlayers, p) //add player to shaking group
endif
endif
set p = null
endfunction
//Register new location shake event
public function 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
public function NewEventPlayer takes player p, real m returns nothing
local integer i = GetPlayerId(p)
set playerCurrentShake[i] = (playerCurrentShake[i] + m)
if not (IsPlayerInForce(p, shakingPlayers)) 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
private function Init takes nothing returns nothing
call TimerStart(CreateTimer(), LOOP_PERIOD, true, function Loop)
endfunction
endlibrary