-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add tilemap collision resolution - Add gravity & movement to player - Add player animations
- Loading branch information
Showing
27 changed files
with
986 additions
and
240 deletions.
There are no files selected for viewing
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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,88 @@ | ||
#pragma once | ||
|
||
#include "game_entity_IEntity.h" | ||
|
||
namespace sym::game::entity | ||
{ | ||
|
||
class IPhysicsEntity : public IEntity | ||
{ | ||
public: | ||
virtual ~IPhysicsEntity() = 0; | ||
|
||
IPhysicsEntity(bn::fixed_point position, bn::fixed_rect relativeInteractRange, | ||
bn::fixed_rect relativePhysicsCollider, bool isGravityEnabledByDefault, bn::fixed gravityScale, | ||
const bn::sprite_item* spriteItem); | ||
|
||
IPhysicsEntity(IPhysicsEntity&& other); | ||
IPhysicsEntity& operator=(IPhysicsEntity&& other); | ||
|
||
IPhysicsEntity(const IPhysicsEntity& other) = delete; | ||
IPhysicsEntity& operator=(const IPhysicsEntity& other) = delete; | ||
|
||
/** | ||
* @brief Get the physics collider. | ||
* Absolute Coordinate. | ||
* | ||
* @return `bn::fixed_rect` collider | ||
*/ | ||
[[nodiscard]] bn::fixed_rect GetPhysicsCollider() const; | ||
|
||
[[nodiscard]] bool GetGravityEnabled() const; | ||
void SetGravityEnabled(bool isGravityEnabled); | ||
|
||
[[nodiscard]] bn::fixed GetGravityScale() const; | ||
void SetGravityScale(bn::fixed gravityScale); | ||
[[maybe_unused]] bool ToggleGravityEnabled(); | ||
|
||
[[nodiscard]] bn::fixed_point GetVelocity() const; | ||
void SetVelocity(bn::fixed_point velocity); | ||
void SetXVelocity(bn::fixed xVel); | ||
void SetYVelocity(bn::fixed yVel); | ||
|
||
[[nodiscard]] bool GetGrounded() const; | ||
void SetGrounded(bool); | ||
|
||
enum class MoveDirections | ||
{ | ||
UP = 1, | ||
DOWN = 2, | ||
LEFT = 4, | ||
RIGHT = 8 | ||
}; | ||
MoveDirections GetMoveDirections() const; | ||
|
||
static constexpr bn::fixed EPSILON_VEL = 0.01; | ||
|
||
protected: | ||
/** | ||
* @brief saves collider relative to the position_. | ||
* | ||
*/ | ||
bn::fixed_rect relativePhysicsCollider_; | ||
bool isGravityEnabled_; | ||
bn::fixed gravityScale_; | ||
|
||
bn::fixed_point velocity_ = {0, 0}; | ||
bool isGrounded_ = false; | ||
}; | ||
|
||
inline IPhysicsEntity::MoveDirections operator|(IPhysicsEntity::MoveDirections d1, IPhysicsEntity::MoveDirections d2) | ||
{ | ||
using MoveDirections = IPhysicsEntity::MoveDirections; | ||
return static_cast<MoveDirections>(static_cast<int>(d1) | static_cast<int>(d2)); | ||
} | ||
|
||
inline IPhysicsEntity::MoveDirections operator&(IPhysicsEntity::MoveDirections d1, IPhysicsEntity::MoveDirections d2) | ||
{ | ||
using MoveDirections = IPhysicsEntity::MoveDirections; | ||
return static_cast<MoveDirections>(static_cast<int>(d1) & static_cast<int>(d2)); | ||
} | ||
|
||
inline bool operator!(IPhysicsEntity::MoveDirections dir) | ||
{ | ||
using MoveDirections = IPhysicsEntity::MoveDirections; | ||
return dir == static_cast<MoveDirections>(0); | ||
} | ||
|
||
} // namespace sym::game::entity |
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,32 @@ | ||
#pragma once | ||
|
||
#include "game_system_ISystem.h" | ||
|
||
namespace sym::game::system | ||
{ | ||
|
||
class PhysicsMovement final : public ISystem | ||
{ | ||
public: | ||
PhysicsMovement(scene::GameState& state); | ||
|
||
void Update() final; | ||
|
||
private: | ||
void UpdatePlayer_(); | ||
void PlayerKeyboardHandle_(); | ||
void PlayerGravity_(); | ||
void PlayerClampVelocity_(); | ||
void PlayerCollision_(); | ||
void PlayerAnimation_(); | ||
|
||
void UpdateSymbols_(); | ||
void UpdateSymbolsInHands_(); | ||
void UpdateSymbolsOnFloor_(); | ||
void UpdateSymbolsThrown_(); | ||
|
||
static constexpr int MAX_PLAYER_JUMP_COUNT = 1; | ||
int playerJumpCount = MAX_PLAYER_JUMP_COUNT; | ||
}; | ||
|
||
} // namespace sym::game::system |
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,18 @@ | ||
#pragma once | ||
|
||
#include "bn_log.h" | ||
#include <bn_assert.h> | ||
#include <bn_fixed.h> | ||
|
||
namespace sym::helper::math | ||
{ | ||
|
||
[[nodiscard]] inline bn::fixed operator%(bn::fixed a, int b) | ||
{ | ||
bn::fixed result = a - (a / b).floor_integer() * b; | ||
BN_LOG("operator% : ", result); | ||
BN_ASSERT(0 <= result && result < b, "operator% is giving wrong result"); | ||
return result; | ||
} | ||
|
||
} // namespace sym::helper::math |
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
Oops, something went wrong.