diff --git a/assets/games/rose/prefabs/SwordHitbox.xml b/assets/games/rose/prefabs/SwordHitbox.xml
index baf9c98b..548cd61f 100644
--- a/assets/games/rose/prefabs/SwordHitbox.xml
+++ b/assets/games/rose/prefabs/SwordHitbox.xml
@@ -1,5 +1,5 @@
-
+
\ No newline at end of file
diff --git a/src/dawn/scene/components/physics/2d/CharacterController2D.cpp b/src/dawn/scene/components/physics/2d/CharacterController2D.cpp
index f94d0c21..88dcc6fb 100644
--- a/src/dawn/scene/components/physics/2d/CharacterController2D.cpp
+++ b/src/dawn/scene/components/physics/2d/CharacterController2D.cpp
@@ -14,7 +14,7 @@ CharacterController2D::CharacterController2D(SceneItem *i) :
void CharacterController2D::onStart() {
useEvent([&](float_t delta){
- if(velocity == glm::vec2(0, 0)) return;
+ // if(velocity == glm::vec2(0, 0)) return;
// Common variables
auto myCollider = item->getComponent();
@@ -64,9 +64,11 @@ void CharacterController2D::onStart() {
}
}
- transform->setLocalPosition(
- transform->getLocalPosition() + (glm::vec3(moveAmount.x, 0, moveAmount.y) * delta)
- );
+ if(moveAmount != glm::vec2(0, 0)) {
+ transform->setLocalPosition(
+ transform->getLocalPosition() + (glm::vec3(moveAmount.x, 0, moveAmount.y) * delta)
+ );
+ }
// Now perform trigger collision check
auto allTriggers = getScene()->findComponents();
diff --git a/src/dawnrose/scene/components/HurtHazard.hpp b/src/dawnrose/scene/components/HurtHazard.hpp
index 947e75d1..4e7552b5 100644
--- a/src/dawnrose/scene/components/HurtHazard.hpp
+++ b/src/dawnrose/scene/components/HurtHazard.hpp
@@ -20,6 +20,7 @@ namespace Dawn {
float_t hitKnockback = 20.0f;
// @optional
int32_t damage = 1;
+ // @optional
enum Faction faction = FACTION_NONE;
// @optional
StateProperty trigger;
diff --git a/src/dawnrose/scene/components/entity/EntityMove.cpp b/src/dawnrose/scene/components/entity/EntityMove.cpp
index 11fb5208..dc233de4 100644
--- a/src/dawnrose/scene/components/entity/EntityMove.cpp
+++ b/src/dawnrose/scene/components/entity/EntityMove.cpp
@@ -15,7 +15,6 @@ std::vector EntityMove::getDependencies() {
return {
(characterController = item->getComponent()),
(this->entityHealth = item->getComponent()),
- (this->entitySwordAttack = item->getComponent())
};
}
@@ -26,7 +25,6 @@ void EntityMove::onStart() {
useEvent([&](float_t delta) {
// Don't move if stunned or attacking.
if(entityHealth->isStunned()) return;
- if(entitySwordAttack != nullptr && entitySwordAttack->isAttacking()) return;
// Don't move if no move.
if(direction.x == 0 && direction.y == 0) return;
diff --git a/src/dawnrose/scene/components/entity/EntityMove.hpp b/src/dawnrose/scene/components/entity/EntityMove.hpp
index 097e6661..9b754841 100644
--- a/src/dawnrose/scene/components/entity/EntityMove.hpp
+++ b/src/dawnrose/scene/components/entity/EntityMove.hpp
@@ -7,14 +7,12 @@
#include "scene/SceneItemComponent.hpp"
#include "scene/components/physics/2d/CharacterController2D.hpp"
#include "scene/components/entity/EntityHealth.hpp"
-#include "scene/components/entity/EntitySwordAttack.hpp"
namespace Dawn {
class EntityMove : public SceneItemComponent {
protected:
CharacterController2D *characterController = nullptr;
EntityHealth *entityHealth = nullptr;
- EntitySwordAttack *entitySwordAttack = nullptr;
public:
// @optional
diff --git a/src/dawnrose/scene/components/entity/EntitySwordAttack.cpp b/src/dawnrose/scene/components/entity/EntitySwordAttack.cpp
index 19b2cdd8..6a35d41f 100644
--- a/src/dawnrose/scene/components/entity/EntitySwordAttack.cpp
+++ b/src/dawnrose/scene/components/entity/EntitySwordAttack.cpp
@@ -4,6 +4,7 @@
// https://opensource.org/licenses/MIT
#include "EntitySwordAttack.hpp"
+#include "prefabs/SwordHitbox.hpp"
using namespace Dawn;
@@ -12,33 +13,29 @@ EntitySwordAttack::EntitySwordAttack(SceneItem* item) : EntityAttackBase(item) {
void EntitySwordAttack::onStart() {
EntityAttackBase::onStart();
+
+ this->hurtboxItem = SwordHitbox::create(this->getScene());
+ this->hurtboxItem->transform.setParent(this->transform);
- useEvent([&]{
- }, this->onAttackRampUpStart);
+ useEffect([&]{
+ switch(this->state) {
+ case ENTITY_ATTACK_STATE_ACTIVE: {
+ auto myFaction = item->getComponent();
+ if(myFaction != nullptr) this->hurtboxItem->hazard->faction = myFaction->faction;
+ this->hurtboxItem->transform.setLocalPosition(this->attackOffset);
+ break;
+ }
+ default: {
+ this->hurtboxItem->transform.setLocalPosition(glm::vec3(99999999,0,0));
+ break;
+ }
+ }
+ }, this->state)();
+}
- useEvent([&]{
- }, this->onAttackRampUpEnd);
-
- useEvent([&]{
- }, this->onAttackActiveStart);
-
- useEvent([&]{
- }, this->onAttackActiveEnd);
-
- useEvent([&]{
- }, this->onAttackRampDownStart);
-
- useEvent([&]{
- }, this->onAttackRampDownEnd);
-
- useEvent([&]{
- }, this->onAttackCooldownStart);
-
- useEvent([&]{
- }, this->onAttackCooldownEnd);
-
- useEvent([&]{
- }, this->onAttackInterrupted);
+void EntitySwordAttack::onDispose() {
+ EntityAttackBase::onDispose();
+ this->hurtboxItem->destroy();
}
float_t EntitySwordAttack::getAttackRampUpDuration() {
diff --git a/src/dawnrose/scene/components/entity/EntitySwordAttack.hpp b/src/dawnrose/scene/components/entity/EntitySwordAttack.hpp
index 0814f023..72004153 100644
--- a/src/dawnrose/scene/components/entity/EntitySwordAttack.hpp
+++ b/src/dawnrose/scene/components/entity/EntitySwordAttack.hpp
@@ -5,16 +5,26 @@
#pragma once
#include "EntityAttackBase.hpp"
+#include "scene/components/entity/EntityFaction.hpp"
namespace Dawn {
+ class SwordHitbox;
+
class EntitySwordAttack : public EntityAttackBase {
protected:
float_t attackTime = -1;
+ SwordHitbox *hurtboxItem = nullptr;
public:
+ // @optional
+ glm::vec3 attackOffset = glm::vec3(0,0,1);
+ // @optional
+ glm::vec3 attackSize = glm::vec3(1,1,1);
+
EntitySwordAttack(SceneItem* item);
void onStart() override;
+ void onDispose() override;
float_t getAttackRampUpDuration() override;
float_t getAttackActiveDuration() override;