Download entity added and tested.
This commit is contained in:
107
Entities/DownloadEntity.cs
Normal file
107
Entities/DownloadEntity.cs
Normal file
@@ -0,0 +1,107 @@
|
||||
using System.Drawing;
|
||||
using SkinnerBox.Utilities.Gameplay;
|
||||
using SlatedGameToolkit.Framework.Graphics.Render;
|
||||
using SlatedGameToolkit.Framework.Graphics.Textures;
|
||||
using SlatedGameToolkit.Framework.Utilities.Collections.Pooling;
|
||||
|
||||
namespace SkinnerBox.Entities
|
||||
{
|
||||
public class DownloadEntity : Entity, IPoolable
|
||||
{
|
||||
private readonly float unitSize = 1/2f;
|
||||
private readonly float unitPerProgressTexture = 0.5f;
|
||||
public float stepSize;
|
||||
public TransitionValue progressValue;
|
||||
public RectangleMesh progressMesh;
|
||||
public TransitionValue timeElapsed;
|
||||
public float health;
|
||||
int size;
|
||||
public int Size {
|
||||
get {
|
||||
return size;
|
||||
}
|
||||
set {
|
||||
this.size = value;
|
||||
mesh.TextureBounds = new RectangleF(0, 0, size, 1f);
|
||||
Width = unitSize * size;
|
||||
}
|
||||
}
|
||||
|
||||
public override RectangleF HitBox {
|
||||
get {
|
||||
RectangleF rect = base.HitBox;
|
||||
rect.Width = Width * size;
|
||||
return rect;
|
||||
}
|
||||
}
|
||||
public DownloadEntity(ITexture promptTex, ITexture progressTex) : base(promptTex)
|
||||
{
|
||||
Size = 1;
|
||||
Height = unitSize;
|
||||
progressMesh = new RectangleMesh(progressTex, Color.White);
|
||||
Reset();
|
||||
}
|
||||
|
||||
private void UpdateProgressMesh() {
|
||||
progressMesh.Width = progressValue.Value;
|
||||
progressMesh.TextureBounds = new RectangleF(0, 0, progressValue.Value * unitPerProgressTexture, 1f);
|
||||
progressMesh.Height = Height;
|
||||
progressMesh.X = X;
|
||||
progressMesh.Y = Y;
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
Size = 1;
|
||||
X = 0;
|
||||
Y = 0;
|
||||
mesh.X = X;
|
||||
mesh.Y = Y;
|
||||
progressValue.HardSet(0);
|
||||
timeElapsed.HardSet(0);
|
||||
stepSize = 0;
|
||||
health = 0;
|
||||
Color = Color.DarkCyan;
|
||||
UpdateProgressMesh();
|
||||
}
|
||||
|
||||
public void Input(float x) {
|
||||
if (x <= progressValue.DesignatedValue + (1f/stepSize) && x > progressValue.DesignatedValue) {
|
||||
progressValue.Value = x;
|
||||
if (progressValue.Value > Width) progressValue.HardSet(Width);
|
||||
}
|
||||
}
|
||||
|
||||
public override void InterpolatePosition(float delta) {
|
||||
progressValue.InterpolatePosition(delta);
|
||||
timeElapsed.InterpolatePosition(delta);
|
||||
float prog = timeElapsed.Value / health;
|
||||
if (prog > 1) prog = 1;
|
||||
if (prog < 0) prog = 0;
|
||||
this.Color = Color.FromArgb((int)(byte.MaxValue * (1f - prog)), Color);
|
||||
UpdateProgressMesh();
|
||||
}
|
||||
}
|
||||
|
||||
public struct DownloadSpawnInfo
|
||||
{
|
||||
public float period;
|
||||
public float elapsedSinceSpawn;
|
||||
public float health;
|
||||
public float stepSize;
|
||||
public int maximumAmount;
|
||||
public int generalSize;
|
||||
public int sizeRange;
|
||||
|
||||
public DownloadSpawnInfo(float cooldown, float health, float stepSize, int maxAmount, int generalSize, int sizeRange)
|
||||
{
|
||||
this.period = cooldown;
|
||||
this.elapsedSinceSpawn = 0;
|
||||
this.health = health;
|
||||
this.stepSize = stepSize;
|
||||
this.maximumAmount = maxAmount;
|
||||
this.sizeRange = sizeRange;
|
||||
this.generalSize = generalSize;
|
||||
}
|
||||
}
|
||||
}
|
@@ -28,6 +28,28 @@ namespace SkinnerBox.Entities
|
||||
public void Update(double delta) {
|
||||
this.Y -= (float)(velocity * delta);
|
||||
}
|
||||
}
|
||||
|
||||
public struct PacketSpawnInfo
|
||||
{
|
||||
public float timeElapsed;
|
||||
public int period;
|
||||
public int perSpawn;
|
||||
public float batchLocation;
|
||||
public float distanceBetween;
|
||||
public float jumpDistance;
|
||||
public float speed;
|
||||
public float lastSpawnLocation;
|
||||
|
||||
public PacketSpawnInfo(int period, int perSpawn, float location, float speed, float distance, float jump) {
|
||||
timeElapsed = 0;
|
||||
lastSpawnLocation = 0;
|
||||
this.period = period;
|
||||
this.perSpawn = perSpawn;
|
||||
this.batchLocation = location;
|
||||
this.distanceBetween = distance;
|
||||
this.speed = speed;
|
||||
this.jumpDistance = jump;
|
||||
}
|
||||
}
|
||||
}
|
@@ -55,4 +55,5 @@ namespace SkinnerBox.Entities
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user