-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
General Improvements, and started working on Physics Engine
- Loading branch information
1 parent
47f21a8
commit f22aca7
Showing
11 changed files
with
388 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* -*- encoding: utf-8 with BOM -*- | ||
* .▄▄ · ▄▄· ▄▄▄· ▄▄▄·▄▄▄ . ▄▄· ▄▄▄ ▄▄▄ . | ||
* ▐█ ▀. ▐█ ▌▪▐█ ▀█ ▐█ ▄█▀▄.▀· ▐█ ▌▪▪ ▀▄ █·▀▄.▀· | ||
* ▄▀▀▀█▄██ ▄▄▄█▀▀█ ██▀·▐▀▀▪▄ ██ ▄▄ ▄█▀▄ ▐▀▀▄ ▐▀▀▪▄ | ||
* ▐█▄▪▐█▐███▌▐█ ▪▐▌▐█▪·•▐█▄▄▌ ▐███▌▐█▌.▐▌▐█•█▌▐█▄▄▌ | ||
* ▀▀▀▀ ·▀▀▀ ▀ ▀ .▀ ▀▀▀ ·▀▀▀ ▀█▄▀▪.▀ ▀ ▀▀▀ | ||
* https://github.com/Papishushi/ScapeCore | ||
* | ||
* Copyright (c) 2023 Daniel Molinero Lucas | ||
* This file is subject to the terms and conditions defined in | ||
* file 'LICENSE.txt', which is part of this source code package. | ||
* | ||
* FPSMetric.cs | ||
* You can use this class to check the current FPS of your game. | ||
*/ | ||
|
||
using System; | ||
|
||
namespace ScapeCore.Targets | ||
{ | ||
public sealed class FPSMetric | ||
{ | ||
private static int _fps; | ||
private static int _framesSumatory; | ||
private static TimeSpan _fpsStartTime; | ||
private static TimeSpan _fpsEndTime; | ||
|
||
public static int FPS { get => _fps; } | ||
|
||
internal FPSMetric() | ||
{ | ||
if (_fpsStartTime == TimeSpan.Zero) | ||
_fpsStartTime = DateTime.Now.TimeOfDay; | ||
_framesSumatory++; | ||
_fpsEndTime = DateTime.Now.TimeOfDay; | ||
if (_fpsEndTime.Seconds == _fpsStartTime.Seconds + 1) | ||
{ | ||
_fpsStartTime = TimeSpan.Zero; | ||
_fpsEndTime = TimeSpan.Zero; | ||
_fps = _framesSumatory; | ||
_framesSumatory = 0; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* -*- encoding: utf-8 with BOM -*- | ||
* .▄▄ · ▄▄· ▄▄▄· ▄▄▄·▄▄▄ . ▄▄· ▄▄▄ ▄▄▄ . | ||
* ▐█ ▀. ▐█ ▌▪▐█ ▀█ ▐█ ▄█▀▄.▀· ▐█ ▌▪▪ ▀▄ █·▀▄.▀· | ||
* ▄▀▀▀█▄██ ▄▄▄█▀▀█ ██▀·▐▀▀▪▄ ██ ▄▄ ▄█▀▄ ▐▀▀▄ ▐▀▀▪▄ | ||
* ▐█▄▪▐█▐███▌▐█ ▪▐▌▐█▪·•▐█▄▄▌ ▐███▌▐█▌.▐▌▐█•█▌▐█▄▄▌ | ||
* ▀▀▀▀ ·▀▀▀ ▀ ▀ .▀ ▀▀▀ ·▀▀▀ ▀█▄▀▪.▀ ▀ ▀▀▀ | ||
* https://github.com/Papishushi/ScapeCore | ||
* | ||
* Copyright (c) 2023 Daniel Molinero Lucas | ||
* This file is subject to the terms and conditions defined in | ||
* file 'LICENSE.txt', which is part of this source code package. | ||
* | ||
* Collider2D.cs | ||
* Represent a 2D Collider with a size and an attached RigidBody. | ||
*/ | ||
|
||
using Microsoft.Xna.Framework; | ||
using ScapeCore.Core.Engine; | ||
using ScapeCore.Core.Engine.Components; | ||
using Serilog; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace ScapeCore.Core.Physics2D | ||
{ | ||
public class Collider2D : Component | ||
{ | ||
protected static readonly List<Collider2D> _colliders = new(); | ||
|
||
public Vector2 size; | ||
public RigidBody2D? attachedRigidbody; | ||
|
||
public Collider2D() | ||
{ | ||
_colliders.Add(this); | ||
size = new Vector2(10,10); | ||
attachedRigidbody = null; | ||
} | ||
|
||
public Collider2D(Vector2 size, RigidBody2D? attachedRigidbody) | ||
{ | ||
_colliders.Add(this); | ||
this.size = size; | ||
this.attachedRigidbody = attachedRigidbody; | ||
} | ||
|
||
internal List<Collider2D> IsIntersecting() | ||
{ | ||
List<Collider2D> result = new List<Collider2D>(); | ||
foreach (var collider in _colliders) | ||
{ | ||
if (collider == this) continue; | ||
var rb = collider.attachedRigidbody; | ||
if (rb == null || rb.transform == null || transform == null) | ||
continue; | ||
|
||
float deltaX = Math.Abs(transform.Position.X - rb.transform.Position.X); | ||
float deltaY = Math.Abs(transform.Position.Y - rb.transform.Position.Y); | ||
|
||
float intersectX = (size.X + collider.size.X) * 0.5f; | ||
float intersectY = (size.Y + collider.size.Y) * 0.5f; | ||
|
||
if (deltaX < intersectX && deltaY < intersectY) | ||
{ | ||
// There is an intersection | ||
result.Add(collider); | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
|
||
protected override void OnDestroy() | ||
{ | ||
_colliders.Remove(this); | ||
base.OnDestroy(); | ||
} | ||
} | ||
} |
Oops, something went wrong.