Survival mode: Implement food eating.

This commit is contained in:
UnknownShadow200 2017-09-04 08:59:02 +10:00
parent 4de201d635
commit ba34b5e8ac
8 changed files with 77 additions and 52 deletions

View File

@ -41,30 +41,24 @@ namespace ClassicalSharp {
int btns = (left ? 1 : 0) + (right ? 1 : 0) + (middle ? 1 : 0);
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) {
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);
game.Mode.PickMiddle(old);
} else if (left) {
if (game.Mode.PickingLeft()) return;
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);
if (BlockInfo.Draw[old] == DrawType.Gas || !BlockInfo.CanDelete[old]) return;
game.Mode.PickLeft(old);
} else if (right) {
if (game.Mode.PickingRight()) return;
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 block = inv.Selected;

View File

@ -33,6 +33,14 @@ namespace ClassicalSharp.Mode {
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) {
Vector3I pos = game.SelectedPos.BlockPos;
game.UpdateBlock(pos.X, pos.Y, pos.Z, Block.Air);
@ -68,12 +76,9 @@ namespace ClassicalSharp.Mode {
game.UserEvents.RaiseBlockChanged(pos, old, block);
}
public bool PickEntity(byte id) { return false; }
public Widget MakeHotbar() { return new HotbarWidget(game); }
public void OnNewMapLoaded(Game game) {
}
public void OnNewMapLoaded(Game game) { }
public void Init(Game game) {
this.game = game;

View File

@ -14,10 +14,11 @@ namespace ClassicalSharp.Mode {
public interface IGameMode : IGameComponent {
bool HandlesKeyDown(Key key);
bool PickingLeft();
bool PickingRight();
void PickLeft(BlockID old);
void PickMiddle(BlockID old);
void PickRight(BlockID old, BlockID block);
bool PickEntity(byte id);
Widget MakeHotbar();
void BeginFrame(double delta);
void EndFrame(double delta);

View File

@ -26,6 +26,28 @@ namespace ClassicalSharp.Mode {
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) {
Vector3I pos = game.SelectedPos.BlockPos;
game.UpdateBlock(pos.X, pos.Y, pos.Z, Block.Air);
@ -33,8 +55,7 @@ namespace ClassicalSharp.Mode {
HandleDelete(old);
}
public void PickMiddle(BlockID old) {
}
public void PickMiddle(BlockID old) { }
public void PickRight(BlockID old, BlockID block) {
int index = game.Inventory.SelectedIndex, offset = game.Inventory.Offset;
@ -43,7 +64,11 @@ namespace ClassicalSharp.Mode {
Vector3I pos = game.SelectedPos.TranslatedPos;
game.UpdateBlock(pos.X, pos.Y, pos.Z, block);
game.UserEvents.RaiseBlockChanged(pos, old, block);
DepleteInventoryHeld();
}
void DepleteInventoryHeld() {
int index = game.Inventory.SelectedIndex, offset = game.Inventory.Offset;
invCount[offset + index]--;
if (invCount[offset + index] != 0) return;
@ -52,7 +77,7 @@ namespace ClassicalSharp.Mode {
game.Events.RaiseHeldBlockChanged();
}
public bool PickEntity(byte id) {
bool PickEntity(byte id) {
Entity entity = game.Entities[id];
LocalPlayer p = game.LocalPlayer;
@ -184,6 +209,11 @@ namespace ClassicalSharp.Mode {
}
wasOnGround = p.onGround;
CheckPlayerDied();
}
void CheckPlayerDied() {
LocalPlayer p = game.LocalPlayer;
if (p.Health <= 0 && !showedDeathScreen) {
showedDeathScreen = true;
game.Gui.SetNewScreen(new DeathScreen(game));

View File

@ -374,9 +374,6 @@ namespace ClassicalSharp.Network {
/// <summary> Full URL this item was downloaded from. </summary>
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>
public string ETag;
@ -390,7 +387,6 @@ namespace ClassicalSharp.Network {
TimeAdded = timeAdded;
TimeDownloaded = DateTime.UtcNow;
Url = url;
ResponseCode = code;
ETag = etag;
LastModified = lastModified;
}

View File

@ -56,7 +56,7 @@ namespace Launcher.Web {
request.KeepAlive = true;
request.CookieContainer = cookies;
request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
request.AutomaticDecompression = DecompressionMethods.GZip;
if (data != null) {
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8;";

View File

@ -65,19 +65,19 @@ void PerspectiveCamera_RegrabMouse(void) {
delta = Point2D_Empty;
}
#define sensiFactor (0.0002f / 3.0f * MATH_RAD2DEG)
#define slippery 0.97f
#define adjust 0.025f
#define CAMERA_SENSI_FACTOR (0.0002f / 3.0f * MATH_RAD2DEG)
#define CAMERA_SLIPPERY 0.97f
#define CAMERA_ADJUST 0.025f
Real32 speedX = 0.0f, speedY = 0.0f;
void PerspectiveCamera_UpdateMouseRotation(void) {
Real32 sensitivity = sensiFactor * Game_MouseSensitivity;
Real32 sensitivity = CAMERA_SENSI_FACTOR * Game_MouseSensitivity;
if (Game_SmoothCamera) {
speedX += delta.X * adjust;
speedX *= slippery;
speedY += delta.Y * adjust;
speedY *= slippery;
speedX += delta.X * CAMERA_ADJUST;
speedX *= CAMERA_SLIPPERY;
speedY += delta.Y * CAMERA_ADJUST;
speedY *= CAMERA_SLIPPERY;
} else {
speedX = (Real32)delta.X;
speedY = (Real32)delta.Y;

View File

@ -128,13 +128,12 @@ bool Entity_TouchesAnyWater(Entity* entity) {
}
#define maxAngle (110 * MATH_DEG2RAD)
#define armMax (60.0f * MATH_DEG2RAD)
#define legMax (80.0f * MATH_DEG2RAD)
#define idleMax (3.0f * MATH_DEG2RAD)
#define idleXPeriod (2.0f * MATH_PI / 5.0f)
#define idleZPeriod (2.0f * MATH_PI / 3.5f)
#define ANIM_MAX_ANGLE (110 * MATH_DEG2RAD)
#define ANIM_ARM_MAX (60.0f * MATH_DEG2RAD)
#define ANIM_LEG_MAX (80.0f * MATH_DEG2RAD)
#define ANIM_IDLE_MAX (3.0f * MATH_DEG2RAD)
#define ANIM_IDLE_XPERIOD (2.0f * MATH_PI / 5.0f)
#define ANIM_IDLE_ZPERIOD (2.0f * MATH_PI / 3.5f)
void AnimatedComp_DoTilt(Real32* tilt, bool 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) {
Real32 verAngle = 0.5f + 0.5f * Math_Sin(anim->WalkTime * flapSpeed);
Real32 zRot = -idleZRot - verAngle * anim->Swing * maxAngle;
Real32 horAngle = Math_Cos(anim->WalkTime) * anim->Swing * armMax * 1.5f;
Real32 zRot = -idleZRot - verAngle * anim->Swing * ANIM_MAX_ANGLE;
Real32 horAngle = Math_Cos(anim->WalkTime) * anim->Swing * ANIM_ARM_MAX * 1.5f;
Real32 xRot = idleXRot + horAngle;
if (left) {
@ -205,12 +204,12 @@ void AnimatedComp_GetCurrent(AnimatedComp* anim, Real32 t, bool calcHumanAnims)
anim->BobStrength = Math_Lerp(anim->BobStrengthO, anim->BobStrengthN, t);
Real32 idleTime = (Real32)Game_Accumulator;
Real32 idleXRot = Math_Sin(idleTime * idleXPeriod) * idleMax;
Real32 idleZRot = idleMax + Math_Cos(idleTime * idleZPeriod) * idleMax;
Real32 idleXRot = Math_Sin(idleTime * ANIM_IDLE_XPERIOD) * ANIM_IDLE_MAX;
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->LeftLegX = -(Math_Cos(anim->WalkTime) * anim->Swing * legMax);
anim->LeftLegX = -(Math_Cos(anim->WalkTime) * anim->Swing * ANIM_LEG_MAX);
anim->LeftLegZ = 0;
anim->RightLegX = -anim->LeftLegX; anim->RightLegZ = -anim->LeftLegZ;