Base concept implemented.
Paddle and balls have been added.
This commit is contained in:
76
Entities/Entity.cs
Normal file
76
Entities/Entity.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using System.Drawing;
|
||||
using System.Numerics;
|
||||
using SlatedGameToolkit.Framework.Graphics.Render;
|
||||
using SlatedGameToolkit.Framework.Graphics.Textures;
|
||||
|
||||
namespace SkinnerBox.Entities
|
||||
{
|
||||
public abstract class Entity : IMesh, IPositionInterpolable
|
||||
{
|
||||
public RectangleMesh mesh;
|
||||
public virtual float CenterX {
|
||||
get {
|
||||
return X + Width / 2f;
|
||||
}
|
||||
set {
|
||||
X = value - Width / 2f;
|
||||
}
|
||||
}
|
||||
public float X { get; set; }
|
||||
|
||||
public float Y { get; set; }
|
||||
|
||||
public float Width {
|
||||
get {
|
||||
return mesh.Width;
|
||||
}
|
||||
|
||||
set {
|
||||
mesh.Width = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float Height {
|
||||
get {
|
||||
return mesh.Height;
|
||||
}
|
||||
|
||||
set {
|
||||
mesh.Height = value;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual RectangleF HitBox
|
||||
{
|
||||
get {
|
||||
return mesh.Bounds;
|
||||
}
|
||||
}
|
||||
|
||||
public Entity(ITexture texture)
|
||||
{
|
||||
this.mesh = new RectangleMesh(texture, Color.White);
|
||||
}
|
||||
|
||||
public (Vector3, Vector2)[] Vertices => mesh.Vertices;
|
||||
|
||||
public uint[] Elements => mesh.Elements;
|
||||
|
||||
public ITexture Texture => mesh.Texture;
|
||||
|
||||
public Color Color {
|
||||
get {
|
||||
return this.mesh.Color;
|
||||
}
|
||||
set {
|
||||
this.mesh.Color = value;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void InterpolatePosition(float delta)
|
||||
{
|
||||
mesh.X += delta * (X - mesh.X);
|
||||
mesh.Y += delta * (Y - mesh.Y);
|
||||
}
|
||||
}
|
||||
}
|
33
Entities/PacketEntity.cs
Normal file
33
Entities/PacketEntity.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using SlatedGameToolkit.Framework.Graphics.Render;
|
||||
using SlatedGameToolkit.Framework.Graphics.Textures;
|
||||
using SlatedGameToolkit.Framework.Utilities.Collections.Pooling;
|
||||
|
||||
namespace SkinnerBox.Entities
|
||||
{
|
||||
public class PacketEntity : Entity, IPositionInterpolable, IPoolable
|
||||
{
|
||||
public float velocity;
|
||||
public PacketEntity(ITexture texture) : base(texture)
|
||||
{
|
||||
this.Width = 0.5f;
|
||||
this.Height = 1f;
|
||||
Reset();
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
this.Y = Game.HEIGHT_UNITS;
|
||||
this.mesh.Y = this.Y;
|
||||
this.velocity = 0;
|
||||
this.X = 0;
|
||||
this.mesh.X = this.X;
|
||||
}
|
||||
|
||||
public void Update(double delta) {
|
||||
this.Y -= (float)(velocity * delta);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
58
Entities/ServerEntity.cs
Normal file
58
Entities/ServerEntity.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using System.Drawing;
|
||||
using SlatedGameToolkit.Framework.Graphics.Render;
|
||||
using SlatedGameToolkit.Framework.Graphics.Textures;
|
||||
using SlatedGameToolkit.Framework.Graphics.Window;
|
||||
|
||||
namespace SkinnerBox.Entities
|
||||
{
|
||||
public class ServerEntity : Entity
|
||||
{
|
||||
private readonly float length = 4/8f;
|
||||
public float Speed { get; set; }
|
||||
public override float CenterX {
|
||||
get {
|
||||
return base.X + (length * size) / 2f;
|
||||
}
|
||||
|
||||
set {
|
||||
base.X = value - (length * size) / 2f;
|
||||
}
|
||||
}
|
||||
private int size;
|
||||
public int Size {
|
||||
get {
|
||||
return size;
|
||||
}
|
||||
|
||||
set {
|
||||
if (this.size != value) {
|
||||
this.size = value;
|
||||
this.mesh.TextureBounds = new RectangleF(0, 0, size, 1);
|
||||
this.Width = value * length;
|
||||
}
|
||||
}
|
||||
}
|
||||
public override RectangleF HitBox {
|
||||
get {
|
||||
RectangleF hitbox = base.HitBox;
|
||||
hitbox.Width = hitbox.Width * size;
|
||||
return hitbox;
|
||||
}
|
||||
}
|
||||
public ServerEntity(Texture texture, float initialX, float Y) : base(texture)
|
||||
{
|
||||
this.X = (Game.WIDTH_UNITS - this.Width) / 2f;
|
||||
this.Height = length;
|
||||
|
||||
Size = 1;
|
||||
|
||||
this.Speed = 2f;
|
||||
|
||||
CenterX = initialX;
|
||||
mesh.X = X;
|
||||
this.Y = Y;
|
||||
mesh.Y = this.Y;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
38
Entities/WarningEntity.cs
Normal file
38
Entities/WarningEntity.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using SkinnerBox.Utilities.Gameplay;
|
||||
using SlatedGameToolkit.Framework.Graphics.Textures;
|
||||
using SlatedGameToolkit.Framework.Utilities.Collections.Pooling;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
|
||||
namespace SkinnerBox.Entities
|
||||
{
|
||||
public class WarningEntity : Entity, IPoolable
|
||||
{
|
||||
public float LifeTime { get; set; }
|
||||
public TransitionValue aliveTime;
|
||||
|
||||
public WarningEntity(ITexture texture) : base(texture) {
|
||||
this.Width = 2;
|
||||
this.Height = 2;
|
||||
Reset();
|
||||
}
|
||||
public void Reset()
|
||||
{
|
||||
LifeTime = 0;
|
||||
X = 0 - Width;
|
||||
mesh.X = X;
|
||||
Y = Game.HEIGHT_UNITS - Height;
|
||||
mesh.Y = Y;
|
||||
aliveTime.HardSet(0);
|
||||
this.Color = Color.Red;
|
||||
}
|
||||
|
||||
public override void InterpolatePosition(float delta) {
|
||||
aliveTime.InterpolatePosition(delta);
|
||||
float prog = (aliveTime.Value / LifeTime);
|
||||
if (prog > 1) prog = 1;
|
||||
this.Color = Color.FromArgb((int)(byte.MaxValue * (1f - prog)), this.Color);
|
||||
base.InterpolatePosition(delta);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user