Finished base code for basic renderer. Now all I have to do is create the character renderer and AssetManager...

This commit is contained in:
2018-02-23 23:16:10 -08:00
parent 1fc38b964c
commit b57a5f506f
6 changed files with 502 additions and 7 deletions

View File

@ -0,0 +1,134 @@
using CustomNPCFramework.Framework.NPCS;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using StardewValley;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CustomNPCFramework.Framework.ModularNPCS
{
public class AnimatedSpriteCollection
{
AnimatedSprite leftSprite;
AnimatedSprite rightSprite;
AnimatedSprite upSprite;
AnimatedSprite downSprite;
public AnimatedSprite currentSprite;
/// <summary>
/// Constructor.
/// </summary>
/// <param name="LeftSprite">Left animated sprite for this piece.</param>
/// <param name="RightSprite">Right animated sprite for this piece.</param>
/// <param name="UpSprite">Up animated sprite for this piece.</param>
/// <param name="DownSprite">Down animated sprite for this piece.</param>
/// <param name="startingSpriteDirection"></param>
public AnimatedSpriteCollection(AnimatedSprite LeftSprite,AnimatedSprite RightSprite,AnimatedSprite UpSprite,AnimatedSprite DownSprite,Direction startingSpriteDirection)
{
this.leftSprite = LeftSprite;
this.rightSprite = RightSprite;
this.upSprite = UpSprite;
this.downSprite = DownSprite;
if (startingSpriteDirection == Direction.down)
{
setDown();
}
if (startingSpriteDirection == Direction.left)
{
setLeft();
}
if (startingSpriteDirection == Direction.right)
{
setRight();
}
if (startingSpriteDirection == Direction.up)
{
setUp();
}
}
/// <summary>
/// Sets the current
/// </summary>
public void setLeft()
{
this.currentSprite = leftSprite;
}
public void setRight()
{
this.currentSprite = rightSprite;
}
public void setDown()
{
this.currentSprite = downSprite;
}
public void setUp()
{
this.currentSprite = upSprite;
}
/// <summary>
/// Used to draw the sprite to the screen.
/// </summary>
/// <param name="b"></param>
/// <param name="screenPosition"></param>
/// <param name="layerDepth"></param>
public void draw(SpriteBatch b, Vector2 screenPosition, float layerDepth)
{
b.Draw(this.currentSprite.Texture, screenPosition, new Rectangle?(this.currentSprite.sourceRect), Color.White, 0.0f, Vector2.Zero, (float)Game1.pixelZoom, this.currentSprite.currentAnimation == null || !this.currentSprite.currentAnimation[this.currentSprite.currentAnimationIndex].flip ? SpriteEffects.None : SpriteEffects.FlipHorizontally, layerDepth);
}
/// <summary>
/// Used to draw the sprite to the screen.
/// </summary>
/// <param name="b"></param>
/// <param name="screenPosition"></param>
/// <param name="layerDepth"></param>
/// <param name="xOffset"></param>
/// <param name="yOffset"></param>
/// <param name="c"></param>
/// <param name="flip"></param>
/// <param name="scale"></param>
/// <param name="rotation"></param>
/// <param name="characterSourceRectOffset"></param>
public void draw(SpriteBatch b, Vector2 screenPosition, float layerDepth, int xOffset, int yOffset, Color c, bool flip = false, float scale = 1f, float rotation = 0.0f, bool characterSourceRectOffset = false)
{
b.Draw(this.currentSprite.Texture, screenPosition, new Rectangle?(new Rectangle(this.currentSprite.sourceRect.X + xOffset, this.currentSprite.sourceRect.Y + yOffset, this.currentSprite.sourceRect.Width, this.currentSprite.sourceRect.Height)), c, rotation, characterSourceRectOffset ? new Vector2((float)(this.currentSprite.spriteWidth / 2), (float)((double)this.currentSprite.spriteHeight * 3.0 / 4.0)) : Vector2.Zero, scale, flip || this.currentSprite.currentAnimation != null && this.currentSprite.currentAnimation[this.currentSprite.currentAnimationIndex].flip ? SpriteEffects.FlipHorizontally : SpriteEffects.None, layerDepth);
}
/// <summary>
/// A very verbose asset drawer.
/// </summary>
/// <param name="b"></param>
/// <param name="npc"></param>
/// <param name="position"></param>
/// <param name="sourceRectangle"></param>
/// <param name="color"></param>
/// <param name="alpha"></param>
/// <param name="origin"></param>
/// <param name="scale"></param>
/// <param name="effects"></param>
/// <param name="layerDepth"></param>
public void draw(SpriteBatch b, ExtendedNPC npc, Vector2 position, Rectangle sourceRectangle,Color color, float alpha,Vector2 origin,float scale,SpriteEffects effects,float layerDepth)
{
b.Draw(this.currentSprite.Texture,position,sourceRectangle, color* alpha, npc.rotation, origin,scale,effects,layerDepth);
//b.Draw(this.Sprite.Texture, npc.getLocalPosition(Game1.viewport) + new Vector2((float)(this.sprite.spriteWidth * Game1.pixelZoom / 2), (float)(this.GetBoundingBox().Height / 2)) + (this.shakeTimer > 0 ? new Vector2((float)Game1.random.Next(-1, 2), (float)Game1.random.Next(-1, 2)) : Vector2.Zero), new Microsoft.Xna.Framework.Rectangle?(this.Sprite.SourceRect), Color.White * alpha, this.rotation, new Vector2((float)(this.sprite.spriteWidth / 2), (float)((double)this.sprite.spriteHeight * 3.0 / 4.0)), Math.Max(0.2f, this.scale) * (float)Game1.pixelZoom, this.flip || this.sprite.currentAnimation != null && this.sprite.currentAnimation[this.sprite.currentAnimationIndex].flip ? SpriteEffects.FlipHorizontally : SpriteEffects.None, Math.Max(0.0f, this.drawOnTop ? 0.991f : (float)this.getStandingY() / 10000f));
}
/// <summary>
/// Animate the current sprite. Theoreticlly works from index offset to how many frames
/// </summary>
/// <param name="intervalFromCharacter"></param>
public void Animate(float intervalFromCharacter)
{
this.currentSprite.Animate(Game1.currentGameTime, 0, 3, intervalFromCharacter);
}
}
}

