From 20e2fafcf4d21633b59d6e65c2ec12b62184f39a Mon Sep 17 00:00:00 2001 From: Martin Araneda Date: Tue, 24 May 2022 23:17:16 -0400 Subject: [PATCH] Coin state machines archives created but not functional --- godot/Collectables/Coin/Coin.tscn | 6 +-- src/Coin/CoinCollected.cpp | 0 src/Coin/CoinCollected.h | 0 src/Coin/CoinNotCollected.cpp | 39 ++++++++++++++++ src/Coin/CoinNotCollected.h | 76 +++++++++++++++++++++++++++++++ 5 files changed, 116 insertions(+), 5 deletions(-) create mode 100644 src/Coin/CoinCollected.cpp create mode 100644 src/Coin/CoinCollected.h create mode 100644 src/Coin/CoinNotCollected.cpp create mode 100644 src/Coin/CoinNotCollected.h diff --git a/godot/Collectables/Coin/Coin.tscn b/godot/Collectables/Coin/Coin.tscn index efbd18c..c4b9f4f 100644 --- a/godot/Collectables/Coin/Coin.tscn +++ b/godot/Collectables/Coin/Coin.tscn @@ -1,7 +1,6 @@ -[gd_scene load_steps=7 format=2] +[gd_scene load_steps=6 format=2] [ext_resource path="res://assets/coin.png" type="Texture" id=1] -[ext_resource path="res://Collectables/Coin/Coin.gd" type="Script" id=2] [sub_resource type="CircleShape2D" id=1] radius = 6.0 @@ -24,7 +23,6 @@ animations = [ { [node name="coin" type="Area2D"] collision_layer = 4 -script = ExtResource( 2 ) [node name="CollisionShape2D" type="CollisionShape2D" parent="."] position = Vector2( 9, 9 ) @@ -35,5 +33,3 @@ frames = SubResource( 4 ) frame = 1 playing = true centered = false - -[connection signal="body_entered" from="." to="." method="_on_coin_body_entered"] diff --git a/src/Coin/CoinCollected.cpp b/src/Coin/CoinCollected.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/Coin/CoinCollected.h b/src/Coin/CoinCollected.h new file mode 100644 index 0000000..e69de29 diff --git a/src/Coin/CoinNotCollected.cpp b/src/Coin/CoinNotCollected.cpp new file mode 100644 index 0000000..92d702e --- /dev/null +++ b/src/Coin/CoinNotCollected.cpp @@ -0,0 +1,39 @@ +#include "player/states/CoinNotCollected.h" + +using namespace godot; + +void CoinNotCollected::_register_methods() +{ + register_method("_state_enter", &CoinNotCollected::_state_enter); + register_method("_state_exit", &CoinNotCollected::_state_exit); + register_method("_physics_process", &CoinNotCollected::_physics_process); +} + +CoinNotCollected::CoinNotCollected() +{ +} + +CoinNotCollected::~CoinNotCollected() +{ +} + +void CoinNotCollected::_init() +{ + +} + +void CoinNotCollected::_state_enter() +{ + animated_sprite = get_parent()->get_node("AnimatedSprite"); + animated_sprite->stop(); + animated_sprite->set_animation("idle"); +} + +void CoinNotCollected::_state_exit() +{ +} + +void CoinNotCollected::_physics_process(float delta) +{ + +} diff --git a/src/Coin/CoinNotCollected.h b/src/Coin/CoinNotCollected.h new file mode 100644 index 0000000..d634de2 --- /dev/null +++ b/src/Coin/CoinNotCollected.h @@ -0,0 +1,76 @@ +#ifndef JUEGO_COIN_COINNOTCOLLECTED +#define JJUEGO_COIN_COINNOTCOLLECTED + +#include "state_machine/State.h" + +#include +#include +#include + +namespace godot +{ + /** + * @brief This class controls what happens when the Coin is in the not collected state. + * + */ + class CoinNotCollected : public State + { + GODOT_CLASS(CoinNotCollected, 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 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 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 The physics processed every delta time. + * + * @param[in] delta The time since the method was last run. + */ + void _physics_process(float delta); + }; + +} + +#endif