Added in shake timer for ore veins.

This commit is contained in:
JoshuaNavarro 2019-08-16 12:39:27 -07:00
parent 16d35e2d42
commit eb5231e81a
2 changed files with 18 additions and 4 deletions

View File

@ -38,6 +38,8 @@ namespace Revitalize.Framework.Objects
public Enums.Direction facingDirection;
public int shakeTimer;
public BasicItemInformation()
{
this.name = "";
@ -57,6 +59,7 @@ namespace Revitalize.Framework.Objects
this.facingDirection = Enums.Direction.Down;
this.id = "";
this.shakeTimer = 0;
}
@ -88,9 +91,19 @@ namespace Revitalize.Framework.Objects
this.inventory = Inventory ?? new InventoryManager();
this.lightManager = Lights ?? new LightManager();
this.facingDirection = Enums.Direction.Down;
this.shakeTimer = 0;
}
/// <summary>
/// Gets an x offset for shaking an object. Source code used from game.
/// </summary>
/// <returns></returns>
public int shakeTimerOffset()
{
return (this.shakeTimer > 0 ? Game1.random.Next(-1, 2) : 0);
}
}
}

View File

@ -67,6 +67,7 @@ namespace Revitalize.Framework.Objects.Resources.OreVeins
{
base.updateWhenCurrentLocation(time, environment);
this.setHealth(this.healthValue);
this.info.shakeTimer -= time.ElapsedGameTime.Milliseconds;
}
public override void DayUpdate(GameLocation location)
@ -117,7 +118,8 @@ namespace Revitalize.Framework.Objects.Resources.OreVeins
if (this.location != null)
{
this.location.playSound("hammer");
ModCore.log("Ore has this much health left: "+this.healthValue);
//ModCore.log("Ore has this much health left: "+this.healthValue);
this.info.shakeTimer = 200;
}
return false;
}
@ -277,7 +279,6 @@ namespace Revitalize.Framework.Objects.Resources.OreVeins
/// <summary>What happens when the object is drawn at a tile location.</summary>
public override void draw(SpriteBatch spriteBatch, int x, int y, float alpha = 1f)
{
if (this.info == null)
{
Revitalize.ModCore.log("info is null");
@ -292,7 +293,7 @@ namespace Revitalize.Framework.Objects.Resources.OreVeins
if (this.animationManager.getExtendedTexture() == null)
ModCore.ModMonitor.Log("Tex Extended is null???");
spriteBatch.Draw(this.displayTexture, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(x * Game1.tileSize), y * Game1.tileSize)), new Rectangle?(this.animationManager.currentAnimation.sourceRectangle), this.info.drawColor * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, this.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, Math.Max(0f, (float)(y * Game1.tileSize) / 10000f));
spriteBatch.Draw(this.displayTexture, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(x * Game1.tileSize)+this.info.shakeTimerOffset(), (y * Game1.tileSize)+this.info.shakeTimerOffset())), new Rectangle?(this.animationManager.currentAnimation.sourceRectangle), this.info.drawColor * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, this.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, Math.Max(0f, (float)(y * Game1.tileSize) / 10000f));
// Log.AsyncG("ANIMATION IS NULL?!?!?!?!");
}
@ -311,7 +312,7 @@ namespace Revitalize.Framework.Objects.Resources.OreVeins
{
addedDepth += 1.0f;
}
this.animationManager.draw(spriteBatch, this.displayTexture, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(x * Game1.tileSize), y * Game1.tileSize)), new Rectangle?(this.animationManager.currentAnimation.sourceRectangle), this.info.drawColor * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, this.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, Math.Max(0f, (float)((y + addedDepth) * Game1.tileSize) / 10000f) + .00001f);
this.animationManager.draw(spriteBatch, this.displayTexture, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(x * Game1.tileSize)+this.info.shakeTimerOffset(), (y * Game1.tileSize)+this.info.shakeTimerOffset())), new Rectangle?(this.animationManager.currentAnimation.sourceRectangle), this.info.drawColor * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, this.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, Math.Max(0f, (float)((y + addedDepth) * Game1.tileSize) / 10000f) + .00001f);
try
{
this.animationManager.tickAnimation();