Flag successfully placed on lvl, hitbox detected and working

This commit is contained in:
2022-07-17 21:51:11 -04:00
parent b9ff12dab3
commit d14cc627de
7 changed files with 300 additions and 2 deletions

View File

@@ -0,0 +1,56 @@
#include "goal/GoalNotReached.h"
#include <Area2D.hpp>
using namespace godot;
void GoalNotReached::_register_methods()
{
register_method("_state_enter", &GoalNotReached::_state_enter);
register_method("_state_exit", &GoalNotReached::_state_exit);
register_method("_on_Goal_body_entered", &GoalNotReached::_on_Goal_body_entered);
}
GoalNotReached::GoalNotReached()
{
}
GoalNotReached::~GoalNotReached()
{
}
void GoalNotReached::_init()
{
}
void GoalNotReached::_state_enter()
{
animated_sprite = get_parent()->get_node<AnimatedSprite>("AnimatedSprite");
animated_sprite->set_animation("flagmove");
animated_sprite->play();
}
void GoalNotReached::_state_exit()
{
}
void GoalNotReached::_on_Goal_body_entered(Node *node)
{
Godot::print("Flag touched");
/* auto parent_node = get_parent();
if (parent_node != nullptr)
{
auto goal = Object::cast_to<Area2D>(parent_node);
goal->set_collision_mask_bit(0, false);
}
get_state_machine()->change("GoalReached");*/
}

76
src/goal/GoalNotReached.h Normal file
View File

@@ -0,0 +1,76 @@
#ifndef ALAI_GOAL_NOT_REACHED
#define ALAI_GOAL_NOT_REACHED
#include "state_machine/State.h"
#include <Godot.hpp>
#include <Node.hpp>
#include <AnimatedSprite.hpp>
namespace godot
{
/**
* @brief This class controls what happens when the Coin is in the not collected state.
*
*/
class GoalNotReached : public State
{
GODOT_CLASS(GoalNotReached, State)
private:
/**
* @brief The animated sprite of the Coin.
*
*/
AnimatedSprite *animated_sprite;
public:
/**
* @brief This method registers classes with Godot.
*
* @details This method registers methods, properties, and signals with the Godot engine.
*/
static void _register_methods();
/**
* @brief Construct a new GoalNotReached object.
*
*/
GoalNotReached();
/**
* @brief Destroy the GoalNotReached object.
*
*/
~GoalNotReached();
/**
* @brief Initialize the class from Godot.
*
* @details This method is called just once when the Godot engine connects to the instance of the class.
*/
void _init();
/**
* @brief Called when the not collected state of the coin is entered.
*
*/
void _state_enter();
/**
* @brief Called when the not collected state of the coin is exited.
*
*/
void _state_exit();
/**
* @brief Method called on body entered.
*
* @param[in] node Node interacting with whoever
*/
void _on_Goal_body_entered(Node *node);
};
}
#endif

35
src/goal/GoalReached.cpp Normal file
View File

@@ -0,0 +1,35 @@
#include "goal/GoalReached.h"
using namespace godot;
void GoalReached::_register_methods()
{
register_method("_state_enter", &GoalReached::_state_enter);
register_method("_state_exit", &GoalReached::_state_exit);
//register_signal<GoalReached>("coin_collected", "amount", GODOT_VARIANT_TYPE_INT);
}
GoalReached::GoalReached()
{
}
GoalReached::~GoalReached()
{
}
void GoalReached::_init()
{
}
void GoalReached::_state_enter()
{
}
void GoalReached::_state_exit()
{
}

74
src/goal/GoalReached.h Normal file
View File

@@ -0,0 +1,74 @@
#ifndef ALAI_GOAL_REACHED
#define ALAI_GOAL_REACHED
#include "state_machine/State.h"
#include <Godot.hpp>
#include <Node.hpp>
#include <AnimatedSprite.hpp>
namespace godot
{
/**
* @brief This class controls what happens when the goal flag is in the reached state.
*
*/
class GoalReached : public State
{
GODOT_CLASS(GoalReached, State)
private:
/**
* @brief The animated sprite of the Coin.
*
*/
AnimatedSprite *animated_sprite;
public:
/**
* @brief This method registers classes with Godot.
*
* @details This method registers methods, properties, and signals with the Godot engine.
*/
static void _register_methods();
/**
* @brief Construct a new GoalReached object.
*
*/
GoalReached();
/**
* @brief Destroy the GoalReached object.
*
*/
~GoalReached();
/**
* @brief Initialize the class from Godot.
*
* @details This method is called just once when the Godot engine connects to the instance of the class.
*/
void _init();
/**
* @brief Called when the collected state of the coin is entered.
*
*/
void _state_enter();
/**
* @brief Called when the collected state of the coin is exited.
*
*/
void _state_exit();
/**
* @brief Called when the animation of the collected coin has finished.
*
*/
};
}
#endif

View File

@@ -12,6 +12,8 @@
#include "coin/CoinNotCollected.h"
#include "coin/CoinCollected.h"
#include "coin/CoinCounter.h"
#include "goal/GoalReached.h"
#include "goal/GoalNotReached.h"
using namespace godot;
@@ -55,4 +57,6 @@ extern "C" void GDN_EXPORT godot_nativescript_init(void *handle)
register_class<CoinNotCollected>();
register_class<CoinCollected>();
register_class<CoinCounter>();
register_class<GoalReached>();
register_class<GoalNotReached>();
}