mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-19 04:26:52 -04:00
Survival mode: Implement food eating.
This commit is contained in:
parent
4de201d635
commit
ba34b5e8ac
@ -40,31 +40,25 @@ namespace ClassicalSharp {
|
|||||||
|
|
||||||
int btns = (left ? 1 : 0) + (right ? 1 : 0) + (middle ? 1 : 0);
|
int btns = (left ? 1 : 0) + (right ? 1 : 0) + (middle ? 1 : 0);
|
||||||
if (btns > 1 || game.Gui.ActiveScreen.HandlesAllInput || inv.Selected == Block.Invalid) return;
|
if (btns > 1 || game.Gui.ActiveScreen.HandlesAllInput || inv.Selected == Block.Invalid) return;
|
||||||
|
|
||||||
// always play delete animations, even if we aren't picking a block.
|
|
||||||
if (left) {
|
|
||||||
game.HeldBlockRenderer.ClickAnim(true);
|
|
||||||
byte id = game.Entities.GetClosetPlayer(game.LocalPlayer);
|
|
||||||
if (id != EntityList.SelfID && game.Mode.PickEntity(id)) return;
|
|
||||||
}
|
|
||||||
if (!game.SelectedPos.Valid) return;
|
|
||||||
|
|
||||||
if (middle) {
|
if (middle) {
|
||||||
Vector3I pos = game.SelectedPos.BlockPos;
|
Vector3I pos = game.SelectedPos.BlockPos;
|
||||||
if (!game.World.IsValidPos(pos)) return;
|
if (!game.SelectedPos.Valid || !game.World.IsValidPos(pos)) return;
|
||||||
|
|
||||||
BlockID old = game.World.GetBlock(pos);
|
BlockID old = game.World.GetBlock(pos);
|
||||||
game.Mode.PickMiddle(old);
|
game.Mode.PickMiddle(old);
|
||||||
} else if (left) {
|
} else if (left) {
|
||||||
|
if (game.Mode.PickingLeft()) return;
|
||||||
Vector3I pos = game.SelectedPos.BlockPos;
|
Vector3I pos = game.SelectedPos.BlockPos;
|
||||||
if (!game.World.IsValidPos(pos)) return;
|
if (!game.SelectedPos.Valid || !game.World.IsValidPos(pos)) return;
|
||||||
|
|
||||||
BlockID old = game.World.GetBlock(pos);
|
BlockID old = game.World.GetBlock(pos);
|
||||||
if (BlockInfo.Draw[old] == DrawType.Gas || !BlockInfo.CanDelete[old]) return;
|
if (BlockInfo.Draw[old] == DrawType.Gas || !BlockInfo.CanDelete[old]) return;
|
||||||
game.Mode.PickLeft(old);
|
game.Mode.PickLeft(old);
|
||||||
} else if (right) {
|
} else if (right) {
|
||||||
|
if (game.Mode.PickingRight()) return;
|
||||||
Vector3I pos = game.SelectedPos.TranslatedPos;
|
Vector3I pos = game.SelectedPos.TranslatedPos;
|
||||||
if (!game.World.IsValidPos(pos)) return;
|
if (!game.SelectedPos.Valid || !game.World.IsValidPos(pos)) return;
|
||||||
|
|
||||||
BlockID old = game.World.GetBlock(pos);
|
BlockID old = game.World.GetBlock(pos);
|
||||||
BlockID block = inv.Selected;
|
BlockID block = inv.Selected;
|
||||||
|
@ -33,6 +33,14 @@ namespace ClassicalSharp.Mode {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool PickingLeft() {
|
||||||
|
// always play delete animations, even if we aren't picking a block.
|
||||||
|
game.HeldBlockRenderer.ClickAnim(true);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool PickingRight() { return false; }
|
||||||
|
|
||||||
public void PickLeft(BlockID old) {
|
public void PickLeft(BlockID old) {
|
||||||
Vector3I pos = game.SelectedPos.BlockPos;
|
Vector3I pos = game.SelectedPos.BlockPos;
|
||||||
game.UpdateBlock(pos.X, pos.Y, pos.Z, Block.Air);
|
game.UpdateBlock(pos.X, pos.Y, pos.Z, Block.Air);
|
||||||
@ -67,13 +75,10 @@ namespace ClassicalSharp.Mode {
|
|||||||
game.UpdateBlock(pos.X, pos.Y, pos.Z, block);
|
game.UpdateBlock(pos.X, pos.Y, pos.Z, block);
|
||||||
game.UserEvents.RaiseBlockChanged(pos, old, block);
|
game.UserEvents.RaiseBlockChanged(pos, old, block);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Widget MakeHotbar() { return new HotbarWidget(game); }
|
||||||
|
|
||||||
public bool PickEntity(byte id) { return false; }
|
public void OnNewMapLoaded(Game game) { }
|
||||||
public Widget MakeHotbar() { return new HotbarWidget(game); }
|
|
||||||
|
|
||||||
|
|
||||||
public void OnNewMapLoaded(Game game) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Init(Game game) {
|
public void Init(Game game) {
|
||||||
this.game = game;
|
this.game = game;
|
||||||
|
@ -14,10 +14,11 @@ namespace ClassicalSharp.Mode {
|
|||||||
public interface IGameMode : IGameComponent {
|
public interface IGameMode : IGameComponent {
|
||||||
|
|
||||||
bool HandlesKeyDown(Key key);
|
bool HandlesKeyDown(Key key);
|
||||||
|
bool PickingLeft();
|
||||||
|
bool PickingRight();
|
||||||
void PickLeft(BlockID old);
|
void PickLeft(BlockID old);
|
||||||
void PickMiddle(BlockID old);
|
void PickMiddle(BlockID old);
|
||||||
void PickRight(BlockID old, BlockID block);
|
void PickRight(BlockID old, BlockID block);
|
||||||
bool PickEntity(byte id);
|
|
||||||
Widget MakeHotbar();
|
Widget MakeHotbar();
|
||||||
void BeginFrame(double delta);
|
void BeginFrame(double delta);
|
||||||
void EndFrame(double delta);
|
void EndFrame(double delta);
|
||||||
|
@ -24,7 +24,29 @@ namespace ClassicalSharp.Mode {
|
|||||||
|
|
||||||
public SurvivalGameMode() { invCount[8] = 10; } // tnt
|
public SurvivalGameMode() { invCount[8] = 10; } // tnt
|
||||||
|
|
||||||
public bool HandlesKeyDown(Key key) { return false; }
|
public bool HandlesKeyDown(Key key) { return false; }
|
||||||
|
|
||||||
|
public bool PickingLeft() {
|
||||||
|
// always play delete animations, even if we aren't picking a block.
|
||||||
|
game.HeldBlockRenderer.ClickAnim(true);
|
||||||
|
byte id = game.Entities.GetClosetPlayer(game.LocalPlayer);
|
||||||
|
return id != EntityList.SelfID && PickEntity(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool PickingRight() {
|
||||||
|
if (game.Inventory.Selected == Block.RedMushroom) {
|
||||||
|
DepleteInventoryHeld();
|
||||||
|
game.LocalPlayer.Health -= 5;
|
||||||
|
CheckPlayerDied();
|
||||||
|
return true;
|
||||||
|
} else if (game.Inventory.Selected == Block.BrownMushroom) {
|
||||||
|
DepleteInventoryHeld();
|
||||||
|
game.LocalPlayer.Health += 5;
|
||||||
|
if (game.LocalPlayer.Health > 20) game.LocalPlayer.Health = 20;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public void PickLeft(BlockID old) {
|
public void PickLeft(BlockID old) {
|
||||||
Vector3I pos = game.SelectedPos.BlockPos;
|
Vector3I pos = game.SelectedPos.BlockPos;
|
||||||
@ -33,8 +55,7 @@ namespace ClassicalSharp.Mode {
|
|||||||
HandleDelete(old);
|
HandleDelete(old);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PickMiddle(BlockID old) {
|
public void PickMiddle(BlockID old) { }
|
||||||
}
|
|
||||||
|
|
||||||
public void PickRight(BlockID old, BlockID block) {
|
public void PickRight(BlockID old, BlockID block) {
|
||||||
int index = game.Inventory.SelectedIndex, offset = game.Inventory.Offset;
|
int index = game.Inventory.SelectedIndex, offset = game.Inventory.Offset;
|
||||||
@ -43,7 +64,11 @@ namespace ClassicalSharp.Mode {
|
|||||||
Vector3I pos = game.SelectedPos.TranslatedPos;
|
Vector3I pos = game.SelectedPos.TranslatedPos;
|
||||||
game.UpdateBlock(pos.X, pos.Y, pos.Z, block);
|
game.UpdateBlock(pos.X, pos.Y, pos.Z, block);
|
||||||
game.UserEvents.RaiseBlockChanged(pos, old, block);
|
game.UserEvents.RaiseBlockChanged(pos, old, block);
|
||||||
|
DepleteInventoryHeld();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DepleteInventoryHeld() {
|
||||||
|
int index = game.Inventory.SelectedIndex, offset = game.Inventory.Offset;
|
||||||
invCount[offset + index]--;
|
invCount[offset + index]--;
|
||||||
if (invCount[offset + index] != 0) return;
|
if (invCount[offset + index] != 0) return;
|
||||||
|
|
||||||
@ -52,7 +77,7 @@ namespace ClassicalSharp.Mode {
|
|||||||
game.Events.RaiseHeldBlockChanged();
|
game.Events.RaiseHeldBlockChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool PickEntity(byte id) {
|
bool PickEntity(byte id) {
|
||||||
Entity entity = game.Entities[id];
|
Entity entity = game.Entities[id];
|
||||||
LocalPlayer p = game.LocalPlayer;
|
LocalPlayer p = game.LocalPlayer;
|
||||||
|
|
||||||
@ -184,6 +209,11 @@ namespace ClassicalSharp.Mode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
wasOnGround = p.onGround;
|
wasOnGround = p.onGround;
|
||||||
|
CheckPlayerDied();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CheckPlayerDied() {
|
||||||
|
LocalPlayer p = game.LocalPlayer;
|
||||||
if (p.Health <= 0 && !showedDeathScreen) {
|
if (p.Health <= 0 && !showedDeathScreen) {
|
||||||
showedDeathScreen = true;
|
showedDeathScreen = true;
|
||||||
game.Gui.SetNewScreen(new DeathScreen(game));
|
game.Gui.SetNewScreen(new DeathScreen(game));
|
||||||
|
@ -369,14 +369,11 @@ namespace ClassicalSharp.Network {
|
|||||||
public DateTime TimeAdded;
|
public DateTime TimeAdded;
|
||||||
|
|
||||||
/// <summary> Point in time the item was fully downloaded. </summary>
|
/// <summary> Point in time the item was fully downloaded. </summary>
|
||||||
public DateTime TimeDownloaded;
|
public DateTime TimeDownloaded;
|
||||||
|
|
||||||
/// <summary> Full URL this item was downloaded from. </summary>
|
/// <summary> Full URL this item was downloaded from. </summary>
|
||||||
public string Url;
|
public string Url;
|
||||||
|
|
||||||
/// <summary> HTTP status code returned by the server for this request. </summary>
|
|
||||||
public HttpStatusCode ResponseCode;
|
|
||||||
|
|
||||||
/// <summary> Unique identifier assigned by the server to this item. </summary>
|
/// <summary> Unique identifier assigned by the server to this item. </summary>
|
||||||
public string ETag;
|
public string ETag;
|
||||||
|
|
||||||
@ -390,7 +387,6 @@ namespace ClassicalSharp.Network {
|
|||||||
TimeAdded = timeAdded;
|
TimeAdded = timeAdded;
|
||||||
TimeDownloaded = DateTime.UtcNow;
|
TimeDownloaded = DateTime.UtcNow;
|
||||||
Url = url;
|
Url = url;
|
||||||
ResponseCode = code;
|
|
||||||
ETag = etag;
|
ETag = etag;
|
||||||
LastModified = lastModified;
|
LastModified = lastModified;
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ namespace Launcher.Web {
|
|||||||
request.KeepAlive = true;
|
request.KeepAlive = true;
|
||||||
request.CookieContainer = cookies;
|
request.CookieContainer = cookies;
|
||||||
|
|
||||||
request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
|
request.AutomaticDecompression = DecompressionMethods.GZip;
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
request.Method = "POST";
|
request.Method = "POST";
|
||||||
request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8;";
|
request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8;";
|
||||||
|
@ -65,19 +65,19 @@ void PerspectiveCamera_RegrabMouse(void) {
|
|||||||
delta = Point2D_Empty;
|
delta = Point2D_Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define sensiFactor (0.0002f / 3.0f * MATH_RAD2DEG)
|
#define CAMERA_SENSI_FACTOR (0.0002f / 3.0f * MATH_RAD2DEG)
|
||||||
#define slippery 0.97f
|
#define CAMERA_SLIPPERY 0.97f
|
||||||
#define adjust 0.025f
|
#define CAMERA_ADJUST 0.025f
|
||||||
|
|
||||||
Real32 speedX = 0.0f, speedY = 0.0f;
|
Real32 speedX = 0.0f, speedY = 0.0f;
|
||||||
void PerspectiveCamera_UpdateMouseRotation(void) {
|
void PerspectiveCamera_UpdateMouseRotation(void) {
|
||||||
Real32 sensitivity = sensiFactor * Game_MouseSensitivity;
|
Real32 sensitivity = CAMERA_SENSI_FACTOR * Game_MouseSensitivity;
|
||||||
|
|
||||||
if (Game_SmoothCamera) {
|
if (Game_SmoothCamera) {
|
||||||
speedX += delta.X * adjust;
|
speedX += delta.X * CAMERA_ADJUST;
|
||||||
speedX *= slippery;
|
speedX *= CAMERA_SLIPPERY;
|
||||||
speedY += delta.Y * adjust;
|
speedY += delta.Y * CAMERA_ADJUST;
|
||||||
speedY *= slippery;
|
speedY *= CAMERA_SLIPPERY;
|
||||||
} else {
|
} else {
|
||||||
speedX = (Real32)delta.X;
|
speedX = (Real32)delta.X;
|
||||||
speedY = (Real32)delta.Y;
|
speedY = (Real32)delta.Y;
|
||||||
|
@ -128,13 +128,12 @@ bool Entity_TouchesAnyWater(Entity* entity) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#define maxAngle (110 * MATH_DEG2RAD)
|
#define ANIM_MAX_ANGLE (110 * MATH_DEG2RAD)
|
||||||
#define armMax (60.0f * MATH_DEG2RAD)
|
#define ANIM_ARM_MAX (60.0f * MATH_DEG2RAD)
|
||||||
#define legMax (80.0f * MATH_DEG2RAD)
|
#define ANIM_LEG_MAX (80.0f * MATH_DEG2RAD)
|
||||||
#define idleMax (3.0f * MATH_DEG2RAD)
|
#define ANIM_IDLE_MAX (3.0f * MATH_DEG2RAD)
|
||||||
#define idleXPeriod (2.0f * MATH_PI / 5.0f)
|
#define ANIM_IDLE_XPERIOD (2.0f * MATH_PI / 5.0f)
|
||||||
#define idleZPeriod (2.0f * MATH_PI / 3.5f)
|
#define ANIM_IDLE_ZPERIOD (2.0f * MATH_PI / 3.5f)
|
||||||
|
|
||||||
|
|
||||||
void AnimatedComp_DoTilt(Real32* tilt, bool reduce) {
|
void AnimatedComp_DoTilt(Real32* tilt, bool reduce) {
|
||||||
if (reduce) {
|
if (reduce) {
|
||||||
@ -147,8 +146,8 @@ void AnimatedComp_DoTilt(Real32* tilt, bool reduce) {
|
|||||||
|
|
||||||
void AnimatedComp_PerpendicularAnim(AnimatedComp* anim, Real32 flapSpeed, Real32 idleXRot, Real32 idleZRot, bool left) {
|
void AnimatedComp_PerpendicularAnim(AnimatedComp* anim, Real32 flapSpeed, Real32 idleXRot, Real32 idleZRot, bool left) {
|
||||||
Real32 verAngle = 0.5f + 0.5f * Math_Sin(anim->WalkTime * flapSpeed);
|
Real32 verAngle = 0.5f + 0.5f * Math_Sin(anim->WalkTime * flapSpeed);
|
||||||
Real32 zRot = -idleZRot - verAngle * anim->Swing * maxAngle;
|
Real32 zRot = -idleZRot - verAngle * anim->Swing * ANIM_MAX_ANGLE;
|
||||||
Real32 horAngle = Math_Cos(anim->WalkTime) * anim->Swing * armMax * 1.5f;
|
Real32 horAngle = Math_Cos(anim->WalkTime) * anim->Swing * ANIM_ARM_MAX * 1.5f;
|
||||||
Real32 xRot = idleXRot + horAngle;
|
Real32 xRot = idleXRot + horAngle;
|
||||||
|
|
||||||
if (left) {
|
if (left) {
|
||||||
@ -205,12 +204,12 @@ void AnimatedComp_GetCurrent(AnimatedComp* anim, Real32 t, bool calcHumanAnims)
|
|||||||
anim->BobStrength = Math_Lerp(anim->BobStrengthO, anim->BobStrengthN, t);
|
anim->BobStrength = Math_Lerp(anim->BobStrengthO, anim->BobStrengthN, t);
|
||||||
|
|
||||||
Real32 idleTime = (Real32)Game_Accumulator;
|
Real32 idleTime = (Real32)Game_Accumulator;
|
||||||
Real32 idleXRot = Math_Sin(idleTime * idleXPeriod) * idleMax;
|
Real32 idleXRot = Math_Sin(idleTime * ANIM_IDLE_XPERIOD) * ANIM_IDLE_MAX;
|
||||||
Real32 idleZRot = idleMax + Math_Cos(idleTime * idleZPeriod) * idleMax;
|
Real32 idleZRot = ANIM_IDLE_MAX + Math_Cos(idleTime * ANIM_IDLE_ZPERIOD) * ANIM_IDLE_MAX;
|
||||||
|
|
||||||
anim->LeftArmX = (Math_Cos(anim->WalkTime) * anim->Swing * armMax) - idleXRot;
|
anim->LeftArmX = (Math_Cos(anim->WalkTime) * anim->Swing * ANIM_ARM_MAX) - idleXRot;
|
||||||
anim->LeftArmZ = -idleZRot;
|
anim->LeftArmZ = -idleZRot;
|
||||||
anim->LeftLegX = -(Math_Cos(anim->WalkTime) * anim->Swing * legMax);
|
anim->LeftLegX = -(Math_Cos(anim->WalkTime) * anim->Swing * ANIM_LEG_MAX);
|
||||||
anim->LeftLegZ = 0;
|
anim->LeftLegZ = 0;
|
||||||
|
|
||||||
anim->RightLegX = -anim->LeftLegX; anim->RightLegZ = -anim->LeftLegZ;
|
anim->RightLegX = -anim->LeftLegX; anim->RightLegZ = -anim->LeftLegZ;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user