Browse Source

Move InertiaComponent to Ex3

physics
Emilia Jarosz 7 months ago
parent
commit
37cd937cbd
4 changed files with 21 additions and 14 deletions
  1. +1
    -1
      Expansion1/ExampleInputComponent.cs
  2. +1
    -0
      Expansion2/ExampleShootingInputComponent.cs
  3. +18
    -13
      Expansion3/InertiaComponent.cs
  4. +1
    -0
      Program.cs

+ 1
- 1
Expansion1/ExampleInputComponent.cs View File

@ -1,7 +1,7 @@
using Smoll; using Smoll;
using Raylib_cs; using Raylib_cs;
using System.Numerics; using System.Numerics;
using Smoll.Ex2;
using Smoll.Ex3;
namespace Smoll.Ex1 namespace Smoll.Ex1
{ {

+ 1
- 0
Expansion2/ExampleShootingInputComponent.cs View File

@ -2,6 +2,7 @@ using Smoll;
using Raylib_cs; using Raylib_cs;
using System.Numerics; using System.Numerics;
using Smoll.Ex1; using Smoll.Ex1;
using Smoll.Ex3;
namespace Smoll.Ex2 namespace Smoll.Ex2
{ {

Expansion2/InertiaComponent.cs → Expansion3/InertiaComponent.cs View File

@ -1,34 +1,39 @@
using System.Numerics; using System.Numerics;
namespace Smoll.Ex2 {
sealed class InertiaComponent : Component {
namespace Smoll.Ex3
{
sealed class InertiaComponent : Component
{
public Transform2D transform; public Transform2D transform;
public float dampening; public float dampening;
private Transform2DComponent? ownerTransform; private Transform2DComponent? ownerTransform;
public InertiaComponent(float dampening = 1)
: this(dampening,0,0,0)
{}
public InertiaComponent(float dampening = 1)
: this(dampening, 0, 0, 0)
{ }
public InertiaComponent(float dampening, float x, float y)
: this(dampening,x,y,0)
{}
public InertiaComponent(float dampening, float x, float y)
: this(dampening, x, y, 0)
{ }
public InertiaComponent(float dampening, float x, float y, float angle) {
public InertiaComponent(float dampening, float x, float y, float angle)
{
transform = new Transform2D(); transform = new Transform2D();
transform.position = y*Complex.ImaginaryOne + x;
transform.position = y * Complex.ImaginaryOne + x;
transform.angle = angle; transform.angle = angle;
transform.scale = 1; transform.scale = 1;
this.dampening = dampening; this.dampening = dampening;
} }
public InertiaComponent(float dampening, Transform2D tr) {
public InertiaComponent(float dampening, Transform2D tr)
{
transform = tr; transform = tr;
this.dampening = dampening; this.dampening = dampening;
} }
public override void OnAttached() {
public override void OnAttached()
{
ownerTransform = owner.GetComponent<Transform2DComponent>(); ownerTransform = owner.GetComponent<Transform2DComponent>();
} }
@ -41,7 +46,7 @@ namespace Smoll.Ex2 {
transform.position *= MathF.Pow(dampening, deltaTimeSeconds); transform.position *= MathF.Pow(dampening, deltaTimeSeconds);
transform.angle *= MathF.Pow(dampening, deltaTimeSeconds); transform.angle *= MathF.Pow(dampening, deltaTimeSeconds);
} }
} }

+ 1
- 0
Program.cs View File

@ -2,6 +2,7 @@
using Smoll; using Smoll;
using Smoll.Ex1; using Smoll.Ex1;
using Smoll.Ex2; using Smoll.Ex2;
using Smoll.Ex3;
Raylib.InitWindow(800, 600, "Smoll"); Raylib.InitWindow(800, 600, "Smoll");

Loading…
Cancel
Save