Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions Objects/CameraFrameObject.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
}
12 changes: 6 additions & 6 deletions Objects/Dynamics/DynamicRectObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
}

Expand Down
18 changes: 13 additions & 5 deletions Objects/SpriteController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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),
Expand All @@ -90,7 +98,7 @@ public void Draw(SpriteBatch _sb, Vector2 drawLocation, GameTime gameTime, Singl
Vector2.Zero,
drawSize,
SpriteEffects.None,
0
ZIndex
);
_i = newPos;
}
Expand Down
6 changes: 3 additions & 3 deletions _Example/DynamicsTestFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 7 additions & 6 deletions _Example/Game1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TimedEvent> LogicEventSet = new HashSet<TimedEvent>();
private Boolean ContinuityError = false;
private Boolean WideScreen
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
60 changes: 60 additions & 0 deletions _Example/GameData/DotRPG.Example_data.mgcb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions _Example/GameData/Fonts/File.spritefont
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ with.
<!--
Modify this string to change the font that will be imported.
-->
<FontName>VCR OSD Mono</FontName>

<!--<FontName>VCR OSD Mono</FontName>-->
<FontName>Alef</FontName>
<!--
Size is a float value, measured in points. Modify this value to change
the size of the font.
Expand Down
4 changes: 2 additions & 2 deletions _Example/GameData/Fonts/MainFont_Large.spritefont
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ with.
<!--
Modify this string to change the font that will be imported.
-->
<FontName>VCR OSD Mono</FontName>

<!--<FontName>VCR OSD Mono</FontName>-->
<FontName>Alef</FontName>
<!--
Size is a float value, measured in points. Modify this value to change
the size of the font.
Expand Down
Binary file added _Example/GameData/Texture2D/backdrop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _Example/GameData/Texture2D/red.idle.down.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _Example/GameData/Texture2D/red.idle.left.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _Example/GameData/Texture2D/red.idle.right.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _Example/GameData/Texture2D/red.idle.up.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 42 additions & 9 deletions _Example/ScriptTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class ScriptTest : Frame
DynamicRectObject dro;
Boolean[] lastInputCollection = new bool[8];
Boolean ShowingText;
CameraFrameObject cam = new CameraFrameObject();

public override int FrameID
{
Expand All @@ -39,14 +40,21 @@ public override void Initialize()

public override void Draw(GameTime gameTime, SpriteBatch spriteBatch, Rectangle drawZone)
{
Player.Draw(spriteBatch, gameTime, 540, new Point(0, 0), new Point(drawZone.Width, drawZone.Height));
dro.Draw(spriteBatch, gameTime, 540, new Point(0, 0), new Point(drawZone.Width, drawZone.Height));
spriteBatch.Draw(FrameResources.Textures["backdrop"], Vector2.Zero - cam.GetTopLeftAngle(new Point(drawZone.Width, drawZone.Height)).ToVector2(), new Rectangle(0, 0, 960, 540), Color.White, 0, Vector2.Zero, (drawZone.Height / 540), SpriteEffects.None, 1.0f);
dro.Draw(spriteBatch, gameTime, 540, cam.GetTopLeftAngle(new Point(drawZone.Width, drawZone.Height)), new Point(drawZone.Width, drawZone.Height), (0.3f - (0.1f * (dro.Location.Y / 540))));
Player.Draw(spriteBatch, gameTime, 540, cam.GetTopLeftAngle(new Point(drawZone.Width, drawZone.Height)), new Point(drawZone.Width, drawZone.Height), (0.3f - (0.1f * (Player.Location.Y / 540))));
if (ShowingText)
{
Texture2D rect = new Texture2D(spriteBatch.GraphicsDevice, drawZone.Width, drawZone.Height / 5);
Color[] data = new Color[drawZone.Width * drawZone.Height / 5];
for (int i = 0; i < data.Length; i++) data[i] = Color.Black;
rect.SetData(data);
Vector2 textBoxLocation = new Vector2(0, drawZone.Height * 4 / 5);
spriteBatch.Draw(rect, textBoxLocation, Color.White);
DialogForm.Draw(spriteBatch, Owner.Window);
}
#if DEBUG
spriteBatch.DrawString(FrameResources.Global.Fonts["vcr"], String.Format("Sight: {0}, Z key: {1}", Player.SightArea, lastInputCollection[4]), new Vector2(0, 12), Color.White);
spriteBatch.DrawString(FrameResources.Global.Fonts["vcr"], String.Format("Sight: {0}, Direction: {1}, AnimFrame: {2}", Player.SightArea, Player.SightDirection.ToString().ToLower(), Player.Sprite.SpriteIndex), new Vector2(0, 12), Color.White);
#endif
}

Expand Down Expand Up @@ -74,14 +82,18 @@ public override void Update(GameTime gameTime, bool[] controls)
{
Player.SightDirection = Direction.Right;
}
String newAnimSequence = String.Format("red.idle.{0}", Player.SightDirection.ToString().ToLower());
if (Player.Sprite.CurrentAnimationSequence != newAnimSequence)
{
Player.Sprite.SetAnimationSequence(newAnimSequence);
}
Locomotion /= (Locomotion.Length() != 0 ? Locomotion.Length() : 1.0f);
Locomotion *= 0.1f;
Locomotion *= 256f;
if (ShowingText)
{
Locomotion = Vector2.Zero;
}
Player.Velocity = Locomotion;
Player.TryCollideWith(dro);
if (controls[4] && !lastInputCollection[4] || (ShowingText && DialogForm.ReachedEnd && SceneSwitches.AutoScroll))
{
if (Player.SightArea.Intersects(dro.Collider) && !ShowingText)
Expand Down Expand Up @@ -113,6 +125,17 @@ public override void Update(GameTime gameTime, bool[] controls)
DialogForm.Update(gameTime);
}
Player.Update(gameTime);
Player.TryCollideWith(dro);
Player.TryCollideWith(dro);
if (ShowingText)
{
cam.TrackTarget = dro.Location.ToPoint();
}
else
{
cam.TrackTarget = Player.Location.ToPoint();
}
cam.Update(gameTime);
base.Update(gameTime, controls);
for (int i = 0; i < Math.Min(lastInputCollection.Length, controls.Length); i++)
{
Expand All @@ -127,14 +150,24 @@ public override void SetPlayerPosition(object sender, EventArgs e, GameTime game

public override void LoadContent()
{
FrameResources.Textures.Add("backdrop", Owner.Content.Load<Texture2D>("Texture2D/backdrop"));
DialogForm = new TextObject(FrameResources.Global.Fonts["vcr_large"], "...", 0.01f, 0.80f, Color.White, AlignMode.TopLeft, 1080, scrollPerTick: 1, scrollDelay: 0.04f);
DialogTest1 = new LuaModule(System.IO.File.ReadAllText(System.IO.Path.Join(Owner.Content.RootDirectory, "Scripts/dialog.lua")));
DialogTest1.Runtime["dialog"] = DialogForm;
DialogTest1.Runtime["scene"] = SceneSwitches;
Player = new PlayerObject(new Point(32, 32), new Point(32, 32), 20.0f, new Point(32, 8));
dro = new DynamicRectObject(new Point(32, 128), new Point(32, 32), 30.0f, true);
FrameResources.Textures.Add("cube-p", Owner.Content.Load<Texture2D>("Texture2D/cube-p"));
Player.Sprite = new SpriteController(1000 / 60.0f, FrameResources.Textures["cube-p"]);
Player = new PlayerObject(new Point(32, 64), new Point(32, 32), 20.0f, new Point(64, 64));
cam.Focus = Player.Location.ToPoint();
cam.CameraVelocity = 256f;
dro = new DynamicRectObject(new Point(128, 128), new Point(32, 32), 30.0f, true);
FrameResources.Textures.Add("red.idle.down", Owner.Content.Load<Texture2D>("Texture2D/red.idle.down"));
FrameResources.Textures.Add("red.idle.up", Owner.Content.Load<Texture2D>("Texture2D/red.idle.up"));
FrameResources.Textures.Add("red.idle.right", Owner.Content.Load<Texture2D>("Texture2D/red.idle.right"));
FrameResources.Textures.Add("red.idle.left", Owner.Content.Load<Texture2D>("Texture2D/red.idle.left"));
Player.Sprite = new SpriteController(1000 / 6.0f, FrameResources.Textures["red.idle.down"], 12);
Player.Sprite.AddAnimationSequence("red.idle.down", FrameResources.Textures["red.idle.down"], 12);
Player.Sprite.AddAnimationSequence("red.idle.up", FrameResources.Textures["red.idle.up"], 1);
Player.Sprite.AddAnimationSequence("red.idle.left", FrameResources.Textures["red.idle.left"], 12);
Player.Sprite.AddAnimationSequence("red.idle.right", FrameResources.Textures["red.idle.right"], 12);
FrameResources.Textures.Add("cube-o", Owner.Content.Load<Texture2D>("Texture2D/cube-o"));
dro.Sprite = new SpriteController(1000 / 60.0f, FrameResources.Textures["cube-o"]);
}
Expand Down