-
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.
- Loading branch information
Showing
12 changed files
with
299 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,29 @@ | ||
#pragma once | ||
|
||
#include <bn_fixed_rect.h> | ||
#include <bn_optional.h> | ||
#include <bn_sprite_item.h> | ||
#include <bn_sprite_ptr.h> | ||
|
||
namespace sym::game::entity | ||
{ | ||
|
||
class Entity | ||
{ | ||
public: | ||
virtual void FreeGraphicResources() = 0; | ||
virtual void AllocateGraphicResources() = 0; | ||
virtual ~Entity() = 0; | ||
|
||
Entity(bn::fixed_point position, bn::fixed_rect collider, const bn::sprite_item* const spriteItem = nullptr); | ||
Entity(Entity&& other) noexcept; | ||
|
||
void FreeGraphicResource(); | ||
virtual void AllocateGraphicResource(); | ||
|
||
protected: | ||
bn::fixed_point position_; | ||
bn::fixed_rect collider_; | ||
bn::optional<bn::sprite_ptr> sprite_; | ||
const bn::sprite_item* const spriteItem_; | ||
}; | ||
|
||
} // 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include <bn_fixed_rect.h> | ||
|
||
namespace sym::helper::rect | ||
{ | ||
|
||
[[nodiscard]] constexpr bn::fixed_rect MakeFixedRectByTopLeftAndSize(bn::fixed_point topLeft, bn::fixed_size size) | ||
{ | ||
const bn::fixed_point centerPos = topLeft + bn::fixed_point(size.width() / 2, size.height() / 2); | ||
return bn::fixed_rect(centerPos, size); | ||
} | ||
|
||
[[nodiscard]] constexpr bn::fixed_rect MakeFixedRectByTopLeftAndBottomRightPosition(bn::fixed_point topLeft, | ||
bn::fixed_point bottomRight) | ||
{ | ||
const bn::fixed_size size(bottomRight.x() - topLeft.x(), bottomRight.y() - topLeft.y()); | ||
return MakeFixedRectByTopLeftAndSize(topLeft, size); | ||
} | ||
|
||
} // namespace sym::helper::rect |
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,29 @@ | ||
#include "game_entity_Entity.h" | ||
|
||
namespace sym::game::entity | ||
{ | ||
|
||
Entity::~Entity() = default; | ||
|
||
Entity::Entity(bn::fixed_point position, bn::fixed_rect collider, const bn::sprite_item* const spriteItem) | ||
: position_(position), collider_(collider), spriteItem_(spriteItem) | ||
{ | ||
} | ||
|
||
Entity::Entity(Entity&& other) noexcept | ||
: collider_(other.collider_), sprite_(bn::move(other.sprite_)), spriteItem_(other.spriteItem_) | ||
{ | ||
} | ||
|
||
void Entity::FreeGraphicResource() | ||
{ | ||
sprite_.reset(); | ||
} | ||
|
||
void Entity::AllocateGraphicResource() | ||
{ | ||
if (spriteItem_) | ||
sprite_ = spriteItem_->create_sprite(collider_.position()); | ||
} | ||
|
||
} // namespace sym::game::entity |
Oops, something went wrong.