View File

@ -0,0 +1,184 @@
using CustomNPCFramework.Framework.NPCS;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CustomNPCFramework.Framework.ModularNPCS
{
public class CharacterAnimation
{
public AnimatedSpriteCollection hair;
public AnimatedSpriteCollection body;
public AnimatedSpriteCollection eyes;
public AnimatedSpriteCollection shirt;
public AnimatedSpriteCollection pants;
public AnimatedSpriteCollection shoes;
public List<AnimatedSpriteCollection> accessories;
public CharacterAnimation(AnimatedSpriteCollection bodyAnimation, AnimatedSpriteCollection eyeAnimation, AnimatedSpriteCollection hairAnimation, AnimatedSpriteCollection shirtAnimation, AnimatedSpriteCollection pantsAnimation, AnimatedSpriteCollection shoesAnimation,List<AnimatedSpriteCollection> accessoriesWithAnimations)
{
this.body = bodyAnimation;
this.hair = hairAnimation;
this.eyes = eyeAnimation;
this.shirt = shirtAnimation;
this.pants = pantsAnimation;
this.shoes = shoesAnimation;
this.accessories = accessoriesWithAnimations;
}
public void setLeft()
{
this.body.setLeft();
this.hair.setLeft();
this.eyes.setLeft();
this.shirt.setLeft();
this.pants.setLeft();
this.shoes.setLeft();
foreach(var accessory in this.accessories)
{
accessory.setLeft();
}
}
public void setRight()
{
this.body.setRight();
this.hair.setRight();
this.eyes.setRight();
this.shirt.setRight();
this.pants.setRight();
this.shoes.setRight();
foreach (var accessory in this.accessories)
{
accessory.setRight();
}
}
public void setUp()
{
this.body.setUp();
this.hair.setUp();
this.eyes.setUp();
this.shirt.setUp();
this.pants.setUp();
this.shoes.setUp();
foreach (var accessory in this.accessories)
{
accessory.setUp();
}
}
public void setDown()
{
this.body.setDown();
this.hair.setDown();
this.eyes.setDown();
this.shirt.setDown();
this.pants.setDown();
this.shoes.setDown();
foreach (var accessory in this.accessories)
{
accessory.setDown();
}
}
public void Animate(float animationInterval)
{
this.body.Animate(animationInterval);
this.hair.Animate(animationInterval);
this.eyes.Animate(animationInterval);
this.shirt.Animate(animationInterval);
this.pants.Animate(animationInterval);
this.shoes.Animate(animationInterval);
foreach(var accessory in this.accessories)
{
accessory.Animate(animationInterval);
}
}
/// <summary>
/// Used to draw the sprite to the screen.
/// </summary>
/// <param name="b"></param>
/// <param name="screenPosition"></param>
/// <param name="layerDepth"></param>
public void draw(SpriteBatch b, Vector2 screenPosition, float layerDepth)
{
this.body.draw(b,screenPosition,layerDepth);
this.hair.draw(b, screenPosition, layerDepth);
this.eyes.draw(b, screenPosition, layerDepth);
this.shirt.draw(b, screenPosition, layerDepth);
this.pants.draw(b, screenPosition, layerDepth);
this.shoes.draw(b, screenPosition, layerDepth);
foreach (var accessory in this.accessories)
{
accessory.draw(b, screenPosition, layerDepth);
}
//b.Draw(this.currentSprite.Texture, screenPosition, new Rectangle?(this.currentSprite.sourceRect), Color.White, 0.0f, Vector2.Zero, (float)Game1.pixelZoom, this.currentSprite.currentAnimation == null || !this.currentSprite.currentAnimation[this.currentSprite.currentAnimationIndex].flip ? SpriteEffects.None : SpriteEffects.FlipHorizontally, layerDepth);
}
/// <summary>
/// Used to draw the sprite to the screen.
/// </summary>
/// <param name="b"></param>
/// <param name="screenPosition"></param>
/// <param name="layerDepth"></param>
/// <param name="xOffset"></param>
/// <param name="yOffset"></param>
/// <param name="c"></param>
/// <param name="flip"></param>
/// <param name="scale"></param>
/// <param name="rotation"></param>
/// <param name="characterSourceRectOffset"></param>
public void draw(SpriteBatch b, Vector2 screenPosition, float layerDepth, int xOffset, int yOffset, Color c, bool flip = false, float scale = 1f, float rotation = 0.0f, bool characterSourceRectOffset = false)
{
// b.Draw(this.currentSprite.Texture, screenPosition, new Rectangle?(new Rectangle(this.currentSprite.sourceRect.X + xOffset, this.currentSprite.sourceRect.Y + yOffset, this.currentSprite.sourceRect.Width, this.currentSprite.sourceRect.Height)), c, rotation, characterSourceRectOffset ? new Vector2((float)(this.currentSprite.spriteWidth / 2), (float)((double)this.currentSprite.spriteHeight * 3.0 / 4.0)) : Vector2.Zero, scale, flip || this.currentSprite.currentAnimation != null && this.currentSprite.currentAnimation[this.currentSprite.currentAnimationIndex].flip ? SpriteEffects.FlipHorizontally : SpriteEffects.None, layerDepth);
this.body.draw(b, screenPosition, layerDepth, xOffset, yOffset, c, flip, scale, rotation, characterSourceRectOffset);
this.hair.draw(b, screenPosition, layerDepth, xOffset, yOffset, c, flip, scale, rotation, characterSourceRectOffset);
this.eyes.draw(b, screenPosition, layerDepth, xOffset, yOffset, c, flip, scale, rotation, characterSourceRectOffset);
this.shirt.draw(b, screenPosition, layerDepth, xOffset, yOffset, c, flip, scale, rotation, characterSourceRectOffset);
this.pants.draw(b, screenPosition, layerDepth, xOffset, yOffset, c, flip, scale, rotation, characterSourceRectOffset);
this.shoes.draw(b, screenPosition, layerDepth, xOffset, yOffset, c, flip, scale, rotation, characterSourceRectOffset);
foreach(var accessory in this.accessories)
{
accessory.draw(b, screenPosition, layerDepth, xOffset, yOffset, c, flip, scale, rotation, characterSourceRectOffset);
}
}
/// <summary>
/// A very verbose asset drawer.
/// </summary>
/// <param name="b"></param>
/// <param name="npc"></param>
/// <param name="position"></param>
/// <param name="sourceRectangle"></param>
/// <param name="color"></param>
/// <param name="alpha"></param>
/// <param name="origin"></param>
/// <param name="scale"></param>
/// <param name="effects"></param>
/// <param name="layerDepth"></param>
public void draw(SpriteBatch b, ExtendedNPC npc, Vector2 position, Rectangle sourceRectangle, Color color, float alpha, Vector2 origin, float scale, SpriteEffects effects, float layerDepth)
{
this.body.draw(b, npc, position, sourceRectangle, color, alpha, origin, scale, effects, layerDepth);
this.hair.draw(b, npc, position, sourceRectangle, color, alpha, origin, scale, effects, layerDepth);
this.eyes.draw(b, npc, position, sourceRectangle, color, alpha, origin, scale, effects, layerDepth);
this.shirt.draw(b, npc, position, sourceRectangle, color, alpha, origin, scale, effects, layerDepth);
this.pants.draw(b, npc, position, sourceRectangle, color, alpha, origin, scale, effects, layerDepth);
this.shoes.draw(b, npc, position, sourceRectangle, color, alpha, origin, scale, effects, layerDepth);
foreach(var accessory in this.accessories)
{
accessory.draw(b, npc, position, sourceRectangle, color, alpha, origin, scale, effects, layerDepth);
}
}
}
}

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CustomNPCFramework.Framework.ModularNPCS
{
public enum Direction
{
up,
right,
down,
left
}
}

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CustomNPCFramework.Framework.ModularNPCS.ModularRenderers
{
class AnimationKeys
{
public static string standingKey = "standing";
public static string walkingKey = "walking";
public static string sittingKey = "sitting";
public static string swimmingKey = "swimming";
}
}

