develop #34
@ -1,55 +1,48 @@
|
|||||||
#include "coin/CoinCollected.h"
|
#include "coin/CoinCollected.h"
|
||||||
#include <AnimationPlayer.hpp>
|
|
||||||
#include "Event.h"
|
#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_enter", &CoinCollected::_state_enter);
|
||||||
register_method("_state_exit", &CoinCollected::_state_exit);
|
register_method("_state_exit", &CoinCollected::_state_exit);
|
||||||
register_method("_on_animation_finished", &CoinCollected::_on_animation_finished);
|
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");
|
auto node = get_parent()->find_node("AnimationPlayer");
|
||||||
|
|
||||||
if (node != nullptr)
|
if (node != nullptr)
|
||||||
{
|
{
|
||||||
auto animation_player = Object::cast_to<AnimationPlayer>(node);
|
auto animation_player = Object::cast_to<godot::AnimationPlayer>(node);
|
||||||
animation_player->play("jump");
|
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");
|
auto event = get_node<alai::Event>("/root/Event");
|
||||||
event->emit_signal("coin_collected", 1);
|
event->emit_signal("coin_collected", 1);
|
||||||
this->get_parent()->queue_free();
|
this->get_parent()->queue_free();
|
||||||
|
|
||||||
|
|
||||||
// get_state_machine()->change("CoinCounter");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,28 +1,27 @@
|
|||||||
#ifndef ALAI_COIN_COLLECTED
|
#ifndef ALAI_COIN_COIN_COLLECTED_H
|
||||||
#define ALAI_COIN_COLLECTED
|
#define ALAI_COIN_COIN_COLLECTED_H
|
||||||
|
|
||||||
#include "state_machine/State.h"
|
#include "state_machine/State.h"
|
||||||
|
|
||||||
#include <Godot.hpp>
|
|
||||||
#include <Node.hpp>
|
|
||||||
#include <AnimatedSprite.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.
|
* @brief This class controls what happens when the Coin is in the collected state.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class CoinCollected : public State
|
class CoinCollected : public alai::State
|
||||||
{
|
{
|
||||||
GODOT_CLASS(CoinCollected, State)
|
GODOT_CLASS(CoinCollected, alai::State)
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* @brief The animated sprite of the Coin.
|
* @brief The animated sprite of the Coin.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
AnimatedSprite *animated_sprite;
|
godot::AnimatedSprite *animated_sprite;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
@ -67,9 +66,8 @@ namespace godot
|
|||||||
* @brief Called when the animation of the collected coin has finished.
|
* @brief Called when the animation of the collected coin has finished.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void _on_animation_finished(String anim_name);
|
void _on_animation_finished(godot::String anim_name);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,43 +1,37 @@
|
|||||||
#include "coin/CoinCounter.h"
|
#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("_on_coin_collected", &CoinCounter::_on_coin_collected);
|
||||||
register_method("_ready", &CoinCounter::_ready);
|
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 alai::CoinCounter::_on_coin_collected(int amount)
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
void CoinCounter::_on_coin_collected(int amount)
|
|
||||||
{
|
{
|
||||||
coins = coins + 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");
|
set_text("0");
|
||||||
auto event = get_node<alai::Event>("/root/Event");
|
auto event = get_node<alai::Event>("/root/Event");
|
||||||
event->connect("coin_collected", this, "_on_coin_collected");
|
event->connect("coin_collected", this, "_on_coin_collected");
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,24 +1,21 @@
|
|||||||
#ifndef ALAI_COIN_COUNTER
|
#ifndef ALAI_COIN_COIN_COUNTER_H
|
||||||
#define ALAI_COIN_COUNTER
|
#define ALAI_COIN_COIN_COUNTER_H
|
||||||
|
|
||||||
|
|
||||||
#include <Godot.hpp>
|
#include <Godot.hpp>
|
||||||
#include <Node.hpp>
|
|
||||||
#include <Label.hpp>
|
#include <Label.hpp>
|
||||||
|
|
||||||
namespace godot
|
namespace alai
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @brief This class controls what happens when the Coin is in the collected .
|
* @brief This class controls what happens when the Coin is in the collected .
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class CoinCounter : public Label
|
class CoinCounter : public godot::Label
|
||||||
{
|
{
|
||||||
GODOT_CLASS(CoinCounter, Label)
|
GODOT_CLASS(CoinCounter, godot::Label)
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int coins = 0;
|
int coins;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
|
@ -1,56 +1,46 @@
|
|||||||
#include "coin/CoinNotCollected.h"
|
#include "coin/CoinNotCollected.h"
|
||||||
|
|
||||||
#include <Area2D.hpp>
|
#include <Area2D.hpp>
|
||||||
|
|
||||||
using namespace godot;
|
void alai::CoinNotCollected::_register_methods()
|
||||||
|
|
||||||
|
|
||||||
void CoinNotCollected::_register_methods()
|
|
||||||
{
|
{
|
||||||
register_method("_state_enter", &CoinNotCollected::_state_enter);
|
register_method("_state_enter", &CoinNotCollected::_state_enter);
|
||||||
register_method("_state_exit", &CoinNotCollected::_state_exit);
|
register_method("_state_exit", &CoinNotCollected::_state_exit);
|
||||||
register_method("_on_body_entered", &CoinNotCollected::_on_body_entered);
|
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->set_animation("spin");
|
||||||
animated_sprite->play();
|
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();
|
auto parent_node = get_parent();
|
||||||
|
|
||||||
if (parent_node != nullptr)
|
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);
|
coin->set_collision_mask_bit(0, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
get_state_machine()->change("CoinCollected");
|
get_state_machine()->change("CoinCollected");
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,28 +1,27 @@
|
|||||||
#ifndef ALAI_COIN_NOT_COLLECTED
|
#ifndef ALAI_COIN_COIN_NOT_COLLECTED_H
|
||||||
#define ALAI_COIN_NOT_COLLECTED
|
#define ALAI_COIN_COIN_NOT_COLLECTED_H
|
||||||
|
|
||||||
#include "state_machine/State.h"
|
#include "state_machine/State.h"
|
||||||
|
|
||||||
#include <Godot.hpp>
|
|
||||||
#include <Node.hpp>
|
|
||||||
#include <AnimatedSprite.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.
|
* @brief This class controls what happens when the Coin is in the not collected state.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class CoinNotCollected : public State
|
class CoinNotCollected : public alai::State
|
||||||
{
|
{
|
||||||
GODOT_CLASS(CoinNotCollected, State)
|
GODOT_CLASS(CoinNotCollected, alai::State)
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* @brief The animated sprite of the Coin.
|
* @brief The animated sprite of the Coin.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
AnimatedSprite *animated_sprite;
|
godot::AnimatedSprite *animated_sprite;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
@ -70,7 +69,6 @@ namespace godot
|
|||||||
*/
|
*/
|
||||||
void _on_body_entered(Node *node);
|
void _on_body_entered(Node *node);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,55 +1,46 @@
|
|||||||
#include "goal/GoalNotReached.h"
|
#include "goal/GoalNotReached.h"
|
||||||
|
|
||||||
#include <Area2D.hpp>
|
#include <Area2D.hpp>
|
||||||
|
|
||||||
using namespace godot;
|
void alai::GoalNotReached::_register_methods()
|
||||||
|
|
||||||
|
|
||||||
void GoalNotReached::_register_methods()
|
|
||||||
{
|
{
|
||||||
register_method("_state_enter", &GoalNotReached::_state_enter);
|
register_method("_state_enter", &GoalNotReached::_state_enter);
|
||||||
register_method("_state_exit", &GoalNotReached::_state_exit);
|
register_method("_state_exit", &GoalNotReached::_state_exit);
|
||||||
register_method("_on_Goal_body_entered", &GoalNotReached::_on_Goal_body_entered);
|
register_method("_on_Goal_body_entered", &GoalNotReached::_on_Goal_body_entered);
|
||||||
}
|
}
|
||||||
|
|
||||||
GoalNotReached::GoalNotReached()
|
alai::GoalNotReached::GoalNotReached()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
GoalNotReached::~GoalNotReached()
|
alai::GoalNotReached::~GoalNotReached()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void GoalNotReached::_init()
|
void alai::GoalNotReached::_init()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GoalNotReached::_state_enter()
|
void alai::GoalNotReached::_state_enter()
|
||||||
{
|
{
|
||||||
animated_sprite = get_parent()->get_node<AnimatedSprite>("AnimatedSprite");
|
animated_sprite = get_parent()->get_node<godot::AnimatedSprite>("AnimatedSprite");
|
||||||
animated_sprite->set_animation("flagmove");
|
animated_sprite->set_animation("flagmove");
|
||||||
animated_sprite->play();
|
animated_sprite->play();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GoalNotReached::_state_exit()
|
void alai::GoalNotReached::_state_exit()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GoalNotReached::_on_Goal_body_entered(Node *node)
|
void alai::GoalNotReached::_on_Goal_body_entered(Node *node)
|
||||||
{
|
{
|
||||||
auto parent_node = get_parent();
|
auto parent_node = get_parent();
|
||||||
|
|
||||||
if (parent_node != nullptr)
|
if (parent_node != nullptr)
|
||||||
{
|
{
|
||||||
auto goal = Object::cast_to<Area2D>(parent_node);
|
auto goal = Object::cast_to<godot::Area2D>(parent_node);
|
||||||
goal->set_collision_mask_bit(0, false);
|
goal->set_collision_mask_bit(0, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
get_state_machine()->change("GoalReached");
|
get_state_machine()->change("GoalReached");
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,28 +1,27 @@
|
|||||||
#ifndef ALAI_GOAL_NOT_REACHED
|
#ifndef ALAI_GOAL_GOAL_NOT_REACHED_H
|
||||||
#define ALAI_GOAL_NOT_REACHED
|
#define ALAI_GOAL_GOAL_NOT_REACHED_H
|
||||||
|
|
||||||
#include "state_machine/State.h"
|
#include "state_machine/State.h"
|
||||||
|
|
||||||
#include <Godot.hpp>
|
|
||||||
#include <Node.hpp>
|
|
||||||
#include <AnimatedSprite.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.
|
* @brief This class controls what happens when the Coin is in the not collected state.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class GoalNotReached : public State
|
class GoalNotReached : public alai::State
|
||||||
{
|
{
|
||||||
GODOT_CLASS(GoalNotReached, State)
|
GODOT_CLASS(GoalNotReached, alai::State)
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* @brief The animated sprite of the Coin.
|
* @brief The animated sprite of the Coin.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
AnimatedSprite *animated_sprite;
|
godot::AnimatedSprite *animated_sprite;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
@ -70,7 +69,6 @@ namespace godot
|
|||||||
*/
|
*/
|
||||||
void _on_Goal_body_entered(Node *node);
|
void _on_Goal_body_entered(Node *node);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,36 +1,30 @@
|
|||||||
#include "goal/GoalReached.h"
|
#include "goal/GoalReached.h"
|
||||||
|
|
||||||
#include <Area2D.hpp>
|
#include <Area2D.hpp>
|
||||||
|
|
||||||
using namespace godot;
|
void alai::GoalReached::_register_methods()
|
||||||
|
|
||||||
void GoalReached::_register_methods()
|
|
||||||
{
|
{
|
||||||
register_method("_state_enter", &GoalReached::_state_enter);
|
register_method("_state_enter", &GoalReached::_state_enter);
|
||||||
register_method("_state_exit", &GoalReached::_state_exit);
|
register_method("_state_exit", &GoalReached::_state_exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
GoalReached::GoalReached()
|
alai::GoalReached::GoalReached()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
GoalReached::~GoalReached()
|
alai::GoalReached::~GoalReached()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void GoalReached::_init()
|
void alai::GoalReached::_init()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GoalReached::_state_enter()
|
void alai::GoalReached::_state_enter()
|
||||||
{
|
{
|
||||||
Godot::print("Flag touched");
|
godot::Godot::print("Flag touched");
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GoalReached::_state_exit()
|
void alai::GoalReached::_state_exit()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,28 +1,27 @@
|
|||||||
#ifndef ALAI_GOAL_REACHED
|
#ifndef ALAI_GOAL_GOAL_REACHED_H
|
||||||
#define ALAI_GOAL_REACHED
|
#define ALAI_GOAL_GOAL_REACHED_H
|
||||||
|
|
||||||
#include "state_machine/State.h"
|
#include "state_machine/State.h"
|
||||||
|
|
||||||
#include <Godot.hpp>
|
|
||||||
#include <Node.hpp>
|
|
||||||
#include <AnimatedSprite.hpp>
|
#include <AnimatedSprite.hpp>
|
||||||
|
#include <Godot.hpp>
|
||||||
|
|
||||||
namespace godot
|
namespace alai
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @brief This class controls what happens when the goal flag is in the reached state.
|
* @brief This class controls what happens when the goal flag is in the reached state.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class GoalReached : public State
|
class GoalReached : public alai::State
|
||||||
{
|
{
|
||||||
GODOT_CLASS(GoalReached, State)
|
GODOT_CLASS(GoalReached, alai::State)
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* @brief The animated sprite of the Coin.
|
* @brief The animated sprite of the Coin.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
AnimatedSprite *animated_sprite;
|
godot::AnimatedSprite *animated_sprite;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
@ -68,7 +67,6 @@ namespace godot
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -56,10 +56,10 @@ extern "C" void GDN_EXPORT godot_nativescript_init(void *handle)
|
|||||||
godot::register_class<alai::player::PlayerMove>();
|
godot::register_class<alai::player::PlayerMove>();
|
||||||
godot::register_class<alai::player::PlayerJump>();
|
godot::register_class<alai::player::PlayerJump>();
|
||||||
godot::register_class<alai::player::PlayerFall>();
|
godot::register_class<alai::player::PlayerFall>();
|
||||||
godot::register_class<godot::CoinNotCollected>();
|
godot::register_class<alai::CoinNotCollected>();
|
||||||
godot::register_class<godot::CoinCollected>();
|
godot::register_class<alai::CoinCollected>();
|
||||||
godot::register_class<godot::CoinCounter>();
|
godot::register_class<alai::CoinCounter>();
|
||||||
godot::register_class<godot::GoalReached>();
|
godot::register_class<alai::GoalReached>();
|
||||||
godot::register_class<godot::GoalNotReached>();
|
godot::register_class<alai::GoalNotReached>();
|
||||||
godot::register_class<godot::GameOverScreen>();
|
godot::register_class<alai::GameOverScreen>();
|
||||||
}
|
}
|
||||||
|
@ -1,54 +1,49 @@
|
|||||||
#include "gui/game_over/GameOverScreen.h"
|
#include "gui/game_over/GameOverScreen.h"
|
||||||
#include "Event.h"
|
#include "Event.h"
|
||||||
|
|
||||||
#include <Resource.hpp>
|
|
||||||
#include <Ref.hpp>
|
|
||||||
#include <Node.hpp>
|
#include <Node.hpp>
|
||||||
#include <SceneTree.hpp>
|
|
||||||
#include <PackedScene.hpp>
|
#include <PackedScene.hpp>
|
||||||
|
#include <Ref.hpp>
|
||||||
|
#include <Resource.hpp>
|
||||||
|
#include <SceneTree.hpp>
|
||||||
#include <Viewport.hpp>
|
#include <Viewport.hpp>
|
||||||
|
|
||||||
|
void alai::GameOverScreen::_register_methods()
|
||||||
using namespace godot;
|
|
||||||
|
|
||||||
void GameOverScreen::_register_methods()
|
|
||||||
{
|
{
|
||||||
register_method("_on_botonreiniciar_pressed", &GameOverScreen::_on_botonreiniciar_pressed);
|
register_method("_on_restart_button_pressed", &GameOverScreen::_on_restart_button_pressed);
|
||||||
register_method("_ready", &GameOverScreen::_ready);
|
register_method("_ready", &GameOverScreen::_ready);
|
||||||
register_method("connect_signal", &GameOverScreen::connect_signal);
|
register_method("connect_signal", &GameOverScreen::connect_signal);
|
||||||
register_method("_on_player_died", &GameOverScreen::_on_player_died);
|
register_method("_on_player_died", &GameOverScreen::_on_player_died);
|
||||||
}
|
}
|
||||||
|
|
||||||
GameOverScreen::GameOverScreen()
|
alai::GameOverScreen::GameOverScreen()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
GameOverScreen::~GameOverScreen()
|
alai::GameOverScreen::~GameOverScreen()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameOverScreen::_init()
|
void alai::GameOverScreen::_init()
|
||||||
{
|
{
|
||||||
_resource_loader = ResourceLoader::get_singleton();
|
_resource_loader = godot::ResourceLoader::get_singleton();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameOverScreen::_ready()
|
void alai::GameOverScreen::_ready()
|
||||||
{
|
{
|
||||||
connect_signal();
|
connect_signal();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameOverScreen::_on_botonreiniciar_pressed()
|
void alai::GameOverScreen::_on_restart_button_pressed()
|
||||||
{
|
{
|
||||||
if (_resource_loader->exists("res://levels/Prototype.tscn")) //CAMBIAR A DINAMICO
|
if (_resource_loader->exists("res://levels/Prototype.tscn"))
|
||||||
{
|
{
|
||||||
Ref<PackedScene> level_scene = _resource_loader->load("res://levels/Prototype.tscn");
|
godot::Ref<godot::PackedScene> level_scene = _resource_loader->load("res://levels/Prototype.tscn");
|
||||||
auto level = level_scene->instance();
|
auto level = level_scene->instance();
|
||||||
auto level_node = get_tree()->get_root()->get_node("Main")->find_node("Level");
|
auto level_node = get_tree()->get_root()->get_node("Main")->find_node("Level");
|
||||||
|
|
||||||
if (level_node != nullptr)
|
if (level_node != nullptr)
|
||||||
{
|
{
|
||||||
|
|
||||||
level_node->add_child(level);
|
level_node->add_child(level);
|
||||||
set_visible(false);
|
set_visible(false);
|
||||||
call_deferred("connect_signal");
|
call_deferred("connect_signal");
|
||||||
@ -57,16 +52,13 @@ void GameOverScreen::_on_botonreiniciar_pressed()
|
|||||||
{
|
{
|
||||||
WARN_PRINT("Node level not found!");
|
WARN_PRINT("Node level not found!");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
void alai::GameOverScreen::_on_player_died()
|
||||||
|
|
||||||
void GameOverScreen::_on_player_died() //eliminar nivel
|
|
||||||
{
|
{
|
||||||
auto event = get_node<alai::Event>("/root/Event");
|
auto event = get_node<alai::Event>("/root/Event");
|
||||||
event->disconnect("player_died", this, "_on_player_died");
|
event->disconnect("player_died", this, "_on_player_died");
|
||||||
Godot::print("player ded");
|
|
||||||
set_visible(true);
|
set_visible(true);
|
||||||
auto level_node = get_tree()->get_root()->get_node("Main")->find_node("Level");
|
auto level_node = get_tree()->get_root()->get_node("Main")->find_node("Level");
|
||||||
if (level_node != nullptr)
|
if (level_node != nullptr)
|
||||||
@ -74,6 +66,7 @@ void GameOverScreen::_on_player_died() //eliminar nivel
|
|||||||
auto child = level_node->get_child(0);
|
auto child = level_node->get_child(0);
|
||||||
if (child != nullptr)
|
if (child != nullptr)
|
||||||
{
|
{
|
||||||
|
// Delete the currently active level from the tree.
|
||||||
child->queue_free();
|
child->queue_free();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -85,14 +78,10 @@ void GameOverScreen::_on_player_died() //eliminar nivel
|
|||||||
{
|
{
|
||||||
WARN_PRINT("Node level not found!");
|
WARN_PRINT("Node level not found!");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameOverScreen::connect_signal()
|
void alai::GameOverScreen::connect_signal()
|
||||||
{
|
{
|
||||||
auto event = get_node<alai::Event>("/root/Event");
|
auto event = get_node<alai::Event>("/root/Event");
|
||||||
event->connect("player_died", this, "_on_player_died");
|
event->connect("player_died", this, "_on_player_died");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,23 +1,22 @@
|
|||||||
#ifndef ALAI_GAME_OVER_SCREEN_H
|
#ifndef ALAI_GAME_OVER_SCREEN_H
|
||||||
#define ALAI_GAME_OVER_SCREEN_H
|
#define ALAI_GAME_OVER_SCREEN_H
|
||||||
|
|
||||||
#include <Godot.hpp>
|
|
||||||
#include <CanvasLayer.hpp>
|
#include <CanvasLayer.hpp>
|
||||||
|
#include <Godot.hpp>
|
||||||
#include <ResourceLoader.hpp>
|
#include <ResourceLoader.hpp>
|
||||||
|
|
||||||
|
namespace alai
|
||||||
namespace godot
|
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @brief This class controls what happens when the Coin is in the collected .
|
* @brief This class controls what happens when the Coin is in the collected .
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class GameOverScreen : public CanvasLayer
|
class GameOverScreen : public godot::CanvasLayer
|
||||||
{
|
{
|
||||||
GODOT_CLASS(GameOverScreen, CanvasLayer)
|
GODOT_CLASS(GameOverScreen, godot::CanvasLayer)
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ResourceLoader *_resource_loader;
|
godot::ResourceLoader *_resource_loader;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
@ -52,11 +51,9 @@ namespace godot
|
|||||||
*/
|
*/
|
||||||
void _ready();
|
void _ready();
|
||||||
void _on_player_died();
|
void _on_player_died();
|
||||||
void _on_botonreiniciar_pressed();
|
void _on_restart_button_pressed();
|
||||||
void connect_signal();
|
void connect_signal();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -1,4 +1,5 @@
|
|||||||
#include "player/states/PlayerFall.h"
|
#include "player/states/PlayerFall.h"
|
||||||
|
|
||||||
#include "player/Player.h"
|
#include "player/Player.h"
|
||||||
|
|
||||||
void alai::player::PlayerFall::_register_methods()
|
void alai::player::PlayerFall::_register_methods()
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include "player/states/PlayerIdle.h"
|
#include "player/states/PlayerIdle.h"
|
||||||
|
|
||||||
#include "player/Player.h"
|
#include "player/Player.h"
|
||||||
|
|
||||||
void alai::player::PlayerIdle::_register_methods()
|
void alai::player::PlayerIdle::_register_methods()
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include "player/states/PlayerJump.h"
|
#include "player/states/PlayerJump.h"
|
||||||
|
|
||||||
#include "player/Player.h"
|
#include "player/Player.h"
|
||||||
|
|
||||||
#include <AudioStreamPlayer.hpp>
|
#include <AudioStreamPlayer.hpp>
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include "player/states/PlayerMove.h"
|
#include "player/states/PlayerMove.h"
|
||||||
|
|
||||||
#include "player/Player.h"
|
#include "player/Player.h"
|
||||||
|
|
||||||
void alai::player::PlayerMove::_register_methods()
|
void alai::player::PlayerMove::_register_methods()
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include "state_machine/StateMachine.h"
|
#include "state_machine/StateMachine.h"
|
||||||
|
|
||||||
#include "state_machine/State.h"
|
#include "state_machine/State.h"
|
||||||
|
|
||||||
void alai::StateMachine::_register_methods()
|
void alai::StateMachine::_register_methods()
|
||||||
|
Loading…
Reference in New Issue
Block a user