mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-01-22 17:12:25 -05:00
Various simplifications.
This commit is contained in:
parent
dc2b67d538
commit
bae3b3d32e
4 changed files with 32 additions and 37 deletions
|
@ -187,11 +187,8 @@ namespace ClassicalSharp {
|
|||
Velocity.Y -= 0.08f;
|
||||
|
||||
if( BlockUnderFeet == Block.Ice ) {
|
||||
// Limit velocity while travelling on ice.
|
||||
if( Velocity.X > 0.25f ) Velocity.X = 0.25f;
|
||||
if( Velocity.X < -0.25f ) Velocity.X = -0.25f;
|
||||
if( Velocity.Z > 0.25f ) Velocity.Z = 0.25f;
|
||||
if( Velocity.Z < -0.25f ) Velocity.Z = -0.25f;
|
||||
Utils.Clamp( ref Velocity.X, -0.25f, 0.25f );
|
||||
Utils.Clamp( ref Velocity.Z, -0.25f, 0.25f );
|
||||
} else if( onGround || flying ) {
|
||||
// Apply air resistance or ground friction
|
||||
Velocity.X *= 0.6f;
|
||||
|
@ -209,7 +206,8 @@ namespace ClassicalSharp {
|
|||
|
||||
bool jumping, speeding, flying, noClip, flyingDown, flyingUp;
|
||||
public void ParseHackFlags( string name, string motd ) {
|
||||
if( name.Contains( "-hax" ) || motd.Contains( "-hax" ) ) {
|
||||
string joined = name + motd;
|
||||
if( joined.Contains( "-hax" ) ) {
|
||||
CanFly = CanNoclip = CanSpeed = CanRespawn = false;
|
||||
Window.CanUseThirdPersonCamera = false;
|
||||
Window.SetCamera( false );
|
||||
|
@ -219,32 +217,32 @@ namespace ClassicalSharp {
|
|||
}
|
||||
|
||||
// Determine if specific hacks are or are not allowed.
|
||||
if( name.Contains( "+fly" ) || motd.Contains( "+fly" ) ) {
|
||||
if( joined.Contains( "+fly" ) ) {
|
||||
CanFly = true;
|
||||
} else if( name.Contains( "-fly" ) || motd.Contains( "-fly" ) ) {
|
||||
} else if( joined.Contains( "-fly" ) ) {
|
||||
CanFly = false;
|
||||
}
|
||||
if( name.Contains( "+noclip" ) || motd.Contains( "+noclip" ) ) {
|
||||
if( joined.Contains( "+noclip" ) ) {
|
||||
CanNoclip = true;
|
||||
} else if( name.Contains( "-noclip" ) || motd.Contains( "-noclip" ) ) {
|
||||
} else if( joined.Contains( "-noclip" ) ) {
|
||||
CanNoclip = false;
|
||||
}
|
||||
if( name.Contains( "+speed" ) || motd.Contains( "+speed" ) ) {
|
||||
if( joined.Contains( "+speed" ) ) {
|
||||
CanSpeed = true;
|
||||
} else if( name.Contains( "-speed" ) || motd.Contains( "-speed" ) ) {
|
||||
} else if( joined.Contains( "-speed" ) ) {
|
||||
CanSpeed = false;
|
||||
}
|
||||
if( name.Contains( "+respawn" ) || motd.Contains( "+respawn" ) ) {
|
||||
if( joined.Contains( "+respawn" ) ) {
|
||||
CanRespawn = true;
|
||||
} else if( name.Contains( "-respawn" ) || motd.Contains( "-respawn" ) ) {
|
||||
} else if( joined.Contains( "-respawn" ) ) {
|
||||
CanRespawn = false;
|
||||
}
|
||||
|
||||
// Operator override.
|
||||
if( UserType == 0x64 ) {
|
||||
if( name.Contains( "+ophax" ) || motd.Contains( "+ophax" ) ) {
|
||||
if( joined.Contains( "+ophax" ) ) {
|
||||
CanFly = CanNoclip = CanSpeed = CanRespawn = true;
|
||||
} else if( name.Contains( "-ophax" ) || motd.Contains( "-ophax" ) ) {
|
||||
} else if( joined.Contains( "-ophax" ) ) {
|
||||
CanFly = CanNoclip = CanSpeed = CanRespawn = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ namespace ClassicalSharp {
|
|||
public const float Width = 0.6f;
|
||||
public const float EyeHeight = 1.625f;
|
||||
public const float Height = 1.8f;
|
||||
public const float Depth = 0.6f;
|
||||
public const float Depth = 0.6f;
|
||||
|
||||
public override Vector3 Size {
|
||||
get { return new Vector3( Width, Height, Depth ); }
|
||||
|
@ -43,22 +43,19 @@ namespace ClassicalSharp {
|
|||
|
||||
/// <summary> Gets the block just underneath the player's feet position. </summary>
|
||||
public Block BlockUnderFeet {
|
||||
get {
|
||||
if( map == null || map.IsNotLoaded ) return Block.Air;
|
||||
Vector3I blockCoords = Vector3I.Floor( Position.X, Position.Y - 0.01f, Position.Z );
|
||||
if( !map.IsValidPos( blockCoords ) ) return Block.Air;
|
||||
return (Block)map.GetBlock( blockCoords );
|
||||
}
|
||||
get { return GetBlock( new Vector3( Position.X, Position.Y - 0.01f, Position.Z ) ); }
|
||||
}
|
||||
|
||||
/// <summary> Gets the block at player's eye position. </summary>
|
||||
public Block BlockAtHead {
|
||||
get {
|
||||
if( map == null || map.IsNotLoaded ) return Block.Air;
|
||||
Vector3I blockCoords = Vector3I.Floor( EyePosition );
|
||||
if( !map.IsValidPos( blockCoords ) ) return Block.Air;
|
||||
return (Block)map.GetBlock( blockCoords );
|
||||
}
|
||||
get { return GetBlock( EyePosition ); }
|
||||
}
|
||||
|
||||
Block GetBlock( Vector3 coords ) {
|
||||
if( map == null || map.IsNotLoaded ) return Block.Air;
|
||||
Vector3I blockCoords = Vector3I.Floor( coords );
|
||||
return map.IsValidPos( blockCoords ) ?
|
||||
(Block)map.GetBlock( blockCoords ) : Block.Air;
|
||||
}
|
||||
|
||||
public abstract void Tick( double delta );
|
||||
|
@ -91,13 +88,13 @@ namespace ClassicalSharp {
|
|||
const float legMax = (float)( 80 * Math.PI / 180.0 );
|
||||
const float idleMax = (float)( 3 * Math.PI / 180.0 );
|
||||
const float idleXPeriod = (float)( 2 * Math.PI / 5f );
|
||||
const float idleZPeriod = (float)( 2 * Math.PI / 3.5f );
|
||||
const float idleZPeriod = (float)( 2 * Math.PI / 3.5f );
|
||||
protected void SetCurrentAnimState( float t ) {
|
||||
float swing = Utils.Lerp( swingO, swingN, t );
|
||||
float walkTime = Utils.Lerp( walkTimeO, walkTimeN, t );
|
||||
float idleTime = (float)( Window.accumulator );
|
||||
float idleXRot = (float)( Math.Sin( idleTime * idleXPeriod ) * idleMax );
|
||||
float idleZRot = (float)( idleMax + Math.Cos( idleTime * idleZPeriod ) * idleMax );
|
||||
float idleZRot = (float)( idleMax + Math.Cos( idleTime * idleZPeriod ) * idleMax );
|
||||
|
||||
leftArmXRot = (float)( Math.Cos( walkTime ) * swing * armMax ) - idleXRot;
|
||||
rightArmXRot = -leftArmXRot;
|
||||
|
|
|
@ -76,7 +76,7 @@ namespace ClassicalSharp {
|
|||
Orientation.X += delta.X * sensitivity;
|
||||
Orientation.Y += delta.Y * sensitivity;
|
||||
|
||||
Clamp( ref Orientation.Y, halfPi + 0.01f, threeHalfPi - 0.01f );
|
||||
Utils.Clamp( ref Orientation.Y, halfPi + 0.01f, threeHalfPi - 0.01f );
|
||||
LocationUpdate update = LocationUpdate.MakeOri(
|
||||
(float)Utils.RadiansToDegrees( Orientation.X ),
|
||||
(float)Utils.RadiansToDegrees( Orientation.Y - Math.PI )
|
||||
|
@ -91,11 +91,6 @@ namespace ClassicalSharp {
|
|||
CentreMousePosition();
|
||||
UpdateMouseRotation();
|
||||
}
|
||||
|
||||
static void Clamp( ref float value, float min, float max ) {
|
||||
if( value < min ) value = min;
|
||||
if( value > max ) value = max;
|
||||
}
|
||||
}
|
||||
|
||||
public class ThirdPersonCamera : PerspectiveCamera {
|
||||
|
|
|
@ -22,6 +22,11 @@ namespace ClassicalSharp {
|
|||
|
||||
public static string AppName = "ClassicalSharp 0.5";
|
||||
|
||||
public static void Clamp( ref float value, float min, float max ) {
|
||||
if( value < min ) value = min;
|
||||
if( value > max ) value = max;
|
||||
}
|
||||
|
||||
public static int NextPowerOf2( int value ) {
|
||||
int next = 1;
|
||||
while( value > next ) {
|
||||
|
|
Loading…
Reference in a new issue