Polished, began adding score, added warning to download.
This commit is contained in:
		@@ -14,7 +14,7 @@ namespace SkinnerBox.Entities
 | 
				
			|||||||
        public TransitionValue progressValue;
 | 
					        public TransitionValue progressValue;
 | 
				
			||||||
        public RectangleMesh progressMesh;
 | 
					        public RectangleMesh progressMesh;
 | 
				
			||||||
        public TransitionValue timeElapsed;
 | 
					        public TransitionValue timeElapsed;
 | 
				
			||||||
        public float health;
 | 
					        public float upTime;
 | 
				
			||||||
        int size;
 | 
					        int size;
 | 
				
			||||||
        public int Size {
 | 
					        public int Size {
 | 
				
			||||||
            get {
 | 
					            get {
 | 
				
			||||||
@@ -30,7 +30,7 @@ namespace SkinnerBox.Entities
 | 
				
			|||||||
        public override RectangleF HitBox {
 | 
					        public override RectangleF HitBox {
 | 
				
			||||||
            get {
 | 
					            get {
 | 
				
			||||||
                RectangleF rect = base.HitBox;
 | 
					                RectangleF rect = base.HitBox;
 | 
				
			||||||
                rect.Width = Width * size;
 | 
					                rect.Width = Width + 0.5f;
 | 
				
			||||||
                return rect;
 | 
					                return rect;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -53,15 +53,11 @@ namespace SkinnerBox.Entities
 | 
				
			|||||||
        public void Reset()
 | 
					        public void Reset()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            Size = 1;
 | 
					            Size = 1;
 | 
				
			||||||
            X = 0;
 | 
					 | 
				
			||||||
            Y = 0;
 | 
					 | 
				
			||||||
            mesh.X = X;
 | 
					 | 
				
			||||||
            mesh.Y = Y;
 | 
					 | 
				
			||||||
            progressValue.HardSet(0);
 | 
					            progressValue.HardSet(0);
 | 
				
			||||||
            timeElapsed.HardSet(0);
 | 
					            timeElapsed.HardSet(0);
 | 
				
			||||||
            stepSize = 0;
 | 
					            stepSize = 0;
 | 
				
			||||||
            health = 0;
 | 
					            upTime = 0;
 | 
				
			||||||
            Color = Color.DarkCyan;
 | 
					            Color = Color.Cyan;
 | 
				
			||||||
            UpdateProgressMesh();
 | 
					            UpdateProgressMesh();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -75,11 +71,13 @@ namespace SkinnerBox.Entities
 | 
				
			|||||||
        public override void InterpolatePosition(float delta) {
 | 
					        public override void InterpolatePosition(float delta) {
 | 
				
			||||||
            progressValue.InterpolatePosition(delta);
 | 
					            progressValue.InterpolatePosition(delta);
 | 
				
			||||||
            timeElapsed.InterpolatePosition(delta);
 | 
					            timeElapsed.InterpolatePosition(delta);
 | 
				
			||||||
            float prog = timeElapsed.Value / health;
 | 
					            float prog = timeElapsed.Value / upTime;
 | 
				
			||||||
            if (prog > 1) prog = 1;
 | 
					            if (prog > 1) prog = 1;
 | 
				
			||||||
            if (prog < 0) prog = 0;
 | 
					            if (prog < 0) prog = 0;
 | 
				
			||||||
            this.Color = Color.FromArgb((int)(byte.MaxValue * (1f - prog)), Color);
 | 
					            this.Color = Color.FromArgb((int)(byte.MaxValue * (1f - prog)), Color);
 | 
				
			||||||
 | 
					            progressMesh.Color = Color.FromArgb((int)(byte.MaxValue * (1f - prog)), progressMesh.Color);
 | 
				
			||||||
            UpdateProgressMesh();
 | 
					            UpdateProgressMesh();
 | 
				
			||||||
 | 
					            base.InterpolatePosition(delta);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -87,7 +85,7 @@ namespace SkinnerBox.Entities
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
        public float period;
 | 
					        public float period;
 | 
				
			||||||
        public float elapsedSinceSpawn;
 | 
					        public float elapsedSinceSpawn;
 | 
				
			||||||
        public float health;
 | 
					        public float upTime;
 | 
				
			||||||
        public float stepSize;
 | 
					        public float stepSize;
 | 
				
			||||||
        public int maximumAmount;
 | 
					        public int maximumAmount;
 | 
				
			||||||
        public int generalSize;
 | 
					        public int generalSize;
 | 
				
			||||||
@@ -97,7 +95,7 @@ namespace SkinnerBox.Entities
 | 
				
			|||||||
        {
 | 
					        {
 | 
				
			||||||
            this.period = cooldown;
 | 
					            this.period = cooldown;
 | 
				
			||||||
            this.elapsedSinceSpawn = 0;
 | 
					            this.elapsedSinceSpawn = 0;
 | 
				
			||||||
            this.health = health;
 | 
					            this.upTime = health;
 | 
				
			||||||
            this.stepSize = stepSize;
 | 
					            this.stepSize = stepSize;
 | 
				
			||||||
            this.maximumAmount = maxAmount;
 | 
					            this.maximumAmount = maxAmount;
 | 
				
			||||||
            this.sizeRange = sizeRange;
 | 
					            this.sizeRange = sizeRange;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,6 +7,8 @@ namespace SkinnerBox.Entities
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    public class ServerEntity : Entity
 | 
					    public class ServerEntity : Entity
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
					        public const float MIN_SPEED = 1f;
 | 
				
			||||||
 | 
					        public const float SPEED_STEP = 1f;
 | 
				
			||||||
        private readonly float length = 4/8f;
 | 
					        private readonly float length = 4/8f;
 | 
				
			||||||
        public float Speed { get; set; }
 | 
					        public float Speed { get; set; }
 | 
				
			||||||
        public override float CenterX {
 | 
					        public override float CenterX {
 | 
				
			||||||
@@ -35,7 +37,7 @@ namespace SkinnerBox.Entities
 | 
				
			|||||||
        public override RectangleF HitBox {
 | 
					        public override RectangleF HitBox {
 | 
				
			||||||
            get {
 | 
					            get {
 | 
				
			||||||
                RectangleF hitbox = base.HitBox;
 | 
					                RectangleF hitbox = base.HitBox;
 | 
				
			||||||
                hitbox.Width = hitbox.Width * size;
 | 
					                hitbox.Width = Width;
 | 
				
			||||||
                return hitbox;
 | 
					                return hitbox;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -46,7 +48,7 @@ namespace SkinnerBox.Entities
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            Size = 1;
 | 
					            Size = 1;
 | 
				
			||||||
            
 | 
					            
 | 
				
			||||||
            this.Speed = 2f;
 | 
					            this.Speed = MIN_SPEED;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            CenterX = initialX;
 | 
					            CenterX = initialX;
 | 
				
			||||||
            mesh.X = X;
 | 
					            mesh.X = X;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -12,8 +12,8 @@ namespace SkinnerBox.Entities
 | 
				
			|||||||
        public TransitionValue aliveTime;
 | 
					        public TransitionValue aliveTime;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public WarningEntity(ITexture texture) : base(texture) {
 | 
					        public WarningEntity(ITexture texture) : base(texture) {
 | 
				
			||||||
            this.Width = 2;
 | 
					            this.Width = 1f;
 | 
				
			||||||
            this.Height = 2;
 | 
					            this.Height = 1f;
 | 
				
			||||||
            Reset();
 | 
					            Reset();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        public void Reset()
 | 
					        public void Reset()
 | 
				
			||||||
@@ -21,7 +21,7 @@ namespace SkinnerBox.Entities
 | 
				
			|||||||
            LifeTime = 0;
 | 
					            LifeTime = 0;
 | 
				
			||||||
            X = 0 - Width;
 | 
					            X = 0 - Width;
 | 
				
			||||||
            mesh.X = X;
 | 
					            mesh.X = X;
 | 
				
			||||||
            Y = Game.HEIGHT_UNITS - Height;
 | 
					            Y = - Height;
 | 
				
			||||||
            mesh.Y = Y;
 | 
					            mesh.Y = Y;
 | 
				
			||||||
            aliveTime.HardSet(0);
 | 
					            aliveTime.HardSet(0);
 | 
				
			||||||
            this.Color = Color.Red;
 | 
					            this.Color = Color.Red;
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										3
									
								
								Game.cs
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								Game.cs
									
									
									
									
									
								
							@@ -1,5 +1,7 @@
 | 
				
			|||||||
using SkinnerBox.States.Main;
 | 
					using SkinnerBox.States.Main;
 | 
				
			||||||
 | 
					using SkinnerBox.Utilities;
 | 
				
			||||||
using SlatedGameToolkit.Framework;
 | 
					using SlatedGameToolkit.Framework;
 | 
				
			||||||
 | 
					using SlatedGameToolkit.Framework.Logging;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace SkinnerBox
 | 
					namespace SkinnerBox
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@@ -11,6 +13,7 @@ namespace SkinnerBox
 | 
				
			|||||||
        {
 | 
					        {
 | 
				
			||||||
            GameEngine.targetFPS = 0;
 | 
					            GameEngine.targetFPS = 0;
 | 
				
			||||||
            GameEngine.UpdatesPerSecond = 20;
 | 
					            GameEngine.UpdatesPerSecond = 20;
 | 
				
			||||||
 | 
					            Logger.AddLogListener(new ConsoleLogger());
 | 
				
			||||||
            GameEngine.Ignite(new MenuState());
 | 
					            GameEngine.Ignite(new MenuState());
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -13,6 +13,7 @@ using SlatedGameToolkit.Framework.StateSystem;
 | 
				
			|||||||
using SlatedGameToolkit.Framework.StateSystem.States;
 | 
					using SlatedGameToolkit.Framework.StateSystem.States;
 | 
				
			||||||
using SlatedGameToolkit.Framework.Utilities.Collections.Pooling;
 | 
					using SlatedGameToolkit.Framework.Utilities.Collections.Pooling;
 | 
				
			||||||
using SlatedGameToolkit.Framework.Utilities;
 | 
					using SlatedGameToolkit.Framework.Utilities;
 | 
				
			||||||
 | 
					using SlatedGameToolkit.Framework.Graphics.Text;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace SkinnerBox.States.Gameplay
 | 
					namespace SkinnerBox.States.Gameplay
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@@ -21,37 +22,52 @@ namespace SkinnerBox.States.Gameplay
 | 
				
			|||||||
        private MeshBatchRenderer renderer;
 | 
					        private MeshBatchRenderer renderer;
 | 
				
			||||||
        private AssetManager assets;
 | 
					        private AssetManager assets;
 | 
				
			||||||
        private StateManager stateManager;
 | 
					        private StateManager stateManager;
 | 
				
			||||||
 | 
					        private BitmapFont font;
 | 
				
			||||||
        private Random random;
 | 
					        private Random random;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        //Cursor information
 | 
					        #region CursorVars
 | 
				
			||||||
        private float widthFactor, heightFactor;
 | 
					        private float cursorWidthScale, cursorHeightScale;
 | 
				
			||||||
        private float serverTargetPos; //Last left click position
 | 
					        private float serverTargetPos; //Last left click position
 | 
				
			||||||
 | 
					        private int viewHeight; // The viewports height for inverting Y value.
 | 
				
			||||||
 | 
					        #endregion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        //Entities
 | 
					        #region EntitiesVariables
 | 
				
			||||||
        private ServerEntity server;
 | 
					        private ServerEntity server; //The player
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Warning entities
 | 
				
			||||||
        private ObjectPool<WarningEntity> warningPool;
 | 
					        private ObjectPool<WarningEntity> warningPool;
 | 
				
			||||||
        private List<WarningEntity> activeWarnings = new List<WarningEntity>();
 | 
					        private List<WarningEntity> activeWarnings = new List<WarningEntity>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Packet entities
 | 
				
			||||||
        private ObjectPool<PacketEntity> packetPool;
 | 
					        private ObjectPool<PacketEntity> packetPool;
 | 
				
			||||||
        private List<PacketEntity> activePackets = new List<PacketEntity>();
 | 
					        private List<PacketEntity> activePackets = new List<PacketEntity>();
 | 
				
			||||||
        private PacketSpawnInfo packetSpawnInfo;
 | 
					        private PacketSpawnInfo packetSpawnInfo;
 | 
				
			||||||
        private const float packetSafeMargin = 1/2f;
 | 
					        private const float packetSafeMargin = 1/2f;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        //Download entities.
 | 
				
			||||||
        private ObjectPool<DownloadEntity> downloadPool;
 | 
					        private ObjectPool<DownloadEntity> downloadPool;
 | 
				
			||||||
        private List<DownloadEntity> activeDownloads = new List<DownloadEntity>();
 | 
					        private List<DownloadEntity> activeDownloads = new List<DownloadEntity>();
 | 
				
			||||||
        private DownloadSpawnInfo downloadSpawnInfo;
 | 
					        private DownloadSpawnInfo downloadSpawnInfo;
 | 
				
			||||||
        private const float downloadSafeMargin = 1.5f;
 | 
					        private const float downloadSafeMargin = 1.5f;
 | 
				
			||||||
        private int viewHeight;
 | 
					        #endregion
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
 | 
					        #region PlayerStats
 | 
				
			||||||
 | 
					        private readonly int totalUsage = 3;
 | 
				
			||||||
 | 
					        private int usedUsage = 0;
 | 
				
			||||||
 | 
					        private RectangleMesh usageMesh;
 | 
				
			||||||
 | 
					        private int score;
 | 
				
			||||||
 | 
					        private float timeElapsed;
 | 
				
			||||||
 | 
					        #endregion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public GamePlayState(MeshBatchRenderer renderer, AssetManager asset)
 | 
					        public GamePlayState(MeshBatchRenderer renderer, AssetManager asset, BitmapFont font)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            this.assets = asset;
 | 
					            this.assets = asset;
 | 
				
			||||||
            this.renderer = renderer;
 | 
					            this.renderer = renderer;
 | 
				
			||||||
            packetPool = new ObjectPool<PacketEntity>(CreatePacket);
 | 
					            packetPool = new ObjectPool<PacketEntity>(CreatePacket);
 | 
				
			||||||
            warningPool = new ObjectPool<WarningEntity>(createWarning);
 | 
					            warningPool = new ObjectPool<WarningEntity>(createWarning);
 | 
				
			||||||
            downloadPool = new ObjectPool<DownloadEntity>(createDownload);
 | 
					            downloadPool = new ObjectPool<DownloadEntity>(createDownload);
 | 
				
			||||||
 | 
					            this.font = font;
 | 
				
			||||||
 | 
					            font.PrepareCharacterGroup("score:0123456789timlapsd".ToCharArray());
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public bool Activate()
 | 
					        public bool Activate()
 | 
				
			||||||
@@ -60,6 +76,7 @@ namespace SkinnerBox.States.Gameplay
 | 
				
			|||||||
            Mouse.mouseUpdateEvent += MouseInput;
 | 
					            Mouse.mouseUpdateEvent += MouseInput;
 | 
				
			||||||
            serverTargetPos = 0.5f * Game.WIDTH_UNITS;
 | 
					            serverTargetPos = 0.5f * Game.WIDTH_UNITS;
 | 
				
			||||||
            server = new ServerEntity((Texture)assets["serverunit.png"], serverTargetPos, 0.1f);
 | 
					            server = new ServerEntity((Texture)assets["serverunit.png"], serverTargetPos, 0.1f);
 | 
				
			||||||
 | 
					            usageMesh = new RectangleMesh(new RectangleF(0, Game.HEIGHT_UNITS - 0.75f, 0.5f, 0.5f), (ITexture)assets["usage.png"], Color.White);
 | 
				
			||||||
            random = new Random();
 | 
					            random = new Random();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            packetSpawnInfo = new PacketSpawnInfo(2, 1, (float)(random.NextDouble() * Game.WIDTH_UNITS), 1f, 0.2f, 3f);
 | 
					            packetSpawnInfo = new PacketSpawnInfo(2, 1, (float)(random.NextDouble() * Game.WIDTH_UNITS), 1f, 0.2f, 3f);
 | 
				
			||||||
@@ -102,25 +119,45 @@ namespace SkinnerBox.States.Gameplay
 | 
				
			|||||||
            int vw, vh, vx, vy;
 | 
					            int vw, vh, vx, vy;
 | 
				
			||||||
            WindowContextsManager.CurrentGL.GetViewport(out vx, out vy, out vw, out vh);
 | 
					            WindowContextsManager.CurrentGL.GetViewport(out vx, out vy, out vw, out vh);
 | 
				
			||||||
            CalculateScaleFactors(vw, vh);
 | 
					            CalculateScaleFactors(vw, vh);
 | 
				
			||||||
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public void Render(double delta)
 | 
					        public void Render(double delta)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            renderer.Begin(Matrix4x4.Identity, delta);
 | 
					            renderer.Begin(Matrix4x4.Identity, delta);
 | 
				
			||||||
 | 
					            #region WarningRender
 | 
				
			||||||
            foreach (WarningEntity warn in activeWarnings)
 | 
					            foreach (WarningEntity warn in activeWarnings)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                renderer.Draw(warn);
 | 
					                renderer.Draw(warn);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					            #endregion
 | 
				
			||||||
 | 
					            #region PacketRender
 | 
				
			||||||
            foreach (PacketEntity packet in activePackets)
 | 
					            foreach (PacketEntity packet in activePackets)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                renderer.Draw(packet);
 | 
					                renderer.Draw(packet);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					            #endregion
 | 
				
			||||||
 | 
					            #region DownloadRender
 | 
				
			||||||
            foreach(DownloadEntity download in activeDownloads) {
 | 
					            foreach(DownloadEntity download in activeDownloads) {
 | 
				
			||||||
                renderer.Draw(download);
 | 
					                renderer.Draw(download);
 | 
				
			||||||
                renderer.Draw(download.progressMesh);
 | 
					                renderer.Draw(download.progressMesh);
 | 
				
			||||||
            }                
 | 
					            }                
 | 
				
			||||||
 | 
					            #endregion
 | 
				
			||||||
            renderer.Draw(server);
 | 
					            renderer.Draw(server);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            #region StatusRender
 | 
				
			||||||
 | 
					                for (int i = 0; i < totalUsage; i++)
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    usageMesh.X = 0.25f + (i * (usageMesh.Width + 0.2f));
 | 
				
			||||||
 | 
					                    if (i >= usedUsage) {
 | 
				
			||||||
 | 
					                        usageMesh.Color = Color.Yellow;
 | 
				
			||||||
 | 
					                    } else {
 | 
				
			||||||
 | 
					                        usageMesh.Color = Color.White;
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                    renderer.Draw(usageMesh);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                font.WriteLine(renderer, 0.05f, Game.HEIGHT_UNITS - 2f, "score: " + score, Color.Black);
 | 
				
			||||||
 | 
					            #endregion
 | 
				
			||||||
            renderer.End();
 | 
					            renderer.End();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -128,7 +165,7 @@ namespace SkinnerBox.States.Gameplay
 | 
				
			|||||||
        {
 | 
					        {
 | 
				
			||||||
            #region ServerUpdate
 | 
					            #region ServerUpdate
 | 
				
			||||||
            if (Mouse.LeftButtonPressed) {
 | 
					            if (Mouse.LeftButtonPressed) {
 | 
				
			||||||
                serverTargetPos = widthFactor * Mouse.X;
 | 
					                serverTargetPos = cursorWidthScale * Mouse.X;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            
 | 
					            
 | 
				
			||||||
            if (serverTargetPos < server.CenterX)
 | 
					            if (serverTargetPos < server.CenterX)
 | 
				
			||||||
@@ -174,7 +211,7 @@ namespace SkinnerBox.States.Gameplay
 | 
				
			|||||||
                PacketEntity packet = activePackets[i];
 | 
					                PacketEntity packet = activePackets[i];
 | 
				
			||||||
                packet.Update(timeStep);
 | 
					                packet.Update(timeStep);
 | 
				
			||||||
                if (packet.HitBox.IntersectsWith(server.HitBox) && packet.velocity > 0) {
 | 
					                if (packet.HitBox.IntersectsWith(server.HitBox) && packet.velocity > 0) {
 | 
				
			||||||
                    packet.velocity *= -2f;
 | 
					                    packet.velocity *= -2.5f;
 | 
				
			||||||
                    packet.Color = Color.Cyan;
 | 
					                    packet.Color = Color.Cyan;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                if (packet.Y <= 0 - packet.Height) {
 | 
					                if (packet.Y <= 0 - packet.Height) {
 | 
				
			||||||
@@ -199,11 +236,16 @@ namespace SkinnerBox.States.Gameplay
 | 
				
			|||||||
                    download.Size = (int)(downloadSpawnInfo.generalSize + ((random.NextDouble() - 1/2f) * 2f * downloadSpawnInfo.sizeRange));
 | 
					                    download.Size = (int)(downloadSpawnInfo.generalSize + ((random.NextDouble() - 1/2f) * 2f * downloadSpawnInfo.sizeRange));
 | 
				
			||||||
                    download.X = (float)(random.NextDouble() * (Game.WIDTH_UNITS - download.Width));
 | 
					                    download.X = (float)(random.NextDouble() * (Game.WIDTH_UNITS - download.Width));
 | 
				
			||||||
                    download.Y = (float)(downloadSafeMargin + random.NextDouble() * (Game.HEIGHT_UNITS - 2 * downloadSafeMargin));
 | 
					                    download.Y = (float)(downloadSafeMargin + random.NextDouble() * (Game.HEIGHT_UNITS - 2 * downloadSafeMargin));
 | 
				
			||||||
                    download.mesh.X = download.X;
 | 
					 | 
				
			||||||
                    download.mesh.Y = download.Y;
 | 
					 | 
				
			||||||
                    download.stepSize = downloadSpawnInfo.stepSize;
 | 
					                    download.stepSize = downloadSpawnInfo.stepSize;
 | 
				
			||||||
                    download.health = downloadSpawnInfo.health;
 | 
					                    download.upTime = downloadSpawnInfo.upTime;
 | 
				
			||||||
                    activeDownloads.Add(download);
 | 
					                    activeDownloads.Add(download);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    WarningEntity warning = warningPool.Retrieve();
 | 
				
			||||||
 | 
					                    warning.CenterX = download.CenterX;
 | 
				
			||||||
 | 
					                    warning.LifeTime = download.upTime * (1/3f);
 | 
				
			||||||
 | 
					                    warning.Y = download.Y - warning.Height;
 | 
				
			||||||
 | 
					                    warning.mesh.Y = warning.Y;
 | 
				
			||||||
 | 
					                    activeWarnings.Add(warning);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -215,8 +257,8 @@ namespace SkinnerBox.States.Gameplay
 | 
				
			|||||||
                download.timeElapsed.Value += (float)timeStep;
 | 
					                download.timeElapsed.Value += (float)timeStep;
 | 
				
			||||||
                if (Mouse.RightButtonPressed) {
 | 
					                if (Mouse.RightButtonPressed) {
 | 
				
			||||||
                    Vector2 rightMousePos;
 | 
					                    Vector2 rightMousePos;
 | 
				
			||||||
                    rightMousePos.X = widthFactor * Mouse.X;
 | 
					                    rightMousePos.X = cursorWidthScale * Mouse.X;
 | 
				
			||||||
                    rightMousePos.Y = heightFactor * (viewHeight - Mouse.Y);
 | 
					                    rightMousePos.Y = cursorHeightScale * (viewHeight - Mouse.Y);
 | 
				
			||||||
                    if (download.HitBox.Contains(rightMousePos)) {
 | 
					                    if (download.HitBox.Contains(rightMousePos)) {
 | 
				
			||||||
                        download.Input(rightMousePos.X - download.X);
 | 
					                        download.Input(rightMousePos.X - download.X);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
@@ -227,15 +269,13 @@ namespace SkinnerBox.States.Gameplay
 | 
				
			|||||||
                    downloadPool.Release(download);
 | 
					                    downloadPool.Release(download);
 | 
				
			||||||
                    activeDownloads.RemoveAt(i);
 | 
					                    activeDownloads.RemoveAt(i);
 | 
				
			||||||
                    i--;
 | 
					                    i--;
 | 
				
			||||||
                    Console.WriteLine("YAY");
 | 
					 | 
				
			||||||
                    continue;
 | 
					                    continue;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                if (download.timeElapsed.Value >= download.health)
 | 
					                if (download.timeElapsed.Value >= download.upTime)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    downloadPool.Release(download);
 | 
					                    downloadPool.Release(download);
 | 
				
			||||||
                    activeDownloads.RemoveAt(i);
 | 
					                    activeDownloads.RemoveAt(i);
 | 
				
			||||||
                    i--;
 | 
					                    i--;
 | 
				
			||||||
                    Console.WriteLine("AW");
 | 
					 | 
				
			||||||
                    continue;
 | 
					                    continue;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
@@ -255,6 +295,31 @@ namespace SkinnerBox.States.Gameplay
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public void KeyInputListener(SDL.SDL_Keycode keycode, bool down) {
 | 
					        public void KeyInputListener(SDL.SDL_Keycode keycode, bool down) {
 | 
				
			||||||
 | 
					            if (!down) return;
 | 
				
			||||||
 | 
					            if (keycode == SDL.SDL_Keycode.SDLK_a) {
 | 
				
			||||||
 | 
					                if (usedUsage > 0 && server.Size > 1) {
 | 
				
			||||||
 | 
					                    usedUsage--;
 | 
				
			||||||
 | 
					                    server.Size--;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            if (keycode == SDL.SDL_Keycode.SDLK_d) {
 | 
				
			||||||
 | 
					                if (usedUsage < totalUsage) {
 | 
				
			||||||
 | 
					                    usedUsage++;
 | 
				
			||||||
 | 
					                    server.Size++;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            if (keycode == SDL.SDL_Keycode.SDLK_s) {
 | 
				
			||||||
 | 
					                if (usedUsage > 0 && server.Speed > ServerEntity.MIN_SPEED) {
 | 
				
			||||||
 | 
					                    usedUsage--;
 | 
				
			||||||
 | 
					                    server.Speed -= ServerEntity.SPEED_STEP;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            if (keycode == SDL.SDL_Keycode.SDLK_w) {
 | 
				
			||||||
 | 
					                if (usedUsage < totalUsage) {
 | 
				
			||||||
 | 
					                    usedUsage++;
 | 
				
			||||||
 | 
					                    server.Speed += ServerEntity.SPEED_STEP;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public void MouseInput(bool leftDown, bool rightDown, bool middle, int x, int y, int scrollX, int scrollY) {
 | 
					        public void MouseInput(bool leftDown, bool rightDown, bool middle, int x, int y, int scrollX, int scrollY) {
 | 
				
			||||||
@@ -270,8 +335,8 @@ namespace SkinnerBox.States.Gameplay
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        private void CalculateScaleFactors(int width, int height) {
 | 
					        private void CalculateScaleFactors(int width, int height) {
 | 
				
			||||||
            viewHeight = height;
 | 
					            viewHeight = height;
 | 
				
			||||||
            this.widthFactor = Game.WIDTH_UNITS * (1f / width);
 | 
					            this.cursorWidthScale = Game.WIDTH_UNITS * (1f / width);
 | 
				
			||||||
            this.heightFactor = Game.HEIGHT_UNITS * (1f / height);
 | 
					            this.cursorHeightScale = Game.HEIGHT_UNITS * (1f / height);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -53,7 +53,7 @@ namespace SkinnerBox.States.Main
 | 
				
			|||||||
        {
 | 
					        {
 | 
				
			||||||
            this.manager = manager;
 | 
					            this.manager = manager;
 | 
				
			||||||
            this.manager.backgroundColour = Color.White;
 | 
					            this.manager.backgroundColour = Color.White;
 | 
				
			||||||
            this.context = new WindowContext("You Are the Website", width: 640, height: 640, options: SDL.SDL_WindowFlags.SDL_WINDOW_HIDDEN); // Creates the window context.
 | 
					            this.context = new WindowContext("You Are the Website", width: 640, height: 640, options: SDL.SDL_WindowFlags.SDL_WINDOW_HIDDEN);
 | 
				
			||||||
            this.assets = new AssetManager();
 | 
					            this.assets = new AssetManager();
 | 
				
			||||||
            this.assets.DefaultPathModifier = (p) => "resources/" + p;
 | 
					            this.assets.DefaultPathModifier = (p) => "resources/" + p;
 | 
				
			||||||
            this.assets.Loaders.TryAdd("png", TextureLoader.Load2DTexture);
 | 
					            this.assets.Loaders.TryAdd("png", TextureLoader.Load2DTexture);
 | 
				
			||||||
@@ -63,14 +63,19 @@ namespace SkinnerBox.States.Main
 | 
				
			|||||||
            this.renderer = new MeshBatchRenderer(camera);
 | 
					            this.renderer = new MeshBatchRenderer(camera);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            //Add additional states
 | 
					            //Add additional states
 | 
				
			||||||
            manager.AddState(new GamePlayState(renderer, this.assets));
 | 
					            BitmapFont genericFont = new BitmapFont("resources/BigShouldersDisplay-Light.ttf");
 | 
				
			||||||
 | 
					            genericFont.PixelsPerUnitHeight = 80;
 | 
				
			||||||
 | 
					            genericFont.PixelsPerUnitWidth = 80;
 | 
				
			||||||
 | 
					            genericFont.PixelHeight = 32;
 | 
				
			||||||
 | 
					            manager.AddState(new GamePlayState(renderer, this.assets, genericFont));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            //Load assets
 | 
					            //Load assets
 | 
				
			||||||
            this.assets.Load("serverunit.png");
 | 
					            assets.Load("serverunit.png");
 | 
				
			||||||
            this.assets.Load("packet.png");
 | 
					            assets.Load("packet.png");
 | 
				
			||||||
            this.assets.Load("warning.png");
 | 
					            assets.Load("warning.png");
 | 
				
			||||||
            this.assets.Load("downloadbar.png");
 | 
					            assets.Load("downloadbar.png");
 | 
				
			||||||
            this.assets.Load("drag.png");
 | 
					            assets.Load("drag.png");
 | 
				
			||||||
 | 
					            assets.Load("usage.png");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            //Set up title TTF
 | 
					            //Set up title TTF
 | 
				
			||||||
            this.titleFont = new BitmapFont("resources/BigShouldersDisplay-Regular.ttf", textureSizes: 512);
 | 
					            this.titleFont = new BitmapFont("resources/BigShouldersDisplay-Regular.ttf", textureSizes: 512);
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										15
									
								
								Utilities/ConsoleLogger.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								Utilities/ConsoleLogger.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,15 @@
 | 
				
			|||||||
 | 
					using System;
 | 
				
			||||||
 | 
					using SlatedGameToolkit.Framework.Logging;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace SkinnerBox.Utilities
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    public class ConsoleLogger : ILogListener
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        public LogLevel Level => LogLevel.DEBUG;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public void LogMessage(string message, DateTime time, LogLevel level)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            Console.WriteLine(string.Format("[{0}] [{1}]: {2}", time.ToString("H:mm:ss"), level, message));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										
											BIN
										
									
								
								resources/BigShouldersDisplay-Light.ttf
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								resources/BigShouldersDisplay-Light.ttf
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 Before Width: | Height: | Size: 644 B After Width: | Height: | Size: 917 B  | 
							
								
								
									
										
											BIN
										
									
								
								resources/usage.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								resources/usage.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 1.6 KiB  | 
		Reference in New Issue
	
	Block a user