Super happy jumping pickle man (#3)

* Added enemy class

* Added enemy class and fixed DumpFraction bug.

* Update README.md

* Fixed enemy movement bug, added game music.

* Fixed bug: Background music looping.

* Fixed enemey getting stuck on wall. Code reorganization

* Minor updates
This commit is contained in:
J. M. Ellis
2024-06-02 15:47:52 -07:00
committed by GitHub
parent ef749d0666
commit 0e8ac75cef
12 changed files with 427 additions and 180 deletions
+45
View File
@@ -0,0 +1,45 @@
using Microsoft.Xna.Framework;
namespace LunaLightXMG
{
public class CollisionManager
{
// Method to check if a position is colliding with any platform
public bool IsColliding(Vector2 newPosition, BoundingBox boundingBox, Platform[] platforms)
{
Rectangle newBounds = new Rectangle((int)newPosition.X, (int)newPosition.Y, boundingBox.Bounds.Width, boundingBox.Bounds.Height);
foreach (var platform in platforms)
{
if (newBounds.Intersects(platform.BoundingBox.Bounds))
{
return true;
}
}
return false;
}
// Method to check if a position is colliding with any platform and return the colliding platform
public Platform GetCollidingPlatform(Vector2 newPosition, BoundingBox boundingBox, Platform[] platforms)
{
Rectangle newBounds = new Rectangle((int)newPosition.X, (int)newPosition.Y, boundingBox.Bounds.Width, boundingBox.Bounds.Height);
foreach (var platform in platforms)
{
if (newBounds.Intersects(platform.BoundingBox.Bounds))
{
return platform;
}
}
return null;
}
// Method to check if a position is colliding with any wall
public bool WallCheck(Vector2 position, BoundingBox boundingBox, Platform[] platforms)
{
if (IsColliding(position + new Vector2(1, 0), boundingBox, platforms) || IsColliding(position + new Vector2(-1, 0), boundingBox, platforms))
{
return true;
}
return false;
}
}
}