View File

@ -0,0 +1,136 @@
using CustomNPCFramework.Framework.NPCS;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CustomNPCFramework.Framework.ModularNPCS.ModularRenderers
{
public class BasicRenderer
{
public Dictionary<string, CharacterAnimation> animationList;
public CharacterAnimation currentAnimation;
public BasicRenderer(CharacterAnimation standingAnimation,CharacterAnimation walkingAnimation, CharacterAnimation swimmingAnimation)
{
animationList = new Dictionary<string, CharacterAnimation>();
animationList.Add(AnimationKeys.standingKey, standingAnimation);
animationList.Add(AnimationKeys.walkingKey, walkingAnimation);
animationList.Add(AnimationKeys.swimmingKey, swimmingAnimation);
setAnimation(AnimationKeys.standingKey);
}
/// <summary>
/// Sets the animation associated with the key name; If it fails the npc will just default to standing.
/// </summary>
/// <param name="key"></param>
public virtual void setAnimation(string key)
{
this.currentAnimation = animationList[key];
if (this.currentAnimation == null) this.setAnimation(AnimationKeys.standingKey);
}
public virtual void setDirection(int facingDirection)
{
if (facingDirection == 0) setUp();
if (facingDirection == 1) setRight();
if (facingDirection == 2) setDown();
if (facingDirection == 2) setLeft();
}
public virtual void setLeft()
{
this.currentAnimation.setLeft();
}
public virtual void setRight()
{
this.currentAnimation.setRight();
}
public virtual void setUp()
{
this.currentAnimation.setUp();
}
public virtual void setDown()
{
this.currentAnimation.setDown();
}
/// <summary>
/// Used to draw the sprite to the screen.
/// </summary>
/// <param name="b"></param>
/// <param name="screenPosition"></param>
/// <param name="layerDepth"></param>
public virtual void draw(SpriteBatch b, Vector2 screenPosition, float layerDepth)
{
this.currentAnimation.draw(b, screenPosition, layerDepth);
}
/// <summary>
/// Used to draw the sprite to the screen.
/// </summary>
/// <param name="b"></param>
/// <param name="screenPosition"></param>
/// <param name="layerDepth"></param>
/// <param name="xOffset"></param>
/// <param name="yOffset"></param>
/// <param name="c"></param>
/// <param name="flip"></param>
/// <param name="scale"></param>
/// <param name="rotation"></param>
/// <param name="characterSourceRectOffset"></param>
public virtual void draw(SpriteBatch b, Vector2 screenPosition, float layerDepth, int xOffset, int yOffset, Color c, bool flip = false, float scale = 1f, float rotation = 0.0f, bool characterSourceRectOffset = false)
{
this.currentAnimation.draw(b, screenPosition, layerDepth, xOffset, yOffset, c, flip, scale, rotation, characterSourceRectOffset);
}
/// <summary>
/// A very verbose asset drawer.
/// </summary>
/// <param name="b"></param>
/// <param name="npc"></param>
/// <param name="position"></param>
/// <param name="sourceRectangle"></param>
/// <param name="color"></param>
/// <param name="alpha"></param>
/// <param name="origin"></param>
/// <param name="scale"></param>
/// <param name="effects"></param>
/// <param name="layerDepth"></param>
public void draw(SpriteBatch b, ExtendedNPC npc, Vector2 position, Rectangle sourceRectangle, Color color, float alpha, Vector2 origin, float scale, SpriteEffects effects, float layerDepth)
{
this.currentAnimation.draw(b, npc, position, sourceRectangle, color, alpha, origin, scale, effects, layerDepth);
}
public virtual void Animate(float interval)
{
this.currentAnimation.Animate(interval);
}
/// <summary>
/// Wrapper for a draw function that accepts rectangles to be null.
/// </summary>
/// <param name="b"></param>
/// <param name="extendedNPC"></param>
/// <param name="vector21"></param>
/// <param name="v1"></param>
/// <param name="white"></param>
/// <param name="rotation"></param>
/// <param name="vector22"></param>
/// <param name="v2"></param>
/// <param name="spriteEffects"></param>
/// <param name="v3"></param>
public void draw(SpriteBatch b, ExtendedNPC extendedNPC, Vector2 vector21, Rectangle? v1, Color white, float rotation, Vector2 vector22, float v2, SpriteEffects spriteEffects, float v3)
{
this.draw(b, extendedNPC, vector21, v1, white, rotation, vector22, v2, spriteEffects, v3);
}
}
}

