Code: Select all
/*
* GZDoom Strafing Camera Tilting
* Copyright (C) 2015 Nash Muhandes
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Feel free to do whatever you want with this, though credits would be
// appreciated! You don't need to ask for my permission to use this code
// in your mods.
// Nash
// This version contains also MaxED underwater effects... amazing!
//===========================================================================
//
// UTILITY FUNCTIONS
//
//===========================================================================
#include "zcommon.acs"
#library "maxdqtlt"
// player is on ground?
function int CheckPlayerOnGround(void)
{
int onground;
if (GetActorZ (0) == GetActorFloorZ (0) || GetActorVelZ(0) == 0 && !Spawn("Z_FloorCheck", GetActorX(0), GetActorY(0), GetActorZ(0) - (4 << 16), 0, GetActorAngle(0)))
{
onground = 1; //ground
}
else
{
onground = 0; //air
}
return onground;
}
// get player velocity
function int GetPlayerMoveSpeed(int p)
{
return VectorLength(GetActorVelX(p), GetActorVelY(p));
}
// input checking
function bool KeyUp(int key)
{
return !(GetPlayerInput(-1, INPUT_BUTTONS) & key);
}
function bool KeyDown(int key)
{
return !!(GetPlayerInput(-1, INPUT_BUTTONS) & key);
}
int dostrafetilt = 1; //nash
int uwrollammountcount = 70; //mxd
int uwrollammount[70] = {-0.012, -0.01199, -0.01195, -0.01189, -0.01181, -0.0117, -0.01157, -0.01141, -0.01123, -0.01103, -0.01081, -0.01057, -0.0103, -0.01001, -0.00971, -0.00938, -0.00904, -0.00867, -0.00829, -0.0079, -0.00748, -0.00705, -0.00661, -0.00615, -0.00569, -0.00521, -0.00472, -0.00422, -0.00371, -0.00319, -0.00267, -0.00214, -0.00161, -0.00108, -0.00054, 0, 0.00054, 0.00108, 0.00161, 0.00214, 0.00267, 0.00319, 0.00371, 0.00422, 0.00472, 0.00521, 0.00569, 0.00615, 0.00661, 0.00705, 0.00748, 0.0079, 0.00829, 0.00867, 0.00904, 0.00938, 0.00971, 0.01001, 0.0103, 0.01057, 0.01081, 0.01103, 0.01123, 0.01141, 0.01157, 0.0117, 0.01181, 0.01189, 0.01195, 0.01199}; //mxd
Script "Script_StrafeTilt" ENTER
{
int uwrollstep = 35; //mxd
int defaultuwrollstep = uwrollstep; //mxd
int uwrolldirection = 1; //mxd
while(true)
{
//mxd. Do underwater camera sway
if(GetActorProperty(0, APROP_Waterlevel) == 3)
{
ChangeActorRoll(0, uwrollammount[uwrollstep], true);
//Change rolling direction?
if(uwrollstep == uwrollammountcount - 1) uwrolldirection = -1;
else if(uwrollstep == 0) uwrolldirection = 1;
uwrollstep += uwrolldirection;
}
else if(uwrollstep != defaultuwrollstep) //mxd. De-roll camera afer leaving the water
{
if(uwrollstep > defaultuwrollstep) uwrollstep--;
else uwrollstep++;
ChangeActorRoll(0, uwrollammount[uwrollstep], true);
}
//Nash strafe tilt codes///////////////////////////////////////////////////
else if(dostrafetilt) //mxd. Do strafe tilting
{
int strafemod;
int strafe;
static int strafespeed = 0.0007;
// receive input
if (CheckPlayerOnGround() && GetPlayerMoveSpeed(PlayerNumber()) > 1.1) // only fast movement will cause tilt
{
strafemod = GetPlayerInput(-1, INPUT_SIDEMOVE) / 50;
}
else
{
// reset view
if (strafe < 0)
strafe += strafespeed;
if (strafe > 0)
strafe -= strafespeed;
}
// tilt left
if (strafemod < 0 && strafe >= strafemod)
{
strafe -= strafespeed;
}
// tilt right
if (strafemod > 0 && strafe <= strafemod)
{
strafe += strafespeed;
}
// reset view
// when no movement keys are pressed or if player starts to move slow
if ((!(KeyDown(BT_MOVELEFT) || GetPlayerInput(-1, INPUT_SIDEMOVE) < 0)
&& !(KeyDown(BT_MOVERIGHT) || GetPlayerInput(-1, INPUT_SIDEMOVE) > 0))
|| GetPlayerMoveSpeed(0) < 1.1)
{
if (strafe < 0)
strafe += strafespeed;
if (strafe > 0)
strafe -= strafespeed;
}
// limits
if (strafe < -1.0)
strafe = -1.0;
if (strafe > 1.0)
strafe = 1.0;
// tilt!
ChangeActorRoll(0, strafe, TRUE);
}
Delay(1);
}
}