Finished coin counter
This commit is contained in:
@@ -2,13 +2,13 @@
|
||||
#include <AnimationPlayer.hpp>
|
||||
|
||||
using namespace godot;
|
||||
int coin = 0;
|
||||
|
||||
void 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);
|
||||
register_signal<CoinCollected>("coin_collected", "amount", GODOT_VARIANT_TYPE_INT);
|
||||
}
|
||||
|
||||
CoinCollected::CoinCollected()
|
||||
@@ -26,7 +26,6 @@ void CoinCollected::_init()
|
||||
|
||||
void CoinCollected::_state_enter()
|
||||
{
|
||||
coin = coin + 1;
|
||||
auto node = get_parent()->find_node("AnimationPlayer");
|
||||
|
||||
if (node != nullptr)
|
||||
@@ -44,8 +43,10 @@ void CoinCollected::_state_exit()
|
||||
|
||||
void CoinCollected::_on_animation_finished(String anim_name)
|
||||
{
|
||||
emit_signal("coin_collected", 1);
|
||||
this->get_parent()->queue_free();
|
||||
|
||||
|
||||
// get_state_machine()->change("CoinCounter");
|
||||
|
||||
}
|
||||
|
@@ -1,14 +1,12 @@
|
||||
#include "coin/CoinCounter.h"
|
||||
#include <Control.hpp>
|
||||
|
||||
#include <String.hpp>
|
||||
#include "coin/CoinCollected.h"
|
||||
using namespace godot;
|
||||
|
||||
|
||||
void CoinCounter::_register_methods()
|
||||
{
|
||||
register_method("_state_enter", &CoinCounter::_state_enter);
|
||||
register_method("_state_exit", &CoinCounter::_state_exit);
|
||||
register_method("_on_body_entered", &CoinCounter::_on_CoinHUD_ready);
|
||||
register_method("_on_coin_collected", &CoinCounter::_on_coin_collected);
|
||||
register_method("_ready", &CoinCounter::_ready);
|
||||
}
|
||||
|
||||
CoinCounter::CoinCounter()
|
||||
@@ -24,20 +22,26 @@ void CoinCounter::_init()
|
||||
|
||||
}
|
||||
|
||||
void CoinCounter::_state_enter()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CoinCounter::_state_exit()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CoinCounter::_on_CoinHUD_ready()
|
||||
{
|
||||
get_node("Coins").text() = "hola";
|
||||
|
||||
|
||||
}
|
||||
void CoinCounter::_on_coin_collected(int amount)
|
||||
{
|
||||
coins = coins + amount;
|
||||
set_text(String::num(coins));
|
||||
}
|
||||
void CoinCounter::_ready()
|
||||
{
|
||||
set_text("0");
|
||||
auto coins_node = get_node("../../Coins");
|
||||
auto children_count = coins_node->get_child_count();
|
||||
for(int64_t i = 0; i < children_count;i++)
|
||||
{
|
||||
auto child = coins_node->get_child(i);
|
||||
child->get_node("StateMachine/CoinCollected")->connect("coin_collected",this,"_on_coin_collected");
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@@ -1,28 +1,24 @@
|
||||
#ifndef ALAI_COIN_COUNTER
|
||||
#define ALAI_COIN_COUNTER
|
||||
|
||||
#include "state_machine/State.h"
|
||||
|
||||
#include <Godot.hpp>
|
||||
#include <Node.hpp>
|
||||
#include <AnimatedSprite.hpp>
|
||||
#include <Label.hpp>
|
||||
|
||||
namespace godot
|
||||
{
|
||||
/**
|
||||
* @brief This class controls what happens when the Coin is in the collected state.
|
||||
* @brief This class controls what happens when the Coin is in the collected .
|
||||
*
|
||||
*/
|
||||
class CoinCounter : public State
|
||||
class CoinCounter : public Label
|
||||
{
|
||||
GODOT_CLASS(CoinCounter, State)
|
||||
GODOT_CLASS(CoinCounter, Label)
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief The animated sprite of the Coin.
|
||||
*
|
||||
*/
|
||||
AnimatedSprite *animated_sprite;
|
||||
int coins = 0;
|
||||
|
||||
|
||||
public:
|
||||
/**
|
||||
@@ -52,23 +48,13 @@ namespace godot
|
||||
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.
|
||||
* @brief Called when the collected of the coin is entered.
|
||||
*
|
||||
*/
|
||||
|
||||
void _on_CoinHUD_ready();
|
||||
void _on_coin_collected(int amount);
|
||||
void _ready();
|
||||
|
||||
};
|
||||
|
||||
|
@@ -11,6 +11,7 @@
|
||||
#include "player/states/PlayerFall.h"
|
||||
#include "coin/CoinNotCollected.h"
|
||||
#include "coin/CoinCollected.h"
|
||||
#include "coin/CoinCounter.h"
|
||||
|
||||
using namespace godot;
|
||||
|
||||
@@ -53,4 +54,5 @@ extern "C" void GDN_EXPORT godot_nativescript_init(void *handle)
|
||||
register_class<player::PlayerFall>();
|
||||
register_class<CoinNotCollected>();
|
||||
register_class<CoinCollected>();
|
||||
register_class<CoinCounter>();
|
||||
}
|
||||
|
Reference in New Issue
Block a user