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
6 changes: 6 additions & 0 deletions DotRPG.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ 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}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -27,6 +29,10 @@ Global
{A5B3FC78-C694-440E-9D99-7CE4FA6A01AC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A5B3FC78-C694-440E-9D99-7CE4FA6A01AC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A5B3FC78-C694-440E-9D99-7CE4FA6A01AC}.Release|Any CPU.Build.0 = Release|Any CPU
{35012066-AC4B-4144-90C9-7F42681652C8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{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
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
8 changes: 8 additions & 0 deletions Objects/DotRPG.Objects.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Complexity\**" />
<Compile Remove="Dynamics\**" />
<EmbeddedResource Remove="Complexity\**" />
<EmbeddedResource Remove="Dynamics\**" />
<None Remove="Complexity\**" />
<None Remove="Dynamics\**" />
</ItemGroup>
<ItemGroup>
<None Remove="Icon.ico" />
<None Remove="Icon.bmp" />
Expand Down
11 changes: 11 additions & 0 deletions Objects/Dynamics/DotRPG.Objects.Dynamics.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

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

<ItemGroup>
<ProjectReference Include="..\DotRPG.Objects.csproj" />
</ItemGroup>

</Project>
184 changes: 184 additions & 0 deletions Objects/Dynamics/DynamicRectObject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using DotRPG.Objects;

namespace DotRPG.Objects.Dynamics
{
public class DynamicRectObject
{
public Boolean Static;
public Vector2 Location;
protected Point BodySize;
public SpriteController Sprite;
public Rectangle Collider
{
get
{
return new Rectangle
(
(int)Location.X - BodySize.X / 2,
(int)Location.Y - BodySize.Y / 2,
BodySize.X,
BodySize.Y
);
}
}
/// <summary>
/// Vector value which describes how much body will travel (pts/s)
/// </summary>
public Vector2 Velocity;
public Single Mass;
public Vector2 AppliedForce = Vector2.Zero;

public Single KineticEnergy
{
get
{
return Mass * (Single)Math.Pow(Velocity.Length(), 2) / 2.0f;
}
}
public Vector2 Momentum
{
get
{
return new Vector2(Velocity.X * Mass, Velocity.Y * Mass);
}
}
public DynamicRectObject(Point StartLocation, Point colliderSize, Single mass)
{
Location = StartLocation.ToVector2();
BodySize = colliderSize;
Mass = mass;
}

public void CollideWith(DynamicRectObject another, Boolean hitVertically)
{
if (another.Static)
{
this.Velocity = new Vector2(!hitVertically ? 0.0f : this.Velocity.X, hitVertically ? 0.0f : this.Velocity.Y);
if (hitVertically)
{
if (this.Location.Y >= another.Location.Y)
{
this.Location.Y += Math.Max((this.BodySize.Y / 2 + another.BodySize.Y / 2) - Math.Abs(this.Location.Y - another.Location.Y), 0);
}
else
{
this.Location.Y -= Math.Max((this.BodySize.Y / 2 + another.BodySize.Y / 2) - Math.Abs(this.Location.Y - another.Location.Y), 0);
}
}
else
{
if (this.Location.X >= another.Location.X)
{
this.Location.X += Math.Max((this.BodySize.X / 2 + another.BodySize.X / 2) - Math.Abs(this.Location.X - another.Location.X), 0);
}
else
{
this.Location.X -= Math.Max((this.BodySize.X / 2 + another.BodySize.X / 2) - Math.Abs(this.Location.X - another.Location.X), 0);
}
}
return;
}
Single Summary_X_Momentum = (this.Momentum.X + another.Momentum.X) / 2;
Single Summary_Y_Momentum = (this.Momentum.Y + another.Momentum.Y) / 2;

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 (this.Mass > another.Mass)
{
if (this.Location.Y >= another.Location.Y)
{
another.Location.Y -= Math.Max((this.BodySize.Y / 2 + another.BodySize.Y / 2) - Math.Abs(this.Location.Y - another.Location.Y), 0);
}
else
{
another.Location.Y += Math.Max((this.BodySize.Y / 2 + another.BodySize.Y / 2) - Math.Abs(this.Location.Y - another.Location.Y), 0);
}
}
else
{
if (this.Location.Y >= another.Location.Y)
{
this.Location.Y += Math.Max((this.BodySize.Y / 2 + another.BodySize.Y / 2) - Math.Abs(this.Location.Y - another.Location.Y), 0);
}
else
{
this.Location.Y -= Math.Max((this.BodySize.Y / 2 + another.BodySize.Y / 2) - Math.Abs(this.Location.Y - another.Location.Y), 0);
}
}
}
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 (this.Mass > another.Mass)
{
if (this.Location.X >= another.Location.X)
{
another.Location.X -= Math.Max((this.BodySize.X / 2 + another.BodySize.X / 2) - Math.Abs(this.Location.X - another.Location.X), 0);
}
else
{
another.Location.X += Math.Max((this.BodySize.X / 2 + another.BodySize.X / 2) - Math.Abs(this.Location.X - another.Location.X), 0);
}
}
else
{
if (this.Location.X >= another.Location.X)
{
this.Location.X += Math.Max((this.BodySize.X / 2 + another.BodySize.X / 2) - Math.Abs(this.Location.X - another.Location.X), 0);
}
else
{
this.Location.X -= Math.Max((this.BodySize.X / 2 + another.BodySize.X / 2) - Math.Abs(this.Location.X - another.Location.X), 0);
}
}
}
}

public void Draw(SpriteBatch _sb, GameTime gameTime, Int32 VirtualVSize, Point scrollOffset, Point scrollSize)
{
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
);
Sprite.Draw(_sb, location, gameTime, sizeMorph);
}

public Boolean TryCollideWith(DynamicRectObject another)
{
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);
}
else
{
CollideWith(another, true);
}
return true;
}
return false;
}

public void Update(GameTime gameTime)
{
Velocity += AppliedForce / ((Single)gameTime.ElapsedGameTime.TotalSeconds * this.Mass);
Location += Velocity / (Single)gameTime.ElapsedGameTime.TotalSeconds;
AppliedForce = Vector2.Zero;
}

public void FullStop()
{
Velocity = Vector2.Zero;
}
}
}
4 changes: 2 additions & 2 deletions Objects/SpriteController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void AddAnimationSequence(String sequenceName, Texture2D frames, UInt16 f
LoopTo.Add(sequenceName, loopTo);
}

public void Draw(SpriteBatch _sb, Vector2 drawLocation, GameTime gameTime)
public void Draw(SpriteBatch _sb, Vector2 drawLocation, GameTime gameTime, Single drawSize = 1.0f)
{
Single addFrames = 0.0f;
if (PlaybackSpeed > 0.0f)
Expand Down Expand Up @@ -88,7 +88,7 @@ public void Draw(SpriteBatch _sb, Vector2 drawLocation, GameTime gameTime)
Color.White,
0,
Vector2.Zero,
1,
drawSize,
SpriteEffects.None,
0
);
Expand Down
3 changes: 2 additions & 1 deletion _Example/DotRPG.Example.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
Expand Down Expand Up @@ -30,5 +30,6 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Objects\DotRPG.Objects.csproj" />
<ProjectReference Include="..\Objects\Dynamics\DotRPG.Objects.Dynamics.csproj" />
</ItemGroup>
</Project>
Loading