View File

@ -1,4 +1,5 @@
using Microsoft.Xna.Framework; using CustomNPCFramework.Framework.ModularNPCS.ModularRenderers;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using StardewValley; using StardewValley;
using StardewValley.Characters; using StardewValley.Characters;
@ -14,8 +15,9 @@ using xTile.Tiles;
namespace CustomNPCFramework.Framework.NPCS namespace CustomNPCFramework.Framework.NPCS
{ {
class ExtendedNPC :StardewValley.NPC public class ExtendedNPC :StardewValley.NPC
{ {
public BasicRenderer characterRenderer;
public ExtendedNPC() :base() public ExtendedNPC() :base()
{ {
@ -158,6 +160,11 @@ namespace CustomNPCFramework.Framework.NPCS
} }
} }
/// <summary>
/// Used to draw the npc with the custom renderer.
/// </summary>
/// <param name="b"></param>
/// <param name="alpha"></param>
public override void draw(SpriteBatch b, float alpha = 1f) public override void draw(SpriteBatch b, float alpha = 1f)
{ {
if (this.sprite == null || this.isInvisible || !Utility.isOnScreen(this.position, 2 * Game1.tileSize)) if (this.sprite == null || this.isInvisible || !Utility.isOnScreen(this.position, 2 * Game1.tileSize))
@ -165,13 +172,15 @@ namespace CustomNPCFramework.Framework.NPCS
//Checks if the npc is swimming. If not draw it's default graphic. Do characters aside from Farmer and Penny Swim??? //Checks if the npc is swimming. If not draw it's default graphic. Do characters aside from Farmer and Penny Swim???
if (this.swimming) if (this.swimming)
{ {
b.Draw(this.Sprite.Texture, this.getLocalPosition(Game1.viewport) + new Vector2((float)(Game1.tileSize / 2), (float)(Game1.tileSize + Game1.tileSize / 4 + this.yJumpOffset * 2)) + (this.shakeTimer > 0 ? new Vector2((float)Game1.random.Next(-1, 2), (float)Game1.random.Next(-1, 2)) : Vector2.Zero) - new Vector2(0.0f, this.yOffset), new Microsoft.Xna.Framework.Rectangle?(new Microsoft.Xna.Framework.Rectangle(this.sprite.SourceRect.X, this.sprite.SourceRect.Y, this.sprite.SourceRect.Width, this.sprite.SourceRect.Height / 2 - (int)((double)this.yOffset / (double)Game1.pixelZoom))), Color.White, this.rotation, new Vector2((float)(Game1.tileSize / 2), (float)(Game1.tileSize * 3 / 2)) / 4f, Math.Max(0.2f, this.scale) * (float)Game1.pixelZoom, this.flip ? SpriteEffects.FlipHorizontally : SpriteEffects.None, Math.Max(0.0f, this.drawOnTop ? 0.991f : (float)this.getStandingY() / 10000f)); this.characterRenderer.setAnimation(AnimationKeys.swimmingKey);
Vector2 localPosition = this.getLocalPosition(Game1.viewport); this.characterRenderer.setDirection(this.facingDirection);
b.Draw(Game1.staminaRect, new Microsoft.Xna.Framework.Rectangle((int)localPosition.X + (int)this.yOffset + Game1.pixelZoom * 2, (int)localPosition.Y - 32 * Game1.pixelZoom + this.sprite.SourceRect.Height * Game1.pixelZoom + Game1.tileSize * 3 / 4 + this.yJumpOffset * 2 - (int)this.yOffset, this.sprite.SourceRect.Width * Game1.pixelZoom - (int)this.yOffset * 2 - Game1.pixelZoom * 4, Game1.pixelZoom), new Microsoft.Xna.Framework.Rectangle?(Game1.staminaRect.Bounds), Color.White * 0.75f, 0.0f, Vector2.Zero, SpriteEffects.None, (float)((double)this.getStandingY() / 10000.0 + 1.0 / 1000.0)); this.characterRenderer.draw(b,this,this.getLocalPosition(Game1.viewport) + new Vector2((float)(Game1.tileSize / 2), (float)(Game1.tileSize + Game1.tileSize / 4 + this.yJumpOffset * 2)) + (this.shakeTimer > 0 ? new Vector2((float)Game1.random.Next(-1, 2), (float)Game1.random.Next(-1, 2)) : Vector2.Zero) - new Vector2(0.0f, this.yOffset), new Microsoft.Xna.Framework.Rectangle?(new Microsoft.Xna.Framework.Rectangle(this.sprite.SourceRect.X, this.sprite.SourceRect.Y, this.sprite.SourceRect.Width, this.sprite.SourceRect.Height / 2 - (int)((double)this.yOffset / (double)Game1.pixelZoom))), Color.White, this.rotation, new Vector2((float)(Game1.tileSize / 2), (float)(Game1.tileSize * 3 / 2)) / 4f, Math.Max(0.2f, this.scale) * (float)Game1.pixelZoom, this.flip ? SpriteEffects.FlipHorizontally : SpriteEffects.None, Math.Max(0.0f, this.drawOnTop ? 0.991f : (float)this.getStandingY() / 10000f));
//Vector2 localPosition = this.getLocalPosition(Game1.viewport);
//b.Draw(Game1.staminaRect, new Microsoft.Xna.Framework.Rectangle((int)localPosition.X + (int)this.yOffset + Game1.pixelZoom * 2, (int)localPosition.Y - 32 * Game1.pixelZoom + this.sprite.SourceRect.Height * Game1.pixelZoom + Game1.tileSize * 3 / 4 + this.yJumpOffset * 2 - (int)this.yOffset, this.sprite.SourceRect.Width * Game1.pixelZoom - (int)this.yOffset * 2 - Game1.pixelZoom * 4, Game1.pixelZoom), new Microsoft.Xna.Framework.Rectangle?(Game1.staminaRect.Bounds), Color.White * 0.75f, 0.0f, Vector2.Zero, SpriteEffects.None, (float)((double)this.getStandingY() / 10000.0 + 1.0 / 1000.0));
} }
else else
{ {
b.Draw(this.Sprite.Texture, this.getLocalPosition(Game1.viewport) + new Vector2((float)(this.sprite.spriteWidth * Game1.pixelZoom / 2), (float)(this.GetBoundingBox().Height / 2)) + (this.shakeTimer > 0 ? new Vector2((float)Game1.random.Next(-1, 2), (float)Game1.random.Next(-1, 2)) : Vector2.Zero), new Microsoft.Xna.Framework.Rectangle?(this.Sprite.SourceRect), Color.White * alpha, this.rotation, new Vector2((float)(this.sprite.spriteWidth / 2), (float)((double)this.sprite.spriteHeight * 3.0 / 4.0)), Math.Max(0.2f, this.scale) * (float)Game1.pixelZoom, this.flip || this.sprite.currentAnimation != null && this.sprite.currentAnimation[this.sprite.currentAnimationIndex].flip ? SpriteEffects.FlipHorizontally : SpriteEffects.None, Math.Max(0.0f, this.drawOnTop ? 0.991f : (float)this.getStandingY() / 10000f)); this.characterRenderer.draw(b,this, this.getLocalPosition(Game1.viewport) + new Vector2((float)(this.sprite.spriteWidth * Game1.pixelZoom / 2), (float)(this.GetBoundingBox().Height / 2)) + (this.shakeTimer > 0 ? new Vector2((float)Game1.random.Next(-1, 2), (float)Game1.random.Next(-1, 2)) : Vector2.Zero), new Microsoft.Xna.Framework.Rectangle?(this.Sprite.SourceRect), Color.White * alpha, this.rotation, new Vector2((float)(this.sprite.spriteWidth / 2), (float)((double)this.sprite.spriteHeight * 3.0 / 4.0)), Math.Max(0.2f, this.scale) * (float)Game1.pixelZoom, this.flip || this.sprite.currentAnimation != null && this.sprite.currentAnimation[this.sprite.currentAnimationIndex].flip ? SpriteEffects.FlipHorizontally : SpriteEffects.None, Math.Max(0.0f, this.drawOnTop ? 0.991f : (float)this.getStandingY() / 10000f));
} }
//If the npc breathes then this code is ran. //If the npc breathes then this code is ran.
if (this.breather && this.shakeTimer <= 0 && (!this.swimming && this.sprite.CurrentFrame < 16) && !this.farmerPassesThrough) if (this.breather && this.shakeTimer <= 0 && (!this.swimming && this.sprite.CurrentFrame < 16) && !this.farmerPassesThrough)
@ -195,7 +204,7 @@ namespace CustomNPCFramework.Framework.NPCS
sourceRect.Height /= 2; sourceRect.Height /= 2;
} }
float num = Math.Max(0.0f, (float)(Math.Ceiling(Math.Sin(Game1.currentGameTime.TotalGameTime.TotalMilliseconds / 600.0 + (double)this.DefaultPosition.X * 20.0)) / 4.0)); float num = Math.Max(0.0f, (float)(Math.Ceiling(Math.Sin(Game1.currentGameTime.TotalGameTime.TotalMilliseconds / 600.0 + (double)this.DefaultPosition.X * 20.0)) / 4.0));
b.Draw(this.Sprite.Texture, this.getLocalPosition(Game1.viewport) + vector2 + (this.shakeTimer > 0 ? new Vector2((float)Game1.random.Next(-1, 2), (float)Game1.random.Next(-1, 2)) : Vector2.Zero), new Microsoft.Xna.Framework.Rectangle?(sourceRect), Color.White * alpha, this.rotation, new Vector2((float)(sourceRect.Width / 2), (float)(sourceRect.Height / 2 + 1)), Math.Max(0.2f, this.scale) * (float)Game1.pixelZoom + num, this.flip ? SpriteEffects.FlipHorizontally : SpriteEffects.None, Math.Max(0.0f, this.drawOnTop ? 0.992f : (float)((double)this.getStandingY() / 10000.0 + 1.0 / 1000.0))); this.characterRenderer.draw(b,this, this.getLocalPosition(Game1.viewport) + vector2 + (this.shakeTimer > 0 ? new Vector2((float)Game1.random.Next(-1, 2), (float)Game1.random.Next(-1, 2)) : Vector2.Zero), new Microsoft.Xna.Framework.Rectangle?(sourceRect), Color.White * alpha, this.rotation, new Vector2((float)(sourceRect.Width / 2), (float)(sourceRect.Height / 2 + 1)), Math.Max(0.2f, this.scale) * (float)Game1.pixelZoom + num, this.flip ? SpriteEffects.FlipHorizontally : SpriteEffects.None, Math.Max(0.0f, this.drawOnTop ? 0.992f : (float)((double)this.getStandingY() / 10000.0 + 1.0 / 1000.0)));
} }
//Checks if the npc is glowing. //Checks if the npc is glowing.