diff --git a/Objects/CameraFrameObject.cs b/Objects/CameraFrameObject.cs new file mode 100644 index 0000000..557ac36 --- /dev/null +++ b/Objects/CameraFrameObject.cs @@ -0,0 +1,33 @@ +using Microsoft.Xna.Framework; +using System; +using System.Collections.Generic; +using System.Text; + +namespace DotRPG.Objects +{ + public class CameraFrameObject + { + public Point Focus; + public Point TrackTarget; + public Single CameraVelocity; + + public Point GetTopLeftAngle(Point screenSize) + { + return new Point(Focus.X - screenSize.X/2, Focus.Y - screenSize.Y/2); + } + public void Update(GameTime gameTime) + { + Vector2 cameraMovement = (Focus - TrackTarget).ToVector2(); + Vector2 cameraMovementDirection = cameraMovement / cameraMovement.Length(); + Vector2 cameraMovementNew = cameraMovementDirection * CameraVelocity * (Single)gameTime.ElapsedGameTime.TotalSeconds; + if (cameraMovementNew.Length() <= cameraMovement.Length()) + { + Focus -= cameraMovementNew.ToPoint(); + } + else + { + Focus -= cameraMovement.ToPoint(); + } + } + } +} diff --git a/Objects/Dynamics/DynamicRectObject.cs b/Objects/Dynamics/DynamicRectObject.cs index 4bd370d..85b4fed 100644 --- a/Objects/Dynamics/DynamicRectObject.cs +++ b/Objects/Dynamics/DynamicRectObject.cs @@ -167,15 +167,15 @@ public void CollideWith(DynamicRectObject another, Boolean hitVertically, Boolea } } - public void Draw(SpriteBatch _sb, GameTime gameTime, Int32 VirtualVSize, Point scrollOffset, Point scrollSize) + public void Draw(SpriteBatch _sb, GameTime gameTime, Int32 VirtualVSize, Point scrollOffset, Point scrollSize, Single ZIndex = 0.0f) { Single sizeMorph = 1.0f * scrollSize.Y / VirtualVSize; Vector2 location = new Vector2 ( - Location.X * sizeMorph - (BodySize.X * sizeMorph / 2) - scrollOffset.X * sizeMorph, - Location.Y * sizeMorph - (BodySize.Y * sizeMorph / 2) - scrollOffset.Y * sizeMorph + Location.X * sizeMorph - (Sprite.SpriteSize.X * sizeMorph / 2) - scrollOffset.X, + Location.Y * sizeMorph + (BodySize.Y * sizeMorph / 2) - (Sprite.SpriteSize.Y * sizeMorph) - scrollOffset.Y ); - Sprite.Draw(_sb, location, gameTime, sizeMorph); + Sprite.Draw(_sb, location, gameTime, sizeMorph, ZIndex); } public Boolean TryCollideWith(DynamicRectObject another, Boolean splitVector = false) @@ -197,8 +197,8 @@ public Boolean TryCollideWith(DynamicRectObject another, Boolean splitVector = f public virtual void Update(GameTime gameTime) { - Velocity += AppliedForce / ((Single)gameTime.ElapsedGameTime.TotalSeconds * this.Mass); - Location += Velocity / (Single)gameTime.ElapsedGameTime.TotalSeconds; + Velocity += AppliedForce * ((Single)gameTime.ElapsedGameTime.TotalSeconds * this.Mass); + Location += Velocity * (Single)gameTime.ElapsedGameTime.TotalSeconds; AppliedForce = Vector2.Zero; } diff --git a/Objects/SpriteController.cs b/Objects/SpriteController.cs index 4ad63b1..92a7b5b 100644 --- a/Objects/SpriteController.cs +++ b/Objects/SpriteController.cs @@ -55,7 +55,15 @@ public void AddAnimationSequence(String sequenceName, Texture2D frames, UInt16 f LoopTo.Add(sequenceName, loopTo); } - public void Draw(SpriteBatch _sb, Vector2 drawLocation, GameTime gameTime, Single drawSize = 1.0f) + public Point SpriteSize + { + get + { + return new Point(AnimationSequenceCollection[CurrentAnimationSequence].Width / FrameAmount[CurrentAnimationSequence], AnimationSequenceCollection[CurrentAnimationSequence].Height); + } + } + + public void Draw(SpriteBatch _sb, Vector2 drawLocation, GameTime gameTime, Single drawSize = 1.0f, Single ZIndex = 0.0f) { Single addFrames = 0.0f; if (PlaybackSpeed > 0.0f) @@ -66,13 +74,13 @@ public void Draw(SpriteBatch _sb, Vector2 drawLocation, GameTime gameTime, Singl ScrollTimer -= (FrameTime / PlaybackSpeed) * (addFrames / PlaybackSpeed); } Single newPos = _i + addFrames; - while (newPos > FrameAmount[CurrentAnimationSequence]) + if (newPos >= FrameAmount[CurrentAnimationSequence]) { - newPos = (ushort)(newPos % FrameAmount[CurrentAnimationSequence] + LoopTo[CurrentAnimationSequence]); + newPos = LoopTo[CurrentAnimationSequence]; } Texture2D toDraw = AnimationSequenceCollection[CurrentAnimationSequence]; Single widthPerFrame = toDraw.Width / FrameAmount[CurrentAnimationSequence]; - UInt16 newPosI = (ushort)Math.Round(newPos); + UInt16 newPosI = (ushort)Math.Floor(newPos); Rectangle lololol = new Rectangle ( (int)(newPosI * widthPerFrame), @@ -90,7 +98,7 @@ public void Draw(SpriteBatch _sb, Vector2 drawLocation, GameTime gameTime, Singl Vector2.Zero, drawSize, SpriteEffects.None, - 0 + ZIndex ); _i = newPos; } diff --git a/_Example/DynamicsTestFrame.cs b/_Example/DynamicsTestFrame.cs index 9773fc3..a05f260 100644 --- a/_Example/DynamicsTestFrame.cs +++ b/_Example/DynamicsTestFrame.cs @@ -74,11 +74,11 @@ public override void Update(GameTime gameTime, bool[] controls) if (controls[3]) { loco_x += 1.0f; } Vector2 Locomotion = new Vector2(loco_x, loco_y); Locomotion /= (Locomotion.Length() != 0 ? Locomotion.Length() : 1.0f); - Locomotion *= 0.1f; + Locomotion *= 256f; Vector2 FrictionVector1 = new Vector2(0.0f - (Obstacle1.Velocity.X / (Obstacle1.Velocity.Length() != 0 ? Obstacle1.Velocity.Length() : 1.0f)), 0.0f - (Obstacle1.Velocity.Y / (Obstacle1.Velocity.Length() != 0 ? Obstacle1.Velocity.Length() : 1.0f))); - FrictionVector1 *= Obstacle1.Mass * 0.00001f; + FrictionVector1 *= Obstacle1.Mass * 0.5f; Vector2 FrictionVector2 = new Vector2(0.0f - (Obstacle2.Velocity.X / (Obstacle2.Velocity.Length() != 0 ? Obstacle2.Velocity.Length() : 1.0f)), 0.0f - (Obstacle2.Velocity.Y / (Obstacle2.Velocity.Length() != 0 ? Obstacle2.Velocity.Length() : 1.0f))); - FrictionVector2 *= Obstacle2.Mass * 0.00000005f; + FrictionVector2 *= Obstacle2.Mass * 0.05f; if (Obstacle1.Velocity.Length() >= 0.001f) { #if !MUTE diff --git a/_Example/Game1.cs b/_Example/Game1.cs index 7c45527..428e42c 100644 --- a/_Example/Game1.cs +++ b/_Example/Game1.cs @@ -25,10 +25,10 @@ public class Game1 : Game private Boolean[] IsCtrlKeyDown = new bool[8] { false, false, false, false, false, false, false, false}; private Boolean FullScreen; private Double EscapeTimer = 0.0f; - #if DEBUG +#if DEBUG private Double LastRegisteredEventTime; +#endif private Double TimeSinceError = 0.0f; - #endif private HashSet LogicEventSet = new HashSet(); private Boolean ContinuityError = false; private Boolean WideScreen @@ -221,10 +221,7 @@ protected override void Draw(GameTime gameTime) GraphicsDevice.Clear(Color.Black); _spriteBatch.Begin(); - #if DEBUG - _spriteBatch.DrawString(_spriteFont, "FPS: "+FrameRate.ToString()+" || Fullscreen: "+FullScreen.ToString()+String.Format(" || Resolution: {0}x{1}", Window.ClientBounds.Width, Window.ClientBounds.Height) + " || Frame active: "+(ActiveFrame != null?ActiveFrame.FrameID.ToString():"-1")+" || Update rate: "+Math.Round(1000/LastRegisteredEventTime), new Vector2(0, 0), (FrameRate > 50 ? Color.White : (FrameRate > 24 ? Color.Yellow : Color.Red))); - #endif - _spriteBatch.DrawString(_spriteFont, "Quitting...", new Vector2(0, 12), new Color(new Vector4((float) EscapeTimer/1000))); + if (ContinuityError) { _spriteBatch.DrawString(_spriteFontLarge, "/!\\ CONTINUITY ERROR /!\\", SharedMethodSet.FindTextAlignment(_spriteFontLarge, "/!\\ CONTINUITY ERROR /!\\", Window.ClientBounds, 0.5f, 0.5f), Color.Red); @@ -261,6 +258,10 @@ protected override void Draw(GameTime gameTime) { ActiveFrame.Draw(gameTime, _spriteBatch); } +#if DEBUG + _spriteBatch.DrawString(_spriteFont, "FPS: " + FrameRate.ToString() + " || Fullscreen: " + FullScreen.ToString() + String.Format(" || Resolution: {0}x{1}", Window.ClientBounds.Width, Window.ClientBounds.Height) + " || Frame active: " + (ActiveFrame != null ? ActiveFrame.FrameID.ToString() : "-1") + " || Update rate: " + Math.Round(1000 / LastRegisteredEventTime), new Vector2(0, 0), (FrameRate > 50 ? Color.White : (FrameRate > 24 ? Color.Yellow : Color.Red))); +#endif + _spriteBatch.DrawString(_spriteFont, "Quitting...", new Vector2(0, 12), new Color(new Vector4((float)EscapeTimer / 1000))); _spriteBatch.End(); base.Draw(gameTime); diff --git a/_Example/GameData/DotRPG.Example_data.mgcb b/_Example/GameData/DotRPG.Example_data.mgcb index 239d975..8e0b538 100644 --- a/_Example/GameData/DotRPG.Example_data.mgcb +++ b/_Example/GameData/DotRPG.Example_data.mgcb @@ -60,6 +60,18 @@ /processorParam:Quality=Best /build:Sounds/wallcling.wav +#begin Texture2D/backdrop.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Texture2D/backdrop.png + #begin Texture2D/Banana.png /importer:TextureImporter /processor:TextureProcessor @@ -108,6 +120,54 @@ /processorParam:TextureFormat=Color /build:Texture2D/cube-p.png +#begin Texture2D/red.idle.down.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Texture2D/red.idle.down.png + +#begin Texture2D/red.idle.left.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Texture2D/red.idle.left.png + +#begin Texture2D/red.idle.right.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Texture2D/red.idle.right.png + +#begin Texture2D/red.idle.up.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Texture2D/red.idle.up.png + #begin Texture2D/ScrollMarker.png /importer:TextureImporter /processor:TextureProcessor diff --git a/_Example/GameData/Fonts/File.spritefont b/_Example/GameData/Fonts/File.spritefont index 18e80c2..f694e12 100644 --- a/_Example/GameData/Fonts/File.spritefont +++ b/_Example/GameData/Fonts/File.spritefont @@ -11,8 +11,8 @@ with. - VCR OSD Mono - + + Alef - VCR OSD Mono - + + Alef