Last active
August 29, 2015 13:59
-
-
Save gw1108/10516618 to your computer and use it in GitHub Desktop.
The main body of the Slice Trail Effect.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private class PositionWidth | |
{ | |
public const int timeToDisappear = 3000; | |
public Vector2 position { get; private set; } | |
public float width { get; private set; } | |
private float elapsedTime; | |
public PositionWidth(Vector2 position, float width) | |
{ | |
this.position = position; | |
this.width = width; | |
elapsedTime = 0f; | |
} | |
public void update(GameTime gameTime) | |
{ | |
elapsedTime += gameTime.ElapsedGameTime.Milliseconds; | |
width = MathHelper.Lerp(width, 0, MathHelper.Clamp(elapsedTime / timeToDisappear, 0, 1)); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void update(GameTime gameTime) | |
{ | |
//Detect if we have released but not yet begun swiping again | |
if (Flame.inputManager.released) | |
{ | |
released = true; | |
} | |
//get the current input | |
if (Flame.inputManager.DRAG) | |
{ | |
SetVerticeColor(); | |
if (released) | |
{ | |
released = false; | |
resetSlicerDeluxue(); | |
} | |
EnqueInput(); | |
} | |
if (positions.Count != 0) | |
{ | |
vertices[0].Position.X = positions.Peek().position.X; | |
vertices[0].Position.Y = positions.Peek().position.Y; | |
prevPos = positions.Peek().position; | |
} | |
int i = 0; | |
//already set vertice 0 so start at 1 | |
int currentV = 1; | |
//the first positionwidth is the least recent position | |
foreach (PositionWidth posWidth in positions) | |
{ | |
if (i != 0) | |
{ | |
//if not at the last one | |
if (i < positions.Count - 1) | |
{ | |
Vector2 offset = SliceMath.normalOneSide(prevPos, posWidth.position); | |
offset.Normalize(); | |
float xOffset = (offset.X * i * posWidth.width); | |
float yOffset = (offset.Y * i * posWidth.width); | |
vertices[currentV].Position = SliceMath.setVector3(vertices[currentV].Position, posWidth.position.X - xOffset, posWidth.position.Y - yOffset); | |
vertices[currentV + 1].Position = SliceMath.setVector3(vertices[currentV + 1].Position, posWidth.position.X + xOffset, posWidth.position.Y + yOffset); | |
currentV += 2; | |
} | |
else | |
{ | |
//set the head | |
Vector2 length = (posWidth.position - prevPos); | |
length.Normalize(); | |
float xOffset = length.X * posWidth.width * headSize; | |
float yOffset = length.Y * posWidth.width * headSize; | |
vertices[currentV].Position = SliceMath.setVector3(vertices[currentV].Position, posWidth.position.X + xOffset, posWidth.position.Y + yOffset); | |
} | |
} | |
prevPos = posWidth.position; | |
++i; | |
posWidth.update(gameTime); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment