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
14 changes: 13 additions & 1 deletion DotRPG.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotRPG.Example", "_Example\
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotRPG.Objects.Complexity", "Objects\Complexity\DotRPG.Objects.Complexity.csproj", "{A5B3FC78-C694-440E-9D99-7CE4FA6A01AC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotRPG.Objects.Dynamics", "Objects\Dynamics\DotRPG.Objects.Dynamics.csproj", "{35012066-AC4B-4144-90C9-7F42681652C8}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotRPG.Objects.Dynamics", "Objects\Dynamics\DotRPG.Objects.Dynamics.csproj", "{35012066-AC4B-4144-90C9-7F42681652C8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotRPG.Scripting.Pipeline", "Scripting\Pipeline\DotRPG.Scripting.Pipeline.csproj", "{4B3EB206-0C31-4504-807C-14E346EB155D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotRPG.Scripting", "Scripting\DotRPG.Scripting.csproj", "{610FDEAE-E1EB-475C-A095-2F337FBB5A2C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -33,6 +37,14 @@ Global
{35012066-AC4B-4144-90C9-7F42681652C8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{35012066-AC4B-4144-90C9-7F42681652C8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{35012066-AC4B-4144-90C9-7F42681652C8}.Release|Any CPU.Build.0 = Release|Any CPU
{4B3EB206-0C31-4504-807C-14E346EB155D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4B3EB206-0C31-4504-807C-14E346EB155D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4B3EB206-0C31-4504-807C-14E346EB155D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4B3EB206-0C31-4504-807C-14E346EB155D}.Release|Any CPU.Build.0 = Release|Any CPU
{610FDEAE-E1EB-475C-A095-2F337FBB5A2C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{610FDEAE-E1EB-475C-A095-2F337FBB5A2C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{610FDEAE-E1EB-475C-A095-2F337FBB5A2C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{610FDEAE-E1EB-475C-A095-2F337FBB5A2C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
674 changes: 0 additions & 674 deletions LICENSE

This file was deleted.

504 changes: 504 additions & 0 deletions LICENSE.md

Large diffs are not rendered by default.

48 changes: 37 additions & 11 deletions Objects/Dynamics/DynamicRectObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,27 @@ public Vector2 Momentum
return new Vector2(Velocity.X * Mass, Velocity.Y * Mass);
}
}
public DynamicRectObject(Point StartLocation, Point colliderSize, Single mass)
public DynamicRectObject(Point StartLocation, Point colliderSize, Single mass, Boolean isStatic = false)
{
Location = StartLocation.ToVector2();
BodySize = colliderSize;
Mass = mass;
Static = isStatic;
}

public void CollideWith(DynamicRectObject another, Boolean hitVertically)
public void CollideWith(DynamicRectObject another, Boolean hitVertically, Boolean splitVector)
{
if (another.Static)
{
this.Velocity = new Vector2(!hitVertically ? 0.0f : this.Velocity.X, hitVertically ? 0.0f : this.Velocity.Y);
if (splitVector)
{
this.Velocity = new Vector2(!hitVertically ? 0.0f : this.Velocity.X, hitVertically ? 0.0f : this.Velocity.Y);
}
else
{
this.Velocity = Vector2.Zero;
}

if (hitVertically)
{
if (this.Location.Y >= another.Location.Y)
Expand Down Expand Up @@ -87,8 +96,17 @@ public void CollideWith(DynamicRectObject another, Boolean hitVertically)

if (hitVertically)
{
this.Velocity = new Vector2(this.Velocity.X, Summary_Y_Momentum / this.Mass);
another.Velocity = new Vector2(another.Velocity.X, Summary_Y_Momentum / another.Mass);
if (splitVector)
{
this.Velocity = new Vector2(this.Velocity.X, Summary_Y_Momentum / this.Mass);
another.Velocity = new Vector2(another.Velocity.X, Summary_Y_Momentum / another.Mass);
}
else
{
this.Velocity = new Vector2(Summary_X_Momentum / this.Mass, Summary_Y_Momentum / this.Mass);
another.Velocity = new Vector2(Summary_X_Momentum / another.Mass, Summary_Y_Momentum / another.Mass);
}

if (this.Mass > another.Mass)
{
if (this.Location.Y >= another.Location.Y)
Expand All @@ -114,8 +132,16 @@ public void CollideWith(DynamicRectObject another, Boolean hitVertically)
}
else
{
this.Velocity = new Vector2(Summary_X_Momentum / this.Mass, this.Velocity.Y);
another.Velocity = new Vector2(Summary_X_Momentum / another.Mass, another.Velocity.Y);
if (splitVector)
{
this.Velocity = new Vector2(Summary_X_Momentum / this.Mass, this.Velocity.Y);
another.Velocity = new Vector2(Summary_X_Momentum / another.Mass, another.Velocity.Y);
}
else
{
this.Velocity = new Vector2(Summary_X_Momentum / this.Mass, Summary_Y_Momentum / this.Mass);
another.Velocity = new Vector2(Summary_X_Momentum / another.Mass, Summary_Y_Momentum / another.Mass);
}
if (this.Mass > another.Mass)
{
if (this.Location.X >= another.Location.X)
Expand Down Expand Up @@ -152,24 +178,24 @@ public void Draw(SpriteBatch _sb, GameTime gameTime, Int32 VirtualVSize, Point s
Sprite.Draw(_sb, location, gameTime, sizeMorph);
}

public Boolean TryCollideWith(DynamicRectObject another)
public Boolean TryCollideWith(DynamicRectObject another, Boolean splitVector = false)
{
if (this.Collider.Intersects(another.Collider))
{
if (1.0 * Math.Abs(this.Location.X - another.Location.X) / (this.BodySize.X / 2 + another.BodySize.X / 2) >= 1.0 * Math.Abs(this.Location.Y - another.Location.Y) / (this.BodySize.Y / 2 + another.BodySize.Y / 2))
{
CollideWith(another, false);
CollideWith(another, false, splitVector);
}
else
{
CollideWith(another, true);
CollideWith(another, true, splitVector);
}
return true;
}
return false;
}

public void Update(GameTime gameTime)
public virtual void Update(GameTime gameTime)
{
Velocity += AppliedForce / ((Single)gameTime.ElapsedGameTime.TotalSeconds * this.Mass);
Location += Velocity / (Single)gameTime.ElapsedGameTime.TotalSeconds;
Expand Down
89 changes: 89 additions & 0 deletions Objects/Dynamics/Player.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;

namespace DotRPG.Objects.Dynamics
{
public enum Direction
{
Up=0, Down=1, Left=2, Right=3
};

public class Player : DynamicRectObject
{
protected Point SightAreaSize;
public Direction SightDirection;

public virtual Rectangle SightArea
{
get
{
switch (SightDirection)
{
case Direction.Up:
{
return new Rectangle
(
Collider.X + Collider.Width / 2 - SightAreaSize.X,
Collider.Y - SightAreaSize.Y,
SightAreaSize.X,
SightAreaSize.Y
);
}
case Direction.Down:
{
return new Rectangle
(
Collider.X + Collider.Width / 2 - SightAreaSize.X,
Collider.Y + Collider.Height + SightAreaSize.Y,
SightAreaSize.X,
SightAreaSize.Y
);
}
case Direction.Left:
{
return new Rectangle
(
Collider.X - SightArea.X,
Collider.Y + Collider.Height / 2 - SightAreaSize.Y,
SightAreaSize.X,
SightAreaSize.Y
);
}
case Direction.Right:
{
return new Rectangle
(
Collider.X + Collider.Width + SightArea.X,
Collider.Y + Collider.Height / 2 - SightAreaSize.Y,
SightAreaSize.X,
SightAreaSize.Y
);
}
default:
{
return new Rectangle
(
Collider.X + Collider.Width / 2 - SightAreaSize.X / 2,
Collider.Y + Collider.Height / 2 - SightAreaSize.Y / 2,
SightAreaSize.X,
SightAreaSize.Y
);
}
}
}
}

public Player(Point StartLocation, Point colliderSize, Single mass, Point sightAreaSize) : base(StartLocation, colliderSize, mass, false)
{
SightAreaSize = sightAreaSize;
}

public void Update(GameTime gameTime, Direction lookTowards)
{
base.Update(gameTime);
SightDirection = lookTowards;
}
}
}
2 changes: 1 addition & 1 deletion Objects/TextObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void Draw(SpriteBatch _sb, GameWindow w)
}
// Alighning text according to set anchor position and client bounds
Vector2 position = SharedMethodSet.FindTextAlignment(Font, (ScrollPerTick > 0 ? WrittenString : Text), w.ClientBounds, RelativeAlignmentX, RelativeAlignmentY, AlignAnchor, w.ClientBounds.Height / DefaultScreenScale);
_sb.DrawString(Font, (ScrollPerTick > 0 ? WrittenString : Text), position, TextColor, Rotation, new Vector2(0.0f), 1.0f*(w.ClientBounds.Height)/DefaultScreenScale, SpriteEffects.None, Depth);
_sb.DrawString(Font, (ScrollPerTick > 0 ? WrittenString : Text), position, TextColor, Rotation, new Vector2(0.0f), 1.0f*w.ClientBounds.Height/DefaultScreenScale, SpriteEffects.None, Depth);
LastDrawnText = DrawnText;
}
public void ResetToStart()
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,12 @@ A game engine for creation of jRPGs and visual novels based on MonoGame.
+ Timed event firing
+ Rigid body collision physics (see \_Example and Objects/Dynamics projects)

## DotRPG uses
+ [**MonoGame**](https://github.com/MonoGame/MonoGame) -- an open source XNA framework successor. This engine heavily relies on MonoGame's constructions.
+ [**NLua**](https://github.com/NLua/NLua) -- Embedded Lua runtime

**NOTE**: To make sure everything compiles correctly, install MonoGame packages into solution manually.

(C) 2021 red-the-random-dev

Distributed under GPL license 3.0
17 changes: 17 additions & 0 deletions Scripting/DotRPG.Scripting.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Compile Remove="Pipeline\**" />
<EmbeddedResource Remove="Pipeline\**" />
<None Remove="Pipeline\**" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="NLua" Version="1.5.11" />
</ItemGroup>

</Project>
43 changes: 43 additions & 0 deletions Scripting/LuaModule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using NLua;

namespace DotRPG.Scripting
{
/// <summary>
/// Embedded Lua module which features Update() function done every frame.
/// </summary>
public class LuaModule
{
public Lua Runtime;
public Boolean IsUp = true;
public Int32 EventID;
public readonly Int32 EventAmount;

public LuaModule(String initFile, Int32 eventAmount)
{
Runtime = new Lua();
Runtime.LoadCLRPackage();
Runtime.DoString(initFile);
EventAmount = eventAmount;
}
public LuaModule(String initFile)
{
Runtime = new Lua();
Runtime.LoadCLRPackage();
Runtime.DoString(initFile);
EventAmount = (Int32) Runtime["event_count"];
}

public void Update(Single elapsedTime, Single totalTime)
{
LuaFunction loopFunction = Runtime["loop"] as LuaFunction;
loopFunction.Call(EventID, elapsedTime, totalTime);
EventID++;
if (EventID >= EventAmount)
{
EventID = 0;
}
}
}
}
16 changes: 16 additions & 0 deletions Scripting/Pipeline/DotRPG.Scripting.Pipeline.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MonoGame.Framework.Content.Pipeline" Version="3.8.0.1641">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.0.1641">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DotRPG.Scripting.csproj" />
</ItemGroup>
</Project>
17 changes: 17 additions & 0 deletions Scripting/Pipeline/ScriptImporter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Microsoft.Xna.Framework.Content.Pipeline;
using Scripting = DotRPG.Scripting;
using System.IO;

using TImport = System.String;

namespace DotRPG.Scripting.Pipeline
{
[ContentImporter(".lua", DisplayName = "DotRPG embeddable script handler", DefaultProcessor = "ScriptProcessor")]
public class ScriptImporter : ContentImporter<TImport>
{
public override TImport Import(string filename, ContentImporterContext context)
{
return File.ReadAllText(filename);
}
}
}
16 changes: 16 additions & 0 deletions Scripting/Pipeline/ScriptProcessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Microsoft.Xna.Framework.Content.Pipeline;

using TInput = System.String;
using TOutput = DotRPG.Scripting.LuaModule;

namespace ScriptImporter
{
[ContentProcessor(DisplayName = "DotRPG script processor")]
class ScriptProcessor : ContentProcessor<TInput, TOutput>
{
public override TOutput Process(TInput input, ContentProcessorContext context)
{
return new TOutput(input);
}
}
}
Loading