cleanup code
This commit is contained in:
@@ -1,55 +1,48 @@
|
||||
#include "coin/CoinCollected.h"
|
||||
#include <AnimationPlayer.hpp>
|
||||
|
||||
#include "Event.h"
|
||||
|
||||
using namespace godot;
|
||||
#include <AnimationPlayer.hpp>
|
||||
|
||||
void CoinCollected::_register_methods()
|
||||
void alai::CoinCollected::_register_methods()
|
||||
{
|
||||
register_method("_state_enter", &CoinCollected::_state_enter);
|
||||
register_method("_state_exit", &CoinCollected::_state_exit);
|
||||
register_method("_on_animation_finished", &CoinCollected::_on_animation_finished);
|
||||
}
|
||||
|
||||
CoinCollected::CoinCollected()
|
||||
alai::CoinCollected::CoinCollected()
|
||||
{
|
||||
}
|
||||
|
||||
CoinCollected::~CoinCollected()
|
||||
alai::CoinCollected::~CoinCollected()
|
||||
{
|
||||
}
|
||||
|
||||
void CoinCollected::_init()
|
||||
void alai::CoinCollected::_init()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CoinCollected::_state_enter()
|
||||
void alai::CoinCollected::_state_enter()
|
||||
{
|
||||
auto node = get_parent()->find_node("AnimationPlayer");
|
||||
|
||||
if (node != nullptr)
|
||||
{
|
||||
auto animation_player = Object::cast_to<AnimationPlayer>(node);
|
||||
auto animation_player = Object::cast_to<godot::AnimationPlayer>(node);
|
||||
animation_player->play("jump");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void CoinCollected::_state_exit()
|
||||
void alai::CoinCollected::_state_exit()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CoinCollected::_on_animation_finished(String anim_name)
|
||||
void alai::CoinCollected::_on_animation_finished(godot::String anim_name)
|
||||
{
|
||||
auto event = get_node<alai::Event>("/root/Event");
|
||||
event->emit_signal("coin_collected", 1);
|
||||
this->get_parent()->queue_free();
|
||||
|
||||
|
||||
// get_state_machine()->change("CoinCounter");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,75 +1,73 @@
|
||||
#ifndef ALAI_COIN_COLLECTED
|
||||
#define ALAI_COIN_COLLECTED
|
||||
#ifndef ALAI_COIN_COIN_COLLECTED_H
|
||||
#define ALAI_COIN_COIN_COLLECTED_H
|
||||
|
||||
#include "state_machine/State.h"
|
||||
|
||||
#include <Godot.hpp>
|
||||
#include <Node.hpp>
|
||||
#include <AnimatedSprite.hpp>
|
||||
#include <Godot.hpp>
|
||||
|
||||
namespace godot
|
||||
namespace alai
|
||||
{
|
||||
/**
|
||||
* @brief This class controls what happens when the Coin is in the collected state.
|
||||
*
|
||||
*/
|
||||
class CoinCollected : public State
|
||||
{
|
||||
GODOT_CLASS(CoinCollected, State)
|
||||
/**
|
||||
* @brief This class controls what happens when the Coin is in the collected state.
|
||||
*
|
||||
*/
|
||||
class CoinCollected : public alai::State
|
||||
{
|
||||
GODOT_CLASS(CoinCollected, alai::State)
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief The animated sprite of the Coin.
|
||||
*
|
||||
*/
|
||||
AnimatedSprite *animated_sprite;
|
||||
private:
|
||||
/**
|
||||
* @brief The animated sprite of the Coin.
|
||||
*
|
||||
*/
|
||||
godot::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();
|
||||
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 CoinCollected object.
|
||||
*
|
||||
*/
|
||||
CoinCollected();
|
||||
/**
|
||||
* @brief Construct a new CoinCollected object.
|
||||
*
|
||||
*/
|
||||
CoinCollected();
|
||||
|
||||
/**
|
||||
* @brief Destroy the CoinCollected object.
|
||||
*
|
||||
*/
|
||||
~CoinCollected();
|
||||
/**
|
||||
* @brief Destroy the CoinCollected object.
|
||||
*
|
||||
*/
|
||||
~CoinCollected();
|
||||
|
||||
/**
|
||||
* @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 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 entered.
|
||||
*
|
||||
*/
|
||||
void _state_enter();
|
||||
|
||||
/**
|
||||
* @brief Called when the collected state of the coin is exited.
|
||||
*
|
||||
*/
|
||||
void _state_exit();
|
||||
/**
|
||||
* @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.
|
||||
*
|
||||
*/
|
||||
void _on_animation_finished(String anim_name);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Called when the animation of the collected coin has finished.
|
||||
*
|
||||
*/
|
||||
void _on_animation_finished(godot::String anim_name);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,43 +1,37 @@
|
||||
#include "coin/CoinCounter.h"
|
||||
#include <String.hpp>
|
||||
#include "coin/CoinCollected.h"
|
||||
#include "Event.h"
|
||||
using namespace godot;
|
||||
|
||||
void CoinCounter::_register_methods()
|
||||
#include "Event.h"
|
||||
|
||||
#include <String.hpp>
|
||||
|
||||
void alai::CoinCounter::_register_methods()
|
||||
{
|
||||
register_method("_on_coin_collected", &CoinCounter::_on_coin_collected);
|
||||
register_method("_ready", &CoinCounter::_ready);
|
||||
}
|
||||
|
||||
CoinCounter::CoinCounter()
|
||||
alai::CoinCounter::CoinCounter()
|
||||
{
|
||||
}
|
||||
|
||||
CoinCounter::~CoinCounter()
|
||||
alai::CoinCounter::~CoinCounter()
|
||||
{
|
||||
}
|
||||
|
||||
void CoinCounter::_init()
|
||||
void alai::CoinCounter::_init()
|
||||
{
|
||||
|
||||
coins = 0;
|
||||
}
|
||||
|
||||
void CoinCounter::_on_CoinHUD_ready()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
void CoinCounter::_on_coin_collected(int amount)
|
||||
void alai::CoinCounter::_on_coin_collected(int amount)
|
||||
{
|
||||
coins = coins + amount;
|
||||
set_text(String::num(coins));
|
||||
set_text(godot::String::num(coins));
|
||||
}
|
||||
void CoinCounter::_ready()
|
||||
|
||||
void alai::CoinCounter::_ready()
|
||||
{
|
||||
set_text("0");
|
||||
auto event = get_node<alai::Event>("/root/Event");
|
||||
event->connect("coin_collected", this, "_on_coin_collected");
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,62 +1,59 @@
|
||||
#ifndef ALAI_COIN_COUNTER
|
||||
#define ALAI_COIN_COUNTER
|
||||
|
||||
#ifndef ALAI_COIN_COIN_COUNTER_H
|
||||
#define ALAI_COIN_COIN_COUNTER_H
|
||||
|
||||
#include <Godot.hpp>
|
||||
#include <Node.hpp>
|
||||
#include <Label.hpp>
|
||||
|
||||
namespace godot
|
||||
namespace alai
|
||||
{
|
||||
/**
|
||||
* @brief This class controls what happens when the Coin is in the collected .
|
||||
*
|
||||
*/
|
||||
class CoinCounter : public Label
|
||||
{
|
||||
GODOT_CLASS(CoinCounter, Label)
|
||||
/**
|
||||
* @brief This class controls what happens when the Coin is in the collected .
|
||||
*
|
||||
*/
|
||||
class CoinCounter : public godot::Label
|
||||
{
|
||||
GODOT_CLASS(CoinCounter, godot::Label)
|
||||
|
||||
private:
|
||||
int coins = 0;
|
||||
private:
|
||||
int coins;
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief This method registers classes with Godot.
|
||||
*
|
||||
* @details This method registers methods, properties, and signals with the Godot engine.
|
||||
*/
|
||||
static void _register_methods();
|
||||
|
||||
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 CoinCounter object.
|
||||
*
|
||||
*/
|
||||
CoinCounter();
|
||||
|
||||
/**
|
||||
* @brief Construct a new CoinCounter object.
|
||||
*
|
||||
*/
|
||||
CoinCounter();
|
||||
/**
|
||||
* @brief Destroy the CoinCounter object.
|
||||
*
|
||||
*/
|
||||
~CoinCounter();
|
||||
|
||||
/**
|
||||
* @brief Destroy the CoinCounter object.
|
||||
*
|
||||
*/
|
||||
~CoinCounter();
|
||||
/**
|
||||
* @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 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 of the coin is entered.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Called when the collected of the coin is entered.
|
||||
*
|
||||
*/
|
||||
|
||||
void _on_CoinHUD_ready();
|
||||
void _on_coin_collected(int amount);
|
||||
void _ready();
|
||||
|
||||
};
|
||||
void _on_CoinHUD_ready();
|
||||
void _on_coin_collected(int amount);
|
||||
void _ready();
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,56 +1,46 @@
|
||||
#include "coin/CoinNotCollected.h"
|
||||
|
||||
#include <Area2D.hpp>
|
||||
|
||||
using namespace godot;
|
||||
|
||||
|
||||
void CoinNotCollected::_register_methods()
|
||||
void alai::CoinNotCollected::_register_methods()
|
||||
{
|
||||
register_method("_state_enter", &CoinNotCollected::_state_enter);
|
||||
register_method("_state_exit", &CoinNotCollected::_state_exit);
|
||||
register_method("_on_body_entered", &CoinNotCollected::_on_body_entered);
|
||||
}
|
||||
|
||||
CoinNotCollected::CoinNotCollected()
|
||||
alai::CoinNotCollected::CoinNotCollected()
|
||||
{
|
||||
}
|
||||
|
||||
CoinNotCollected::~CoinNotCollected()
|
||||
alai::CoinNotCollected::~CoinNotCollected()
|
||||
{
|
||||
}
|
||||
|
||||
void CoinNotCollected::_init()
|
||||
void alai::CoinNotCollected::_init()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CoinNotCollected::_state_enter()
|
||||
void alai::CoinNotCollected::_state_enter()
|
||||
{
|
||||
animated_sprite = get_parent()->get_node<AnimatedSprite>("AnimatedSprite");
|
||||
animated_sprite = get_parent()->get_node<godot::AnimatedSprite>("AnimatedSprite");
|
||||
animated_sprite->set_animation("spin");
|
||||
animated_sprite->play();
|
||||
}
|
||||
|
||||
void CoinNotCollected::_state_exit()
|
||||
void alai::CoinNotCollected::_state_exit()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CoinNotCollected::_on_body_entered(Node *node)
|
||||
void alai::CoinNotCollected::_on_body_entered(Node *node)
|
||||
{
|
||||
Godot::print("Coin touched");
|
||||
auto parent_node = get_parent();
|
||||
|
||||
if (parent_node != nullptr)
|
||||
{
|
||||
auto coin = Object::cast_to<Area2D>(parent_node);
|
||||
auto coin = Object::cast_to<godot::Area2D>(parent_node);
|
||||
coin->set_collision_mask_bit(0, false);
|
||||
}
|
||||
|
||||
get_state_machine()->change("CoinCollected");
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,76 +1,74 @@
|
||||
#ifndef ALAI_COIN_NOT_COLLECTED
|
||||
#define ALAI_COIN_NOT_COLLECTED
|
||||
#ifndef ALAI_COIN_COIN_NOT_COLLECTED_H
|
||||
#define ALAI_COIN_COIN_NOT_COLLECTED_H
|
||||
|
||||
#include "state_machine/State.h"
|
||||
|
||||
#include <Godot.hpp>
|
||||
#include <Node.hpp>
|
||||
#include <AnimatedSprite.hpp>
|
||||
#include <Godot.hpp>
|
||||
|
||||
namespace godot
|
||||
namespace alai
|
||||
{
|
||||
/**
|
||||
* @brief This class controls what happens when the Coin is in the not collected state.
|
||||
*
|
||||
*/
|
||||
class CoinNotCollected : public State
|
||||
{
|
||||
GODOT_CLASS(CoinNotCollected, State)
|
||||
/**
|
||||
* @brief This class controls what happens when the Coin is in the not collected state.
|
||||
*
|
||||
*/
|
||||
class CoinNotCollected : public alai::State
|
||||
{
|
||||
GODOT_CLASS(CoinNotCollected, alai::State)
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief The animated sprite of the Coin.
|
||||
*
|
||||
*/
|
||||
AnimatedSprite *animated_sprite;
|
||||
private:
|
||||
/**
|
||||
* @brief The animated sprite of the Coin.
|
||||
*
|
||||
*/
|
||||
godot::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();
|
||||
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 CoinNotCollected object.
|
||||
*
|
||||
*/
|
||||
CoinNotCollected();
|
||||
/**
|
||||
* @brief Construct a new CoinNotCollected object.
|
||||
*
|
||||
*/
|
||||
CoinNotCollected();
|
||||
|
||||
/**
|
||||
* @brief Destroy the CoinNotCollected object.
|
||||
*
|
||||
*/
|
||||
~CoinNotCollected();
|
||||
/**
|
||||
* @brief Destroy the CoinNotCollected object.
|
||||
*
|
||||
*/
|
||||
~CoinNotCollected();
|
||||
|
||||
/**
|
||||
* @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 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 entered.
|
||||
*
|
||||
*/
|
||||
void _state_enter();
|
||||
|
||||
/**
|
||||
* @brief Called when the not collected state of the coin is exited.
|
||||
*
|
||||
*/
|
||||
void _state_exit();
|
||||
/**
|
||||
* @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_body_entered(Node *node);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Method called on body entered.
|
||||
*
|
||||
* @param[in] node Node interacting with whoever
|
||||
*/
|
||||
void _on_body_entered(Node *node);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user