From 57289dcb8f8260eb1097cf161e2d459e7da86dd9 Mon Sep 17 00:00:00 2001 From: Martin Araneda Date: Fri, 20 May 2022 12:50:47 -0400 Subject: [PATCH 01/28] Coin added to prototype --- godot/Collectables/Coin/Coin.tscn | 31 +++++++++++++++++++++++++++++++ godot/Main.tscn | 2 +- godot/levels/Prototype.tscn | 11 ++++++++++- godot/project.godot | 1 + 4 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 godot/Collectables/Coin/Coin.tscn diff --git a/godot/Collectables/Coin/Coin.tscn b/godot/Collectables/Coin/Coin.tscn new file mode 100644 index 0000000..d627422 --- /dev/null +++ b/godot/Collectables/Coin/Coin.tscn @@ -0,0 +1,31 @@ +[gd_scene load_steps=6 format=2] + +[ext_resource path="res://assets/coin.png" type="Texture" id=1] + +[sub_resource type="CircleShape2D" id=1] +radius = 6.0 + +[sub_resource type="AtlasTexture" id=2] +atlas = ExtResource( 1 ) +region = Rect2( 0, 0, 18, 18 ) + +[sub_resource type="AtlasTexture" id=3] +atlas = ExtResource( 1 ) +region = Rect2( 18, 0, 18, 18 ) + +[sub_resource type="SpriteFrames" id=4] +animations = [ { +"frames": [ SubResource( 2 ), SubResource( 3 ) ], +"loop": true, +"name": "default", +"speed": 5.0 +} ] + +[node name="coin" type="Area2D"] + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +shape = SubResource( 1 ) + +[node name="AnimatedSprite" type="AnimatedSprite" parent="."] +frames = SubResource( 4 ) +playing = true diff --git a/godot/Main.tscn b/godot/Main.tscn index a9c8579..0b5ed2e 100644 --- a/godot/Main.tscn +++ b/godot/Main.tscn @@ -1,7 +1,7 @@ [gd_scene load_steps=3 format=2] [ext_resource path="res://Main.gdns" type="Script" id=1] -[ext_resource path="res://levels/Level2.tscn" type="PackedScene" id=2] +[ext_resource path="res://levels/Prototype.tscn" type="PackedScene" id=2] [node name="Main" type="Node"] script = ExtResource( 1 ) diff --git a/godot/levels/Prototype.tscn b/godot/levels/Prototype.tscn index b18e1ae..8b60c05 100644 --- a/godot/levels/Prototype.tscn +++ b/godot/levels/Prototype.tscn @@ -1,13 +1,16 @@ -[gd_scene load_steps=5 format=2] +[gd_scene load_steps=6 format=2] [ext_resource path="res://CameraLimit.gdns" type="Script" id=1] [ext_resource path="res://characters/player/Player.tscn" type="PackedScene" id=2] [ext_resource path="res://levels/Prototype.tmx" type="PackedScene" id=3] [ext_resource path="res://assets/backgrounds/mountains.png" type="Texture" id=4] +[ext_resource path="res://Collectables/Coin/Coin.tscn" type="PackedScene" id=5] [node name="Prototype" type="Node2D"] [node name="Player" parent="." instance=ExtResource( 2 )] +collision_layer = 5 +collision_mask = 6 [node name="Camera2D" type="Camera2D" parent="Player"] current = true @@ -39,3 +42,9 @@ centered = false [node name="Prototype" parent="Map" instance=ExtResource( 3 )] script = ExtResource( 1 ) + +[node name="coin" parent="." instance=ExtResource( 5 )] +position = Vector2( 72, 456 ) + +[node name="coin2" parent="." instance=ExtResource( 5 )] +position = Vector2( 240, 456 ) diff --git a/godot/project.godot b/godot/project.godot index 52b2be8..4ff88a6 100644 --- a/godot/project.godot +++ b/godot/project.godot @@ -95,6 +95,7 @@ right={ 2d_physics/layer_1="Player" 2d_physics/layer_2="Tiles" +2d_physics/layer_3="Collectables" [physics] From a079d8aa37fec7b26d7f292d53e7d58cf02ef6a1 Mon Sep 17 00:00:00 2001 From: Martin Araneda Date: Tue, 24 May 2022 15:23:29 -0400 Subject: [PATCH 02/28] changes to coin --- godot/Collectables/Coin/Coin.tscn | 10 +++++++++- godot/characters/player/Player.tscn | 2 +- godot/levels/Prototype.tscn | 5 ++--- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/godot/Collectables/Coin/Coin.tscn b/godot/Collectables/Coin/Coin.tscn index d627422..efbd18c 100644 --- a/godot/Collectables/Coin/Coin.tscn +++ b/godot/Collectables/Coin/Coin.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=6 format=2] +[gd_scene load_steps=7 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 @@ -22,10 +23,17 @@ animations = [ { } ] [node name="coin" type="Area2D"] +collision_layer = 4 +script = ExtResource( 2 ) [node name="CollisionShape2D" type="CollisionShape2D" parent="."] +position = Vector2( 9, 9 ) shape = SubResource( 1 ) [node name="AnimatedSprite" type="AnimatedSprite" parent="."] frames = SubResource( 4 ) +frame = 1 playing = true +centered = false + +[connection signal="body_entered" from="." to="." method="_on_coin_body_entered"] diff --git a/godot/characters/player/Player.tscn b/godot/characters/player/Player.tscn index 858efb3..6edccfe 100644 --- a/godot/characters/player/Player.tscn +++ b/godot/characters/player/Player.tscn @@ -12,7 +12,7 @@ extents = Vector2( 7, 12 ) [node name="Player" type="KinematicBody2D"] -collision_mask = 2 +collision_mask = 6 script = ExtResource( 5 ) [node name="AnimatedSprite" type="AnimatedSprite" parent="."] diff --git a/godot/levels/Prototype.tscn b/godot/levels/Prototype.tscn index 8b60c05..d62a938 100644 --- a/godot/levels/Prototype.tscn +++ b/godot/levels/Prototype.tscn @@ -10,7 +10,6 @@ [node name="Player" parent="." instance=ExtResource( 2 )] collision_layer = 5 -collision_mask = 6 [node name="Camera2D" type="Camera2D" parent="Player"] current = true @@ -44,7 +43,7 @@ centered = false script = ExtResource( 1 ) [node name="coin" parent="." instance=ExtResource( 5 )] -position = Vector2( 72, 456 ) +position = Vector2( 72, 450 ) [node name="coin2" parent="." instance=ExtResource( 5 )] -position = Vector2( 240, 456 ) +position = Vector2( 234, 450 ) From 20e2fafcf4d21633b59d6e65c2ec12b62184f39a Mon Sep 17 00:00:00 2001 From: Martin Araneda Date: Tue, 24 May 2022 23:17:16 -0400 Subject: [PATCH 03/28] 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 From 5fe9e3340af57ff911084a4c3b024e739075ee36 Mon Sep 17 00:00:00 2001 From: Martin Araneda Date: Mon, 6 Jun 2022 20:59:51 -0400 Subject: [PATCH 04/28] Some fixes on Coin files --- godot/Collectables/Coin/Coin.tscn | 4 ++-- src/Coin/CoinNotCollected.cpp | 10 ++++++---- src/Coin/CoinNotCollected.h | 2 +- src/godot.cpp | 2 ++ 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/godot/Collectables/Coin/Coin.tscn b/godot/Collectables/Coin/Coin.tscn index c4b9f4f..d496232 100644 --- a/godot/Collectables/Coin/Coin.tscn +++ b/godot/Collectables/Coin/Coin.tscn @@ -17,7 +17,7 @@ region = Rect2( 18, 0, 18, 18 ) animations = [ { "frames": [ SubResource( 2 ), SubResource( 3 ) ], "loop": true, -"name": "default", +"name": "spin", "speed": 5.0 } ] @@ -30,6 +30,6 @@ shape = SubResource( 1 ) [node name="AnimatedSprite" type="AnimatedSprite" parent="."] frames = SubResource( 4 ) -frame = 1 +animation = "spin" playing = true centered = false diff --git a/src/Coin/CoinNotCollected.cpp b/src/Coin/CoinNotCollected.cpp index 92d702e..41a4732 100644 --- a/src/Coin/CoinNotCollected.cpp +++ b/src/Coin/CoinNotCollected.cpp @@ -1,4 +1,4 @@ -#include "player/states/CoinNotCollected.h" +#include "Coin/CoinNotCollected.h" using namespace godot; @@ -25,15 +25,17 @@ void CoinNotCollected::_init() void CoinNotCollected::_state_enter() { animated_sprite = get_parent()->get_node("AnimatedSprite"); - animated_sprite->stop(); - animated_sprite->set_animation("idle"); + animated_sprite->set_animation("spin"); + animated_sprite->play(); } void CoinNotCollected::_state_exit() { + } void CoinNotCollected::_physics_process(float delta) { - + } + diff --git a/src/Coin/CoinNotCollected.h b/src/Coin/CoinNotCollected.h index d634de2..ab4488f 100644 --- a/src/Coin/CoinNotCollected.h +++ b/src/Coin/CoinNotCollected.h @@ -1,5 +1,5 @@ #ifndef JUEGO_COIN_COINNOTCOLLECTED -#define JJUEGO_COIN_COINNOTCOLLECTED +#define JUEGO_COIN_COINNOTCOLLECTED #include "state_machine/State.h" diff --git a/src/godot.cpp b/src/godot.cpp index 1c56d09..481a009 100644 --- a/src/godot.cpp +++ b/src/godot.cpp @@ -9,6 +9,7 @@ #include "player/states/PlayerMove.h" #include "player/states/PlayerJump.h" #include "player/states/PlayerFall.h" +#include "Coin/CoinNotCollected.h" using namespace godot; @@ -49,4 +50,5 @@ extern "C" void GDN_EXPORT godot_nativescript_init(void *handle) register_class(); register_class(); register_class(); + register_class(); } From 876206c39d25f8d1b775ae0a78f9d460416cf8a6 Mon Sep 17 00:00:00 2001 From: Martin Araneda Date: Sat, 11 Jun 2022 00:26:11 -0400 Subject: [PATCH 05/28] Added two states, collected and not collected --- godot/characters/player/Player.tscn | 2 +- godot/collectables/coin/Coin.tscn | 71 ++++++++++++++++++ .../coin/states/CoinCollected.gdns | 8 ++ .../coin/states/CoinNotCollected.gdns | 8 ++ godot/levels/Prototype.tscn | 2 +- src/Coin/CoinCollected.cpp | 0 src/Coin/CoinCollected.h | 0 src/coin/CoinCollected.cpp | 49 ++++++++++++ src/coin/CoinCollected.h | 75 +++++++++++++++++++ src/{Coin => coin}/CoinNotCollected.cpp | 19 ++++- src/{Coin => coin}/CoinNotCollected.h | 10 +-- src/godot.cpp | 6 +- 12 files changed, 238 insertions(+), 12 deletions(-) create mode 100644 godot/collectables/coin/Coin.tscn create mode 100644 godot/collectables/coin/states/CoinCollected.gdns create mode 100644 godot/collectables/coin/states/CoinNotCollected.gdns delete mode 100644 src/Coin/CoinCollected.cpp delete mode 100644 src/Coin/CoinCollected.h create mode 100644 src/coin/CoinCollected.cpp create mode 100644 src/coin/CoinCollected.h rename src/{Coin => coin}/CoinNotCollected.cpp (55%) rename src/{Coin => coin}/CoinNotCollected.h (87%) diff --git a/godot/characters/player/Player.tscn b/godot/characters/player/Player.tscn index 6edccfe..858efb3 100644 --- a/godot/characters/player/Player.tscn +++ b/godot/characters/player/Player.tscn @@ -12,7 +12,7 @@ extents = Vector2( 7, 12 ) [node name="Player" type="KinematicBody2D"] -collision_mask = 6 +collision_mask = 2 script = ExtResource( 5 ) [node name="AnimatedSprite" type="AnimatedSprite" parent="."] diff --git a/godot/collectables/coin/Coin.tscn b/godot/collectables/coin/Coin.tscn new file mode 100644 index 0000000..6d52bb0 --- /dev/null +++ b/godot/collectables/coin/Coin.tscn @@ -0,0 +1,71 @@ +[gd_scene load_steps=10 format=2] + +[ext_resource path="res://assets/coin.png" type="Texture" id=1] +[ext_resource path="res://state_machine/StateMachine.gdns" type="Script" id=2] +[ext_resource path="res://collectables/coin/states/CoinNotCollected.gdns" type="Script" id=3] +[ext_resource path="res://collectables/coin/states/CoinCollected.gdns" type="Script" id=4] + +[sub_resource type="CircleShape2D" id=1] +radius = 6.0 + +[sub_resource type="AtlasTexture" id=2] +atlas = ExtResource( 1 ) +region = Rect2( 0, 0, 18, 18 ) + +[sub_resource type="AtlasTexture" id=3] +atlas = ExtResource( 1 ) +region = Rect2( 18, 0, 18, 18 ) + +[sub_resource type="SpriteFrames" id=4] +animations = [ { +"frames": [ SubResource( 2 ), SubResource( 3 ) ], +"loop": true, +"name": "spin", +"speed": 5.0 +} ] + +[sub_resource type="Animation" id=5] +resource_name = "jump" +length = 0.4 +tracks/0/type = "value" +tracks/0/path = NodePath("AnimatedSprite:position") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/keys = { +"times": PoolRealArray( 0, 0.2, 0.4 ), +"transitions": PoolRealArray( 1, 1, 1 ), +"update": 0, +"values": [ Vector2( 0, 0 ), Vector2( 0, -20 ), Vector2( 0, 0 ) ] +} + +[node name="Coin" type="Area2D"] +collision_layer = 4 + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +position = Vector2( 9, 9 ) +shape = SubResource( 1 ) + +[node name="AnimatedSprite" type="AnimatedSprite" parent="."] +frames = SubResource( 4 ) +animation = "spin" +frame = 1 +playing = true +centered = false + +[node name="StateMachine" type="Node" parent="."] +script = ExtResource( 2 ) +default_state = "CoinNotCollected" + +[node name="CoinNotCollected" type="Node" parent="StateMachine"] +script = ExtResource( 3 ) + +[node name="CoinCollected" type="Node" parent="StateMachine"] +script = ExtResource( 4 ) + +[node name="AnimationPlayer" type="AnimationPlayer" parent="."] +anims/jump = SubResource( 5 ) + +[connection signal="body_entered" from="." to="StateMachine/CoinNotCollected" method="_on_body_entered" flags=6] +[connection signal="animation_finished" from="AnimationPlayer" to="StateMachine/CoinCollected" method="_on_animation_finished" flags=6] diff --git a/godot/collectables/coin/states/CoinCollected.gdns b/godot/collectables/coin/states/CoinCollected.gdns new file mode 100644 index 0000000..4465239 --- /dev/null +++ b/godot/collectables/coin/states/CoinCollected.gdns @@ -0,0 +1,8 @@ +[gd_resource type="NativeScript" load_steps=2 format=2] + +[ext_resource path="res://gdnative/alai.tres" type="GDNativeLibrary" id=1] + +[resource] +resource_name = "CoinCollected" +class_name = "CoinCollected" +library = ExtResource( 1 ) diff --git a/godot/collectables/coin/states/CoinNotCollected.gdns b/godot/collectables/coin/states/CoinNotCollected.gdns new file mode 100644 index 0000000..acc55d8 --- /dev/null +++ b/godot/collectables/coin/states/CoinNotCollected.gdns @@ -0,0 +1,8 @@ +[gd_resource type="NativeScript" load_steps=2 format=2] + +[ext_resource path="res://gdnative/alai.tres" type="GDNativeLibrary" id=1] + +[resource] +resource_name = "CoinNotCollected" +class_name = "CoinNotCollected" +library = ExtResource( 1 ) diff --git a/godot/levels/Prototype.tscn b/godot/levels/Prototype.tscn index d62a938..e95ba6f 100644 --- a/godot/levels/Prototype.tscn +++ b/godot/levels/Prototype.tscn @@ -4,7 +4,7 @@ [ext_resource path="res://characters/player/Player.tscn" type="PackedScene" id=2] [ext_resource path="res://levels/Prototype.tmx" type="PackedScene" id=3] [ext_resource path="res://assets/backgrounds/mountains.png" type="Texture" id=4] -[ext_resource path="res://Collectables/Coin/Coin.tscn" type="PackedScene" id=5] +[ext_resource path="res://collectables/coin/Coin.tscn" type="PackedScene" id=5] [node name="Prototype" type="Node2D"] diff --git a/src/Coin/CoinCollected.cpp b/src/Coin/CoinCollected.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/src/Coin/CoinCollected.h b/src/Coin/CoinCollected.h deleted file mode 100644 index e69de29..0000000 diff --git a/src/coin/CoinCollected.cpp b/src/coin/CoinCollected.cpp new file mode 100644 index 0000000..65c4a51 --- /dev/null +++ b/src/coin/CoinCollected.cpp @@ -0,0 +1,49 @@ +#include "coin/CoinCollected.h" +#include + +using namespace godot; + +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); +} + +CoinCollected::CoinCollected() +{ +} + +CoinCollected::~CoinCollected() +{ +} + +void CoinCollected::_init() +{ + +} + +void CoinCollected::_state_enter() +{ + + auto node = get_parent()->find_node("AnimationPlayer"); + + if (node != nullptr) + { + auto animation_player = Object::cast_to(node); + animation_player->play("jump"); + } +} + +void CoinCollected::_state_exit() +{ + +} + +void CoinCollected::_on_animation_finished(String anim_name) +{ + this->get_parent()->queue_free(); + +} + + diff --git a/src/coin/CoinCollected.h b/src/coin/CoinCollected.h new file mode 100644 index 0000000..0e8f359 --- /dev/null +++ b/src/coin/CoinCollected.h @@ -0,0 +1,75 @@ +#ifndef ALAI_COIN_COLLECTED +#define ALAI_COIN_COLLECTED + +#include "state_machine/State.h" + +#include +#include +#include + +namespace godot +{ + /** + * @brief This class controls what happens when the Coin is in the collected state. + * + */ + class CoinCollected : public State + { + GODOT_CLASS(CoinCollected, 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 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 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. + * + */ + void _on_animation_finished(String anim_name); + }; + +} + +#endif diff --git a/src/Coin/CoinNotCollected.cpp b/src/coin/CoinNotCollected.cpp similarity index 55% rename from src/Coin/CoinNotCollected.cpp rename to src/coin/CoinNotCollected.cpp index 41a4732..beb34e2 100644 --- a/src/Coin/CoinNotCollected.cpp +++ b/src/coin/CoinNotCollected.cpp @@ -1,4 +1,5 @@ -#include "Coin/CoinNotCollected.h" +#include "coin/CoinNotCollected.h" +#include using namespace godot; @@ -6,7 +7,7 @@ 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); + register_method("_on_body_entered", &CoinNotCollected::_on_body_entered); } CoinNotCollected::CoinNotCollected() @@ -34,8 +35,20 @@ void CoinNotCollected::_state_exit() } -void CoinNotCollected::_physics_process(float delta) +void CoinNotCollected::_on_body_entered(Node *node) { + Godot::print("Coin touched"); + auto parent_node = get_parent(); + if (parent_node != nullptr) + { + auto coin = Object::cast_to(parent_node); + coin->set_collision_mask_bit(0, false); + } + get_state_machine()->change("CoinCollected"); + + } + + diff --git a/src/Coin/CoinNotCollected.h b/src/coin/CoinNotCollected.h similarity index 87% rename from src/Coin/CoinNotCollected.h rename to src/coin/CoinNotCollected.h index ab4488f..4739cf0 100644 --- a/src/Coin/CoinNotCollected.h +++ b/src/coin/CoinNotCollected.h @@ -1,5 +1,5 @@ -#ifndef JUEGO_COIN_COINNOTCOLLECTED -#define JUEGO_COIN_COINNOTCOLLECTED +#ifndef ALAI_COIN_NOT_COLLECTED +#define ALAI_COIN_NOT_COLLECTED #include "state_machine/State.h" @@ -64,11 +64,11 @@ namespace godot void _state_exit(); /** - * @brief The physics processed every delta time. + * @brief Method called on body entered. * - * @param[in] delta The time since the method was last run. + * @param[in] node Node interacting with whoever */ - void _physics_process(float delta); + void _on_body_entered(Node *node); }; } diff --git a/src/godot.cpp b/src/godot.cpp index 481a009..2e5d9a6 100644 --- a/src/godot.cpp +++ b/src/godot.cpp @@ -9,7 +9,8 @@ #include "player/states/PlayerMove.h" #include "player/states/PlayerJump.h" #include "player/states/PlayerFall.h" -#include "Coin/CoinNotCollected.h" +#include "coin/CoinNotCollected.h" +#include "coin/CoinCollected.h" using namespace godot; @@ -50,5 +51,6 @@ extern "C" void GDN_EXPORT godot_nativescript_init(void *handle) register_class(); register_class(); register_class(); - register_class(); + register_class(); + register_class(); } From a439748a344f57e1585b690bd2db443e42e81843 Mon Sep 17 00:00:00 2001 From: Martin Araneda Date: Tue, 21 Jun 2022 23:26:43 -0400 Subject: [PATCH 06/28] On-screen coin counter state machine archives added --- src/coin/CoinCounter.cpp | 0 src/coin/CoinCounter.h | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/coin/CoinCounter.cpp create mode 100644 src/coin/CoinCounter.h diff --git a/src/coin/CoinCounter.cpp b/src/coin/CoinCounter.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/coin/CoinCounter.h b/src/coin/CoinCounter.h new file mode 100644 index 0000000..e69de29 From 3a5877777343bc1e69f8eadaaa12bfba8541f4b1 Mon Sep 17 00:00:00 2001 From: Martin Araneda Date: Sat, 25 Jun 2022 20:54:47 -0400 Subject: [PATCH 07/28] coin counter method created --- godot/levels/Prototype.tscn | 38 +++++++++++++++++- src/coin/CoinCounter.cpp | 40 +++++++++++++++++++ src/coin/CoinCounter.h | 77 +++++++++++++++++++++++++++++++++++++ 3 files changed, 154 insertions(+), 1 deletion(-) diff --git a/godot/levels/Prototype.tscn b/godot/levels/Prototype.tscn index e95ba6f..b6f8afb 100644 --- a/godot/levels/Prototype.tscn +++ b/godot/levels/Prototype.tscn @@ -1,10 +1,14 @@ -[gd_scene load_steps=6 format=2] +[gd_scene load_steps=8 format=2] [ext_resource path="res://CameraLimit.gdns" type="Script" id=1] [ext_resource path="res://characters/player/Player.tscn" type="PackedScene" id=2] [ext_resource path="res://levels/Prototype.tmx" type="PackedScene" id=3] [ext_resource path="res://assets/backgrounds/mountains.png" type="Texture" id=4] [ext_resource path="res://collectables/coin/Coin.tscn" type="PackedScene" id=5] +[ext_resource path="res://assets/coin.png" type="Texture" id=6] + +[sub_resource type="StyleBoxFlat" id=1] +bg_color = Color( 0, 0, 0, 0.541176 ) [node name="Prototype" type="Node2D"] @@ -47,3 +51,35 @@ position = Vector2( 72, 450 ) [node name="coin2" parent="." instance=ExtResource( 5 )] position = Vector2( 234, 450 ) + +[node name="CoinHUD" type="CanvasLayer" parent="."] + +[node name="Panel" type="Panel" parent="CoinHUD"] +margin_left = 144.0 +margin_top = 18.0 +margin_right = 288.0 +margin_bottom = 54.0 +custom_styles/panel = SubResource( 1 ) + +[node name="TextureRect" type="TextureRect" parent="CoinHUD"] +margin_left = 144.0 +margin_top = 18.0 +margin_right = 184.0 +margin_bottom = 58.0 +texture = ExtResource( 6 ) + +[node name="Label" type="Label" parent="CoinHUD"] +margin_left = 198.0 +margin_top = 18.0 +margin_right = 238.0 +margin_bottom = 36.0 +text = "X" + +[node name="Coins" type="Label" parent="CoinHUD"] +margin_left = 216.0 +margin_top = 18.0 +margin_right = 256.0 +margin_bottom = 32.0 +text = "##" + +[connection signal="ready" from="CoinHUD/Coins" to="Player" method="_on_CoinHUD_ready"] diff --git a/src/coin/CoinCounter.cpp b/src/coin/CoinCounter.cpp index e69de29..e50810f 100644 --- a/src/coin/CoinCounter.cpp +++ b/src/coin/CoinCounter.cpp @@ -0,0 +1,40 @@ +#include "coin/CoinCounter.h" +#include + +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); +} + +CoinCounter::CoinCounter() +{ +} + +CoinCounter::~CoinCounter() +{ +} + +void CoinCounter::_init() +{ + +} + +void CoinCounter::_state_enter() +{ + +} + +void CoinCounter::_state_exit() +{ + +} + +void CoinCounter::_on_CoinHUD_ready() +{ + + +} diff --git a/src/coin/CoinCounter.h b/src/coin/CoinCounter.h index e69de29..b194fb9 100644 --- a/src/coin/CoinCounter.h +++ b/src/coin/CoinCounter.h @@ -0,0 +1,77 @@ +#ifndef ALAI_COIN_COUNTER +#define ALAI_COIN_COUNTER + +#include "state_machine/State.h" + +#include +#include +#include + +namespace godot +{ + /** + * @brief This class controls what happens when the Coin is in the collected state. + * + */ + class CoinCounter : public State + { + GODOT_CLASS(CoinCounter, 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 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 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. + * + */ + + void _on_CoinHUD_ready(); + + }; + +} + +#endif From b25e1f040c8eecc6a3df763affaf669145eaf6b7 Mon Sep 17 00:00:00 2001 From: Martin Araneda Date: Fri, 15 Jul 2022 23:04:06 -0400 Subject: [PATCH 08/28] minor changes --- godot/levels/Prototype.tscn | 2 +- src/coin/CoinCollected.cpp | 6 +++++- src/coin/CoinCounter.cpp | 5 ++++- src/coin/CoinNotCollected.cpp | 2 ++ 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/godot/levels/Prototype.tscn b/godot/levels/Prototype.tscn index b6f8afb..b1f265c 100644 --- a/godot/levels/Prototype.tscn +++ b/godot/levels/Prototype.tscn @@ -82,4 +82,4 @@ margin_right = 256.0 margin_bottom = 32.0 text = "##" -[connection signal="ready" from="CoinHUD/Coins" to="Player" method="_on_CoinHUD_ready"] +[connection signal="ready" from="CoinHUD" to="Player" method="_on_CoinHUD_ready"] diff --git a/src/coin/CoinCollected.cpp b/src/coin/CoinCollected.cpp index 65c4a51..7f1f2f2 100644 --- a/src/coin/CoinCollected.cpp +++ b/src/coin/CoinCollected.cpp @@ -2,6 +2,7 @@ #include using namespace godot; +int coin = 0; void CoinCollected::_register_methods() { @@ -25,7 +26,7 @@ void CoinCollected::_init() void CoinCollected::_state_enter() { - + coin = coin + 1; auto node = get_parent()->find_node("AnimationPlayer"); if (node != nullptr) @@ -33,6 +34,7 @@ void CoinCollected::_state_enter() auto animation_player = Object::cast_to(node); animation_player->play("jump"); } + } void CoinCollected::_state_exit() @@ -44,6 +46,8 @@ void CoinCollected::_on_animation_finished(String anim_name) { this->get_parent()->queue_free(); + // get_state_machine()->change("CoinCounter"); + } diff --git a/src/coin/CoinCounter.cpp b/src/coin/CoinCounter.cpp index e50810f..365453b 100644 --- a/src/coin/CoinCounter.cpp +++ b/src/coin/CoinCounter.cpp @@ -3,6 +3,7 @@ using namespace godot; + void CoinCounter::_register_methods() { register_method("_state_enter", &CoinCounter::_state_enter); @@ -35,6 +36,8 @@ void CoinCounter::_state_exit() void CoinCounter::_on_CoinHUD_ready() { - + get_node("Coins").text() = "hola"; } + + diff --git a/src/coin/CoinNotCollected.cpp b/src/coin/CoinNotCollected.cpp index beb34e2..cb7487b 100644 --- a/src/coin/CoinNotCollected.cpp +++ b/src/coin/CoinNotCollected.cpp @@ -3,6 +3,7 @@ using namespace godot; + void CoinNotCollected::_register_methods() { register_method("_state_enter", &CoinNotCollected::_state_enter); @@ -45,6 +46,7 @@ void CoinNotCollected::_on_body_entered(Node *node) auto coin = Object::cast_to(parent_node); coin->set_collision_mask_bit(0, false); } + get_state_machine()->change("CoinCollected"); From b9ff12dab300bb48909b01989da6d36368cf4f49 Mon Sep 17 00:00:00 2001 From: Martin Araneda Date: Sat, 16 Jul 2022 18:36:38 -0400 Subject: [PATCH 09/28] Finished coin counter --- godot/Collectables/Coin/Coin.tscn | 35 ------------------ godot/hud/coin/Counter.gdns | 8 +++++ godot/levels/Prototype.tscn | 59 +++++++++++++++++++++---------- src/coin/CoinCollected.cpp | 5 +-- src/coin/CoinCounter.cpp | 40 +++++++++++---------- src/coin/CoinCounter.h | 32 +++++------------ src/godot.cpp | 2 ++ 7 files changed, 84 insertions(+), 97 deletions(-) delete mode 100644 godot/Collectables/Coin/Coin.tscn create mode 100644 godot/hud/coin/Counter.gdns diff --git a/godot/Collectables/Coin/Coin.tscn b/godot/Collectables/Coin/Coin.tscn deleted file mode 100644 index d496232..0000000 --- a/godot/Collectables/Coin/Coin.tscn +++ /dev/null @@ -1,35 +0,0 @@ -[gd_scene load_steps=6 format=2] - -[ext_resource path="res://assets/coin.png" type="Texture" id=1] - -[sub_resource type="CircleShape2D" id=1] -radius = 6.0 - -[sub_resource type="AtlasTexture" id=2] -atlas = ExtResource( 1 ) -region = Rect2( 0, 0, 18, 18 ) - -[sub_resource type="AtlasTexture" id=3] -atlas = ExtResource( 1 ) -region = Rect2( 18, 0, 18, 18 ) - -[sub_resource type="SpriteFrames" id=4] -animations = [ { -"frames": [ SubResource( 2 ), SubResource( 3 ) ], -"loop": true, -"name": "spin", -"speed": 5.0 -} ] - -[node name="coin" type="Area2D"] -collision_layer = 4 - -[node name="CollisionShape2D" type="CollisionShape2D" parent="."] -position = Vector2( 9, 9 ) -shape = SubResource( 1 ) - -[node name="AnimatedSprite" type="AnimatedSprite" parent="."] -frames = SubResource( 4 ) -animation = "spin" -playing = true -centered = false diff --git a/godot/hud/coin/Counter.gdns b/godot/hud/coin/Counter.gdns new file mode 100644 index 0000000..622052d --- /dev/null +++ b/godot/hud/coin/Counter.gdns @@ -0,0 +1,8 @@ +[gd_resource type="NativeScript" load_steps=2 format=2] + +[ext_resource path="res://gdnative/alai.tres" type="GDNativeLibrary" id=1] + +[resource] +resource_name = "CoinCounter" +class_name = "CoinCounter" +library = ExtResource( 1 ) diff --git a/godot/levels/Prototype.tscn b/godot/levels/Prototype.tscn index b1f265c..e3c4608 100644 --- a/godot/levels/Prototype.tscn +++ b/godot/levels/Prototype.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=8 format=2] +[gd_scene load_steps=12 format=2] [ext_resource path="res://CameraLimit.gdns" type="Script" id=1] [ext_resource path="res://characters/player/Player.tscn" type="PackedScene" id=2] @@ -6,10 +6,27 @@ [ext_resource path="res://assets/backgrounds/mountains.png" type="Texture" id=4] [ext_resource path="res://collectables/coin/Coin.tscn" type="PackedScene" id=5] [ext_resource path="res://assets/coin.png" type="Texture" id=6] +[ext_resource path="res://hud/coin/Counter.gdns" type="Script" id=7] [sub_resource type="StyleBoxFlat" id=1] bg_color = Color( 0, 0, 0, 0.541176 ) +[sub_resource type="AtlasTexture" id=2] +atlas = ExtResource( 6 ) +region = Rect2( 0, 0, 18, 18 ) + +[sub_resource type="AtlasTexture" id=3] +atlas = ExtResource( 6 ) +region = Rect2( 18, 0, 18, 18 ) + +[sub_resource type="SpriteFrames" id=4] +animations = [ { +"frames": [ SubResource( 2 ), SubResource( 3 ) ], +"loop": true, +"name": "spin", +"speed": 5.0 +} ] + [node name="Prototype" type="Node2D"] [node name="Player" parent="." instance=ExtResource( 2 )] @@ -46,12 +63,6 @@ centered = false [node name="Prototype" parent="Map" instance=ExtResource( 3 )] script = ExtResource( 1 ) -[node name="coin" parent="." instance=ExtResource( 5 )] -position = Vector2( 72, 450 ) - -[node name="coin2" parent="." instance=ExtResource( 5 )] -position = Vector2( 234, 450 ) - [node name="CoinHUD" type="CanvasLayer" parent="."] [node name="Panel" type="Panel" parent="CoinHUD"] @@ -61,25 +72,35 @@ margin_right = 288.0 margin_bottom = 54.0 custom_styles/panel = SubResource( 1 ) -[node name="TextureRect" type="TextureRect" parent="CoinHUD"] -margin_left = 144.0 -margin_top = 18.0 -margin_right = 184.0 -margin_bottom = 58.0 -texture = ExtResource( 6 ) - [node name="Label" type="Label" parent="CoinHUD"] -margin_left = 198.0 +margin_left = 180.0 margin_top = 18.0 -margin_right = 238.0 +margin_right = 220.0 margin_bottom = 36.0 text = "X" [node name="Coins" type="Label" parent="CoinHUD"] -margin_left = 216.0 +margin_left = 198.0 margin_top = 18.0 -margin_right = 256.0 +margin_right = 238.0 margin_bottom = 32.0 text = "##" +script = ExtResource( 7 ) -[connection signal="ready" from="CoinHUD" to="Player" method="_on_CoinHUD_ready"] +[node name="AnimatedSprite" type="AnimatedSprite" parent="CoinHUD"] +position = Vector2( 162, 18 ) +frames = SubResource( 4 ) +animation = "spin" +frame = 1 +playing = true +centered = false + +[node name="Coins" type="Node" parent="."] + +[node name="coin" parent="Coins" instance=ExtResource( 5 )] +position = Vector2( 72, 450 ) + +[node name="coin2" parent="Coins" instance=ExtResource( 5 )] +position = Vector2( 234, 450 ) + +[editable path="Coins/coin"] diff --git a/src/coin/CoinCollected.cpp b/src/coin/CoinCollected.cpp index 7f1f2f2..9f3a9a4 100644 --- a/src/coin/CoinCollected.cpp +++ b/src/coin/CoinCollected.cpp @@ -2,13 +2,13 @@ #include 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("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"); } diff --git a/src/coin/CoinCounter.cpp b/src/coin/CoinCounter.cpp index 365453b..22fc8e4 100644 --- a/src/coin/CoinCounter.cpp +++ b/src/coin/CoinCounter.cpp @@ -1,14 +1,12 @@ #include "coin/CoinCounter.h" -#include - +#include +#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"); + } + - +} diff --git a/src/coin/CoinCounter.h b/src/coin/CoinCounter.h index b194fb9..006aa93 100644 --- a/src/coin/CoinCounter.h +++ b/src/coin/CoinCounter.h @@ -1,28 +1,24 @@ #ifndef ALAI_COIN_COUNTER #define ALAI_COIN_COUNTER -#include "state_machine/State.h" #include #include -#include +#include 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(); }; diff --git a/src/godot.cpp b/src/godot.cpp index 2e5d9a6..620fb1d 100644 --- a/src/godot.cpp +++ b/src/godot.cpp @@ -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(); register_class(); register_class(); + register_class(); } From d14cc627de350965fb7aa48ba82d235d23987b46 Mon Sep 17 00:00:00 2001 From: Martin Araneda Date: Sun, 17 Jul 2022 21:51:11 -0400 Subject: [PATCH 10/28] Flag successfully placed on lvl, hitbox detected and working --- godot/levels/GoalNotReached.gdns | 8 ++++ godot/levels/Prototype.tscn | 49 +++++++++++++++++++- src/goal/GoalNotReached.cpp | 56 +++++++++++++++++++++++ src/goal/GoalNotReached.h | 76 ++++++++++++++++++++++++++++++++ src/goal/GoalReached.cpp | 35 +++++++++++++++ src/goal/GoalReached.h | 74 +++++++++++++++++++++++++++++++ src/godot.cpp | 4 ++ 7 files changed, 300 insertions(+), 2 deletions(-) create mode 100644 godot/levels/GoalNotReached.gdns create mode 100644 src/goal/GoalNotReached.cpp create mode 100644 src/goal/GoalNotReached.h create mode 100644 src/goal/GoalReached.cpp create mode 100644 src/goal/GoalReached.h diff --git a/godot/levels/GoalNotReached.gdns b/godot/levels/GoalNotReached.gdns new file mode 100644 index 0000000..1e3a1aa --- /dev/null +++ b/godot/levels/GoalNotReached.gdns @@ -0,0 +1,8 @@ +[gd_resource type="NativeScript" load_steps=2 format=2] + +[ext_resource path="res://gdnative/alai.tres" type="GDNativeLibrary" id=1] + +[resource] +resource_name = "GoalNotReached" +class_name = "GoalNotReached" +library = ExtResource( 1 ) diff --git a/godot/levels/Prototype.tscn b/godot/levels/Prototype.tscn index e3c4608..699991e 100644 --- a/godot/levels/Prototype.tscn +++ b/godot/levels/Prototype.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=12 format=2] +[gd_scene load_steps=18 format=2] [ext_resource path="res://CameraLimit.gdns" type="Script" id=1] [ext_resource path="res://characters/player/Player.tscn" type="PackedScene" id=2] @@ -7,6 +7,8 @@ [ext_resource path="res://collectables/coin/Coin.tscn" type="PackedScene" id=5] [ext_resource path="res://assets/coin.png" type="Texture" id=6] [ext_resource path="res://hud/coin/Counter.gdns" type="Script" id=7] +[ext_resource path="res://assets/flag.png" type="Texture" id=8] +[ext_resource path="res://levels/GoalNotReached.gdns" type="Script" id=9] [sub_resource type="StyleBoxFlat" id=1] bg_color = Color( 0, 0, 0, 0.541176 ) @@ -27,6 +29,25 @@ animations = [ { "speed": 5.0 } ] +[sub_resource type="RectangleShape2D" id=5] +extents = Vector2( 10, 18 ) + +[sub_resource type="AtlasTexture" id=6] +atlas = ExtResource( 8 ) +region = Rect2( 0, 0, 18, 36 ) + +[sub_resource type="AtlasTexture" id=7] +atlas = ExtResource( 8 ) +region = Rect2( 18, 0, 18, 36 ) + +[sub_resource type="SpriteFrames" id=8] +animations = [ { +"frames": [ SubResource( 6 ), SubResource( 7 ) ], +"loop": true, +"name": "flagmove", +"speed": 5.0 +} ] + [node name="Prototype" type="Node2D"] [node name="Player" parent="." instance=ExtResource( 2 )] @@ -91,7 +112,6 @@ script = ExtResource( 7 ) position = Vector2( 162, 18 ) frames = SubResource( 4 ) animation = "spin" -frame = 1 playing = true centered = false @@ -100,7 +120,32 @@ centered = false [node name="coin" parent="Coins" instance=ExtResource( 5 )] position = Vector2( 72, 450 ) +[node name="AnimatedSprite" parent="Coins/coin" index="1"] +frame = 0 + [node name="coin2" parent="Coins" instance=ExtResource( 5 )] position = Vector2( 234, 450 ) +[node name="Goal" type="Area2D" parent="."] +position = Vector2( 324, 378 ) + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Goal"] +position = Vector2( 18, 18 ) +shape = SubResource( 5 ) + +[node name="AnimatedSprite" type="AnimatedSprite" parent="Goal"] +position = Vector2( 18, 18 ) +frames = SubResource( 8 ) +animation = "flagmove" +playing = true + +[node name="StateMachine" type="Node" parent="Goal"] + +[node name="GoalReached" type="Node" parent="Goal/StateMachine"] + +[node name="GoalNotReached" type="Node" parent="Goal/StateMachine"] +script = ExtResource( 9 ) + +[connection signal="body_entered" from="Goal" to="Goal/StateMachine/GoalNotReached" method="_on_Goal_body_entered"] + [editable path="Coins/coin"] diff --git a/src/goal/GoalNotReached.cpp b/src/goal/GoalNotReached.cpp new file mode 100644 index 0000000..4978c11 --- /dev/null +++ b/src/goal/GoalNotReached.cpp @@ -0,0 +1,56 @@ +#include "goal/GoalNotReached.h" +#include + +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"); + 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(parent_node); + goal->set_collision_mask_bit(0, false); + } + + get_state_machine()->change("GoalReached");*/ + + +} + + + diff --git a/src/goal/GoalNotReached.h b/src/goal/GoalNotReached.h new file mode 100644 index 0000000..82c9628 --- /dev/null +++ b/src/goal/GoalNotReached.h @@ -0,0 +1,76 @@ +#ifndef ALAI_GOAL_NOT_REACHED +#define ALAI_GOAL_NOT_REACHED + +#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 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 diff --git a/src/goal/GoalReached.cpp b/src/goal/GoalReached.cpp new file mode 100644 index 0000000..580aea4 --- /dev/null +++ b/src/goal/GoalReached.cpp @@ -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("coin_collected", "amount", GODOT_VARIANT_TYPE_INT); +} + +GoalReached::GoalReached() +{ +} + +GoalReached::~GoalReached() +{ +} + +void GoalReached::_init() +{ + +} + +void GoalReached::_state_enter() +{ + + +} + +void GoalReached::_state_exit() +{ + +} + diff --git a/src/goal/GoalReached.h b/src/goal/GoalReached.h new file mode 100644 index 0000000..2c854bb --- /dev/null +++ b/src/goal/GoalReached.h @@ -0,0 +1,74 @@ +#ifndef ALAI_GOAL_REACHED +#define ALAI_GOAL_REACHED + +#include "state_machine/State.h" + +#include +#include +#include + +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 diff --git a/src/godot.cpp b/src/godot.cpp index 620fb1d..350403b 100644 --- a/src/godot.cpp +++ b/src/godot.cpp @@ -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(); register_class(); register_class(); + register_class(); + register_class(); } From b24c9e8732db2f8642ade13882ef88254716fa75 Mon Sep 17 00:00:00 2001 From: Martin Araneda Date: Mon, 1 Aug 2022 14:10:00 -0400 Subject: [PATCH 11/28] fix goal state --- godot/goal/Goal.tscn | 51 ++++++++++++++++++++++ godot/{levels => goal}/GoalNotReached.gdns | 0 godot/goal/GoalReached.gdns | 8 ++++ godot/levels/Prototype.tscn | 50 ++------------------- godot/project.godot | 1 + src/goal/GoalNotReached.cpp | 11 +---- src/goal/GoalReached.cpp | 3 +- 7 files changed, 68 insertions(+), 56 deletions(-) create mode 100644 godot/goal/Goal.tscn rename godot/{levels => goal}/GoalNotReached.gdns (100%) create mode 100644 godot/goal/GoalReached.gdns diff --git a/godot/goal/Goal.tscn b/godot/goal/Goal.tscn new file mode 100644 index 0000000..3e6e22e --- /dev/null +++ b/godot/goal/Goal.tscn @@ -0,0 +1,51 @@ +[gd_scene load_steps=9 format=2] + +[ext_resource path="res://assets/flag.png" type="Texture" id=1] +[ext_resource path="res://goal/GoalNotReached.gdns" type="Script" id=2] +[ext_resource path="res://goal/GoalReached.gdns" type="Script" id=3] +[ext_resource path="res://state_machine/StateMachine.gdns" type="Script" id=4] + +[sub_resource type="RectangleShape2D" id=5] +extents = Vector2( 10, 18 ) + +[sub_resource type="AtlasTexture" id=6] +atlas = ExtResource( 1 ) +region = Rect2( 0, 0, 18, 36 ) + +[sub_resource type="AtlasTexture" id=7] +atlas = ExtResource( 1 ) +region = Rect2( 18, 0, 18, 36 ) + +[sub_resource type="SpriteFrames" id=8] +animations = [ { +"frames": [ SubResource( 6 ), SubResource( 7 ) ], +"loop": true, +"name": "flagmove", +"speed": 5.0 +} ] + +[node name="Goal" type="Area2D"] +position = Vector2( 324, 378 ) +collision_layer = 32 + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +position = Vector2( 18, 18 ) +shape = SubResource( 5 ) + +[node name="AnimatedSprite" type="AnimatedSprite" parent="."] +position = Vector2( 18, 18 ) +frames = SubResource( 8 ) +animation = "flagmove" +frame = 1 +playing = true + +[node name="StateMachine" type="Node" parent="."] +script = ExtResource( 4 ) + +[node name="GoalReached" type="Node" parent="StateMachine"] +script = ExtResource( 3 ) + +[node name="GoalNotReached" type="Node" parent="StateMachine"] +script = ExtResource( 2 ) + +[connection signal="body_entered" from="." to="StateMachine/GoalNotReached" method="_on_Goal_body_entered"] diff --git a/godot/levels/GoalNotReached.gdns b/godot/goal/GoalNotReached.gdns similarity index 100% rename from godot/levels/GoalNotReached.gdns rename to godot/goal/GoalNotReached.gdns diff --git a/godot/goal/GoalReached.gdns b/godot/goal/GoalReached.gdns new file mode 100644 index 0000000..eaa25ba --- /dev/null +++ b/godot/goal/GoalReached.gdns @@ -0,0 +1,8 @@ +[gd_resource type="NativeScript" load_steps=2 format=2] + +[ext_resource path="res://gdnative/alai.tres" type="GDNativeLibrary" id=1] + +[resource] +resource_name = "GoalReached" +class_name = "GoalReached" +library = ExtResource( 1 ) diff --git a/godot/levels/Prototype.tscn b/godot/levels/Prototype.tscn index 699991e..036f781 100644 --- a/godot/levels/Prototype.tscn +++ b/godot/levels/Prototype.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=18 format=2] +[gd_scene load_steps=13 format=2] [ext_resource path="res://CameraLimit.gdns" type="Script" id=1] [ext_resource path="res://characters/player/Player.tscn" type="PackedScene" id=2] @@ -7,8 +7,7 @@ [ext_resource path="res://collectables/coin/Coin.tscn" type="PackedScene" id=5] [ext_resource path="res://assets/coin.png" type="Texture" id=6] [ext_resource path="res://hud/coin/Counter.gdns" type="Script" id=7] -[ext_resource path="res://assets/flag.png" type="Texture" id=8] -[ext_resource path="res://levels/GoalNotReached.gdns" type="Script" id=9] +[ext_resource path="res://goal/Goal.tscn" type="PackedScene" id=8] [sub_resource type="StyleBoxFlat" id=1] bg_color = Color( 0, 0, 0, 0.541176 ) @@ -29,25 +28,6 @@ animations = [ { "speed": 5.0 } ] -[sub_resource type="RectangleShape2D" id=5] -extents = Vector2( 10, 18 ) - -[sub_resource type="AtlasTexture" id=6] -atlas = ExtResource( 8 ) -region = Rect2( 0, 0, 18, 36 ) - -[sub_resource type="AtlasTexture" id=7] -atlas = ExtResource( 8 ) -region = Rect2( 18, 0, 18, 36 ) - -[sub_resource type="SpriteFrames" id=8] -animations = [ { -"frames": [ SubResource( 6 ), SubResource( 7 ) ], -"loop": true, -"name": "flagmove", -"speed": 5.0 -} ] - [node name="Prototype" type="Node2D"] [node name="Player" parent="." instance=ExtResource( 2 )] @@ -112,6 +92,7 @@ script = ExtResource( 7 ) position = Vector2( 162, 18 ) frames = SubResource( 4 ) animation = "spin" +frame = 1 playing = true centered = false @@ -120,32 +101,9 @@ centered = false [node name="coin" parent="Coins" instance=ExtResource( 5 )] position = Vector2( 72, 450 ) -[node name="AnimatedSprite" parent="Coins/coin" index="1"] -frame = 0 - [node name="coin2" parent="Coins" instance=ExtResource( 5 )] position = Vector2( 234, 450 ) -[node name="Goal" type="Area2D" parent="."] -position = Vector2( 324, 378 ) - -[node name="CollisionShape2D" type="CollisionShape2D" parent="Goal"] -position = Vector2( 18, 18 ) -shape = SubResource( 5 ) - -[node name="AnimatedSprite" type="AnimatedSprite" parent="Goal"] -position = Vector2( 18, 18 ) -frames = SubResource( 8 ) -animation = "flagmove" -playing = true - -[node name="StateMachine" type="Node" parent="Goal"] - -[node name="GoalReached" type="Node" parent="Goal/StateMachine"] - -[node name="GoalNotReached" type="Node" parent="Goal/StateMachine"] -script = ExtResource( 9 ) - -[connection signal="body_entered" from="Goal" to="Goal/StateMachine/GoalNotReached" method="_on_Goal_body_entered"] +[node name="Goal" parent="." instance=ExtResource( 8 )] [editable path="Coins/coin"] diff --git a/godot/project.godot b/godot/project.godot index 4ff88a6..92bc2da 100644 --- a/godot/project.godot +++ b/godot/project.godot @@ -96,6 +96,7 @@ right={ 2d_physics/layer_1="Player" 2d_physics/layer_2="Tiles" 2d_physics/layer_3="Collectables" +2d_physics/layer_6="End Level" [physics] diff --git a/src/goal/GoalNotReached.cpp b/src/goal/GoalNotReached.cpp index 4978c11..c4763f3 100644 --- a/src/goal/GoalNotReached.cpp +++ b/src/goal/GoalNotReached.cpp @@ -38,16 +38,9 @@ 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(parent_node); - goal->set_collision_mask_bit(0, false); - } - get_state_machine()->change("GoalReached");*/ + + get_state_machine()->change("GoalReached"); } diff --git a/src/goal/GoalReached.cpp b/src/goal/GoalReached.cpp index 580aea4..239f1e4 100644 --- a/src/goal/GoalReached.cpp +++ b/src/goal/GoalReached.cpp @@ -1,4 +1,5 @@ #include "goal/GoalReached.h" +#include using namespace godot; @@ -6,7 +7,6 @@ void GoalReached::_register_methods() { register_method("_state_enter", &GoalReached::_state_enter); register_method("_state_exit", &GoalReached::_state_exit); - //register_signal("coin_collected", "amount", GODOT_VARIANT_TYPE_INT); } GoalReached::GoalReached() @@ -24,6 +24,7 @@ void GoalReached::_init() void GoalReached::_state_enter() { + Godot::print("Flag touched"); } From e54e3b0687373c34922abb277108a5bba7439471 Mon Sep 17 00:00:00 2001 From: Martin Araneda Date: Mon, 1 Aug 2022 15:05:09 -0400 Subject: [PATCH 12/28] changes to coinHUD --- godot/goal/Goal.tscn | 2 +- godot/hud/CoinHUD.gd | 8 +++++ godot/hud/CoinHUD.tscn | 58 +++++++++++++++++++++++++++++++++++++ godot/levels/Prototype.tscn | 56 ++--------------------------------- src/goal/GoalNotReached.cpp | 8 ++++- 5 files changed, 77 insertions(+), 55 deletions(-) create mode 100644 godot/hud/CoinHUD.gd create mode 100644 godot/hud/CoinHUD.tscn diff --git a/godot/goal/Goal.tscn b/godot/goal/Goal.tscn index 3e6e22e..ee70903 100644 --- a/godot/goal/Goal.tscn +++ b/godot/goal/Goal.tscn @@ -36,11 +36,11 @@ shape = SubResource( 5 ) position = Vector2( 18, 18 ) frames = SubResource( 8 ) animation = "flagmove" -frame = 1 playing = true [node name="StateMachine" type="Node" parent="."] script = ExtResource( 4 ) +default_state = "GoalNotReached" [node name="GoalReached" type="Node" parent="StateMachine"] script = ExtResource( 3 ) diff --git a/godot/hud/CoinHUD.gd b/godot/hud/CoinHUD.gd new file mode 100644 index 0000000..efe294f --- /dev/null +++ b/godot/hud/CoinHUD.gd @@ -0,0 +1,8 @@ +extends CanvasLayer + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _physics_process(delta): + if get_tree().paused: + visible = false + else: + visible = true diff --git a/godot/hud/CoinHUD.tscn b/godot/hud/CoinHUD.tscn new file mode 100644 index 0000000..512a8cd --- /dev/null +++ b/godot/hud/CoinHUD.tscn @@ -0,0 +1,58 @@ +[gd_scene load_steps=8 format=2] + +[ext_resource path="res://assets/coin.png" type="Texture" id=1] +[ext_resource path="res://hud/coin/Counter.gdns" type="Script" id=2] +[ext_resource path="res://hud/CoinHUD.gd" type="Script" id=3] + +[sub_resource type="StyleBoxFlat" id=1] +bg_color = Color( 0, 0, 0, 0.541176 ) + +[sub_resource type="AtlasTexture" id=2] +atlas = ExtResource( 1 ) +region = Rect2( 0, 0, 18, 18 ) + +[sub_resource type="AtlasTexture" id=3] +atlas = ExtResource( 1 ) +region = Rect2( 18, 0, 18, 18 ) + +[sub_resource type="SpriteFrames" id=4] +animations = [ { +"frames": [ SubResource( 2 ), SubResource( 3 ) ], +"loop": true, +"name": "spin", +"speed": 5.0 +} ] + +[node name="CoinHUD" type="CanvasLayer"] +pause_mode = 2 +script = ExtResource( 3 ) + +[node name="Panel" type="Panel" parent="."] +margin_left = 144.0 +margin_top = 18.0 +margin_right = 288.0 +margin_bottom = 54.0 +custom_styles/panel = SubResource( 1 ) + +[node name="Label" type="Label" parent="."] +margin_left = 180.0 +margin_top = 18.0 +margin_right = 220.0 +margin_bottom = 36.0 +text = "X" + +[node name="Coins" type="Label" parent="."] +margin_left = 198.0 +margin_top = 18.0 +margin_right = 238.0 +margin_bottom = 32.0 +text = "##" +script = ExtResource( 2 ) + +[node name="AnimatedSprite" type="AnimatedSprite" parent="."] +position = Vector2( 162, 18 ) +frames = SubResource( 4 ) +animation = "spin" +frame = 1 +playing = true +centered = false diff --git a/godot/levels/Prototype.tscn b/godot/levels/Prototype.tscn index 036f781..b71e0c7 100644 --- a/godot/levels/Prototype.tscn +++ b/godot/levels/Prototype.tscn @@ -1,33 +1,13 @@ -[gd_scene load_steps=13 format=2] +[gd_scene load_steps=8 format=2] [ext_resource path="res://CameraLimit.gdns" type="Script" id=1] [ext_resource path="res://characters/player/Player.tscn" type="PackedScene" id=2] [ext_resource path="res://levels/Prototype.tmx" type="PackedScene" id=3] [ext_resource path="res://assets/backgrounds/mountains.png" type="Texture" id=4] [ext_resource path="res://collectables/coin/Coin.tscn" type="PackedScene" id=5] -[ext_resource path="res://assets/coin.png" type="Texture" id=6] -[ext_resource path="res://hud/coin/Counter.gdns" type="Script" id=7] +[ext_resource path="res://hud/CoinHUD.tscn" type="PackedScene" id=6] [ext_resource path="res://goal/Goal.tscn" type="PackedScene" id=8] -[sub_resource type="StyleBoxFlat" id=1] -bg_color = Color( 0, 0, 0, 0.541176 ) - -[sub_resource type="AtlasTexture" id=2] -atlas = ExtResource( 6 ) -region = Rect2( 0, 0, 18, 18 ) - -[sub_resource type="AtlasTexture" id=3] -atlas = ExtResource( 6 ) -region = Rect2( 18, 0, 18, 18 ) - -[sub_resource type="SpriteFrames" id=4] -animations = [ { -"frames": [ SubResource( 2 ), SubResource( 3 ) ], -"loop": true, -"name": "spin", -"speed": 5.0 -} ] - [node name="Prototype" type="Node2D"] [node name="Player" parent="." instance=ExtResource( 2 )] @@ -64,37 +44,7 @@ centered = false [node name="Prototype" parent="Map" instance=ExtResource( 3 )] script = ExtResource( 1 ) -[node name="CoinHUD" type="CanvasLayer" parent="."] - -[node name="Panel" type="Panel" parent="CoinHUD"] -margin_left = 144.0 -margin_top = 18.0 -margin_right = 288.0 -margin_bottom = 54.0 -custom_styles/panel = SubResource( 1 ) - -[node name="Label" type="Label" parent="CoinHUD"] -margin_left = 180.0 -margin_top = 18.0 -margin_right = 220.0 -margin_bottom = 36.0 -text = "X" - -[node name="Coins" type="Label" parent="CoinHUD"] -margin_left = 198.0 -margin_top = 18.0 -margin_right = 238.0 -margin_bottom = 32.0 -text = "##" -script = ExtResource( 7 ) - -[node name="AnimatedSprite" type="AnimatedSprite" parent="CoinHUD"] -position = Vector2( 162, 18 ) -frames = SubResource( 4 ) -animation = "spin" -frame = 1 -playing = true -centered = false +[node name="CoinHUD" parent="." instance=ExtResource( 6 )] [node name="Coins" type="Node" parent="."] diff --git a/src/goal/GoalNotReached.cpp b/src/goal/GoalNotReached.cpp index c4763f3..4248066 100644 --- a/src/goal/GoalNotReached.cpp +++ b/src/goal/GoalNotReached.cpp @@ -38,7 +38,13 @@ void GoalNotReached::_state_exit() void GoalNotReached::_on_Goal_body_entered(Node *node) { - + auto parent_node = get_parent(); + + if (parent_node != nullptr) + { + auto goal = Object::cast_to(parent_node); + goal->set_collision_mask_bit(0, false); + } get_state_machine()->change("GoalReached"); From 64102a992aabefbb7bf5153977bf4cf54d83a1ee Mon Sep 17 00:00:00 2001 From: Martin Araneda Date: Fri, 12 Aug 2022 21:50:48 -0400 Subject: [PATCH 13/28] GameOverScreen .h/.cpp made. Godot scene completed --- godot/GUI/GameOver.tscn | 47 ++++++++++++++++++++++ godot/GUI/botonreiniciar.gdns | 8 ++++ src/gui/game_over/GameOverScreen.cpp | 26 +++++++++++++ src/gui/game_over/GameOverScreen.h | 58 ++++++++++++++++++++++++++++ 4 files changed, 139 insertions(+) create mode 100644 godot/GUI/GameOver.tscn create mode 100644 godot/GUI/botonreiniciar.gdns create mode 100644 src/gui/game_over/GameOverScreen.cpp create mode 100644 src/gui/game_over/GameOverScreen.h diff --git a/godot/GUI/GameOver.tscn b/godot/GUI/GameOver.tscn new file mode 100644 index 0000000..d9729bf --- /dev/null +++ b/godot/GUI/GameOver.tscn @@ -0,0 +1,47 @@ +[gd_scene load_steps=7 format=2] + +[ext_resource path="res://assets/fonts/ttf/PixelOperator8.ttf" type="DynamicFontData" id=1] +[ext_resource path="res://assets/fonts/ttf/PixelOperatorHB8.ttf" type="DynamicFontData" id=2] +[ext_resource path="res://GUI/botonreiniciar.gdns" type="Script" id=3] + +[sub_resource type="DynamicFont" id=1] +size = 50 +font_data = ExtResource( 1 ) + +[sub_resource type="DynamicFont" id=2] +font_data = ExtResource( 2 ) + +[sub_resource type="StyleBoxFlat" id=3] +bg_color = Color( 0.0705882, 0.917647, 0, 1 ) + +[node name="GameOver" type="Control"] +anchor_right = 1.0 +anchor_bottom = 1.0 + +[node name="ColorRect" type="ColorRect" parent="."] +margin_right = 512.0 +margin_bottom = 288.0 +rect_min_size = Vector2( 512, 288 ) +rect_rotation = -0.338293 +color = Color( 0, 0, 0, 1 ) + +[node name="Label" type="Label" parent="."] +margin_left = 66.0 +margin_top = 17.0 +margin_right = 456.0 +margin_bottom = 71.0 +custom_fonts/font = SubResource( 1 ) +text = "GAME OVER" +align = 1 + +[node name="botonreiniciar" type="Button" parent="."] +margin_left = 194.0 +margin_top = 150.0 +margin_right = 338.0 +margin_bottom = 180.0 +custom_fonts/font = SubResource( 2 ) +custom_styles/hover = SubResource( 3 ) +text = "REINICIAR" +script = ExtResource( 3 ) + +[connection signal="pressed" from="botonreiniciar" to="botonreiniciar" method="_on_botonreiniciar_pressed"] diff --git a/godot/GUI/botonreiniciar.gdns b/godot/GUI/botonreiniciar.gdns new file mode 100644 index 0000000..750e9bf --- /dev/null +++ b/godot/GUI/botonreiniciar.gdns @@ -0,0 +1,8 @@ +[gd_resource type="NativeScript" load_steps=2 format=2] + +[ext_resource path="res://gdnative/alai.tres" type="GDNativeLibrary" id=1] + +[resource] +resource_name = "GameOverScreen" +class_name = "GameOverScreen" +library = ExtResource( 1 ) diff --git a/src/gui/game_over/GameOverScreen.cpp b/src/gui/game_over/GameOverScreen.cpp new file mode 100644 index 0000000..b26ec00 --- /dev/null +++ b/src/gui/game_over/GameOverScreen.cpp @@ -0,0 +1,26 @@ +#include "gui/game_over/GameOverScreen.h" +#include +using namespace godot; + +void GameOverScreen::_register_methods() +{ + register_method("_on_botonreiniciar_pressed", &GameOverScreen::_on_botonreiniciar_pressed); +} + +GameOverScreen::GameOverScreen() +{ +} + +GameOverScreen::~GameOverScreen() +{ +} + +void GameOverScreen::_init() +{ + +} +void GameOverScreen::_on_botonreiniciar_pressed() +{ + get_tree().change_scene("res://monitor/GUI.tscn"); + +} \ No newline at end of file diff --git a/src/gui/game_over/GameOverScreen.h b/src/gui/game_over/GameOverScreen.h new file mode 100644 index 0000000..651886f --- /dev/null +++ b/src/gui/game_over/GameOverScreen.h @@ -0,0 +1,58 @@ +#ifndef ALAI_GAME_OVER_SCREEN +#define ALAI_GAME_OVER_SCREEN + + +#include +#include +#include + +namespace godot +{ + /** + * @brief This class controls what happens when the Coin is in the collected . + * + */ + class GameOverScreen : public Control + { + GODOT_CLASS(GameOverScreen, Control) + + private: + + + 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 GameOverScreen object. + * + */ + GameOverScreen(); + + /** + * @brief Destroy the GameOverScreen object. + * + */ + ~GameOverScreen(); + + /** + * @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. + * + */ + void _on_botonreiniciar_pressed(); + }; + +} + +#endif From 7083f680ee196ff5bde8cd9a60bd669e4e91f39d Mon Sep 17 00:00:00 2001 From: Chris Cromer Date: Fri, 26 Aug 2022 13:48:39 -0400 Subject: [PATCH 14/28] ignore delta since we don't use it --- godot/hud/CoinHUD.gd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/godot/hud/CoinHUD.gd b/godot/hud/CoinHUD.gd index efe294f..bd8f7b1 100644 --- a/godot/hud/CoinHUD.gd +++ b/godot/hud/CoinHUD.gd @@ -1,7 +1,7 @@ extends CanvasLayer # Called every frame. 'delta' is the elapsed time since the previous frame. -func _physics_process(delta): +func _physics_process(_delta): if get_tree().paused: visible = false else: From ff600cd7614ac74d3b72be7f4ad2a11a7852135a Mon Sep 17 00:00:00 2001 From: Chris Cromer Date: Fri, 26 Aug 2022 13:48:59 -0400 Subject: [PATCH 15/28] fix spacing --- src/gui/game_over/GameOverScreen.h | 76 +++++++++++++++--------------- 1 file changed, 37 insertions(+), 39 deletions(-) diff --git a/src/gui/game_over/GameOverScreen.h b/src/gui/game_over/GameOverScreen.h index 651886f..f794001 100644 --- a/src/gui/game_over/GameOverScreen.h +++ b/src/gui/game_over/GameOverScreen.h @@ -8,51 +8,49 @@ namespace godot { - /** - * @brief This class controls what happens when the Coin is in the collected . - * - */ - class GameOverScreen : public Control - { - GODOT_CLASS(GameOverScreen, Control) + /** + * @brief This class controls what happens when the Coin is in the collected . + * + */ + class GameOverScreen : public Control + { + GODOT_CLASS(GameOverScreen, Control) - private: + private: + 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 GameOverScreen object. + * + */ + GameOverScreen(); - /** - * @brief Construct a new GameOverScreen object. - * - */ - GameOverScreen(); + /** + * @brief Destroy the GameOverScreen object. + * + */ + ~GameOverScreen(); - /** - * @brief Destroy the GameOverScreen object. - * - */ - ~GameOverScreen(); + /** + * @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. - * - */ - void _on_botonreiniciar_pressed(); - }; - + /** + * @brief Called when the collected of the coin is entered. + * + */ + void _on_botonreiniciar_pressed(); + }; } #endif From b74a8ce1aa5fbdd0d223fc0a00a4ccaaea6cf766 Mon Sep 17 00:00:00 2001 From: Chris Cromer Date: Fri, 26 Aug 2022 13:51:19 -0400 Subject: [PATCH 16/28] fix function name and pointer usage --- src/gui/game_over/GameOverScreen.cpp | 11 ++++++----- src/gui/game_over/GameOverScreen.h | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/gui/game_over/GameOverScreen.cpp b/src/gui/game_over/GameOverScreen.cpp index b26ec00..66bc484 100644 --- a/src/gui/game_over/GameOverScreen.cpp +++ b/src/gui/game_over/GameOverScreen.cpp @@ -1,10 +1,12 @@ #include "gui/game_over/GameOverScreen.h" #include +#include + 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); } GameOverScreen::GameOverScreen() @@ -19,8 +21,7 @@ void GameOverScreen::_init() { } -void GameOverScreen::_on_botonreiniciar_pressed() +void GameOverScreen::_on_restart_button_pressed() { - get_tree().change_scene("res://monitor/GUI.tscn"); - -} \ No newline at end of file + get_tree()->change_scene("res://monitor/GUI.tscn"); +} diff --git a/src/gui/game_over/GameOverScreen.h b/src/gui/game_over/GameOverScreen.h index f794001..1a40b2e 100644 --- a/src/gui/game_over/GameOverScreen.h +++ b/src/gui/game_over/GameOverScreen.h @@ -49,7 +49,7 @@ namespace godot * @brief Called when the collected of the coin is entered. * */ - void _on_botonreiniciar_pressed(); + void _on_restart_button_pressed(); }; } From 0f4e77d4b7096cddc1c32617eb25360c0551e218 Mon Sep 17 00:00:00 2001 From: Chris Cromer Date: Fri, 26 Aug 2022 19:27:57 -0400 Subject: [PATCH 17/28] cleanup c++ code --- src/CameraLimit.cpp | 21 ++--- src/CameraLimit.h | 6 +- src/Main.cpp | 79 ++++++++--------- src/Main.h | 56 +++++++----- src/godot.cpp | 35 ++++---- src/player/Player.cpp | 137 ++++++++++++++--------------- src/player/Player.h | 35 ++++---- src/player/states/PlayerFall.cpp | 23 +++-- src/player/states/PlayerFall.h | 12 +-- src/player/states/PlayerIdle.cpp | 23 +++-- src/player/states/PlayerIdle.h | 15 ++-- src/player/states/PlayerJump.cpp | 27 +++--- src/player/states/PlayerJump.h | 14 +-- src/player/states/PlayerMove.cpp | 23 +++-- src/player/states/PlayerMove.h | 10 +-- src/state_machine/State.cpp | 22 +++-- src/state_machine/State.h | 15 ++-- src/state_machine/StateMachine.cpp | 74 ++++++++-------- src/state_machine/StateMachine.h | 64 +++++++------- 19 files changed, 340 insertions(+), 351 deletions(-) diff --git a/src/CameraLimit.cpp b/src/CameraLimit.cpp index 95858b2..cdc4add 100644 --- a/src/CameraLimit.cpp +++ b/src/CameraLimit.cpp @@ -1,40 +1,37 @@ #include "CameraLimit.h" +#include #include #include -#include #include -#include -using namespace godot; - -void CameraLimit::_register_methods() +void alai::CameraLimit::_register_methods() { register_method("_ready", &CameraLimit::_ready); } -CameraLimit::CameraLimit() +alai::CameraLimit::CameraLimit() { } -CameraLimit::~CameraLimit() +alai::CameraLimit::~CameraLimit() { } -void CameraLimit::_init() +void alai::CameraLimit::_init() { } -void CameraLimit::_ready() +void alai::CameraLimit::_ready() { auto node = find_node("Middleground"); - auto middle_ground = cast_to(node); + auto middle_ground = cast_to(node); if (middle_ground != NULL) { auto used_rect = middle_ground->get_used_rect(); - auto bounds = Vector2(used_rect.position.x + used_rect.size.x, used_rect.position.y + used_rect.size.y); + auto bounds = godot::Vector2(used_rect.position.x + used_rect.size.x, used_rect.position.y + used_rect.size.y); node = get_tree()->get_root()->find_node("Camera2D", true, false); - auto camera = cast_to(node); + auto camera = cast_to(node); if (camera != NULL) { camera->set_limit(2, bounds.x * middle_ground->get_cell_size().x); diff --git a/src/CameraLimit.h b/src/CameraLimit.h index e277a4b..d9f86b5 100644 --- a/src/CameraLimit.h +++ b/src/CameraLimit.h @@ -4,16 +4,16 @@ #include #include -namespace godot +namespace alai { /** * @brief This class limits the camera's position. * * @details The camera will be limited based on the used width and height of the Middleground tilemap. */ - class CameraLimit: public Node2D + class CameraLimit: public godot::Node2D { - GODOT_CLASS(CameraLimit, Node2D) + GODOT_CLASS(CameraLimit, godot::Node2D) public: /** diff --git a/src/Main.cpp b/src/Main.cpp index 6bc13fb..00d622f 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -2,50 +2,47 @@ #include -using namespace godot; -using namespace main; - -void Main::_register_methods() +void alai::main::Main::_register_methods() { - register_method("_ready", &Main::_ready); - register_method("_physics_process", &Main::_physics_process); - register_method("_on_monitor_loaded", &Main::_on_monitor_loaded); - register_property("game_version", &Main::set_game_version, &Main::get_game_version, String(main::game_version.c_str())); - register_property>("level", &Main::set_level, &Main::get_level, NULL, GODOT_METHOD_RPC_MODE_DISABLED, GODOT_PROPERTY_USAGE_DEFAULT, GODOT_PROPERTY_HINT_RESOURCE_TYPE, String("PackedScene")); - register_property("full_screen", &Main::set_full_screen, &Main::get_full_screen, main::full_screen); - register_property("window_size", &Main::set_window_size, &Main::get_window_size, main::window_size); - register_property("launch_screen", &Main::set_launch_screen, &Main::get_launch_screen, main::launch_screen); - register_signal
("monitor_loaded"); + godot::register_method("_ready", &Main::_ready); + godot::register_method("_physics_process", &Main::_physics_process); + godot::register_method("_on_monitor_loaded", &Main::_on_monitor_loaded); + godot::register_property("game_version", &Main::set_game_version, &Main::get_game_version, godot::String(main::game_version.c_str())); + godot::register_property>("level", &Main::set_level, &Main::get_level, NULL, GODOT_METHOD_RPC_MODE_DISABLED, GODOT_PROPERTY_USAGE_DEFAULT, GODOT_PROPERTY_HINT_RESOURCE_TYPE, godot::String("PackedScene")); + godot::register_property("full_screen", &Main::set_full_screen, &Main::get_full_screen, main::full_screen); + godot::register_property("window_size", &Main::set_window_size, &Main::get_window_size, main::window_size); + godot::register_property("launch_screen", &Main::set_launch_screen, &Main::get_launch_screen, main::launch_screen); + godot::register_signal
("monitor_loaded"); } -Main::Main() +alai::main::Main::Main() { } -Main::~Main() +alai::main::Main::~Main() { } -void Main::_init() +void alai::main::Main::_init() { - _os = OS::get_singleton(); - _input = Input::get_singleton(); - _project_settings = ProjectSettings::get_singleton(); - _resource_loader = ResourceLoader::get_singleton(); + _os = godot::OS::get_singleton(); + _input = godot::Input::get_singleton(); + _project_settings = godot::ProjectSettings::get_singleton(); + _resource_loader = godot::ResourceLoader::get_singleton(); - game_version = String(main::game_version.c_str()); + game_version = godot::String(main::game_version.c_str()); full_screen = main::full_screen; window_size = main::window_size; launch_screen = main::launch_screen; } -void Main::_ready() +void alai::main::Main::_ready() { auto success = _project_settings->load_resource_pack("monitor.pck"); if (success) { // Load monitor from pck - Godot::print("Monitor pck found, loading..."); + godot::Godot::print("Monitor pck found, loading..."); load_monitor(); } else if (_resource_loader->exists("res://monitor/Monitor.tscn")) @@ -75,19 +72,19 @@ void Main::_ready() if (success) { // Load crt from pck - Godot::print("CRT pck found, loading..."); - Ref crt_scene = _resource_loader->load("res://shaders/crt/crt.tscn"); + godot::Godot::print("CRT pck found, loading..."); + godot::Ref crt_scene = _resource_loader->load("res://shaders/crt/crt.tscn"); add_child(crt_scene->instance()); } else if (_resource_loader->exists("res://shaders/crt/crt.tscn")) { // Load crt from alai's pck - Ref crt_scene = _resource_loader->load("res://shaders/crt/crt.tscn"); + godot::Ref crt_scene = _resource_loader->load("res://shaders/crt/crt.tscn"); add_child(crt_scene->instance()); } } -void Main::_on_monitor_loaded() +void alai::main::Main::_on_monitor_loaded() { if (level != nullptr) { @@ -97,16 +94,16 @@ void Main::_on_monitor_loaded() } } -void Main::load_monitor() +void alai::main::Main::load_monitor() { - Ref monitor_scene = _resource_loader->load("res://monitor/Monitor.tscn"); + godot::Ref monitor_scene = _resource_loader->load("res://monitor/Monitor.tscn"); add_child(monitor_scene->instance()); auto monitor = get_node("Monitor"); monitor->connect("monitor_loaded", this, "_on_monitor_loaded"); get_tree()->set_pause(true); } -Node *Main::load_level() +godot::Node *alai::main::Main::load_level() { if (level != nullptr) { @@ -119,7 +116,7 @@ Node *Main::load_level() return nullptr; } -void Main::_physics_process(float delta) +void alai::main::Main::_physics_process(float delta) { if (_input->is_action_just_pressed("ui_cancel")) { @@ -127,52 +124,52 @@ void Main::_physics_process(float delta) } } -void Main::set_level(Ref level) +void alai::main::Main::set_level(godot::Ref level) { this->level = level; } -Ref Main::get_level() +godot::Ref alai::main::Main::get_level() { return this->level; } -void Main::set_game_version(String game_version) +void alai::main::Main::set_game_version(godot::String game_version) { this->game_version = game_version; } -String Main::get_game_version() +godot::String alai::main::Main::get_game_version() { return this->game_version; } -void Main::set_full_screen(bool full_screen) +void alai::main::Main::set_full_screen(bool full_screen) { this->full_screen = full_screen; } -bool Main::get_full_screen() +bool alai::main::Main::get_full_screen() { return this->full_screen; } -void Main::set_window_size(Vector2 window_size) +void alai::main::Main::set_window_size(godot::Vector2 window_size) { this-> window_size = window_size; } -Vector2 Main::get_window_size() +godot::Vector2 alai::main::Main::get_window_size() { return this->window_size; } -void Main::set_launch_screen(int8_t launch_screen) +void alai::main::Main::set_launch_screen(int8_t launch_screen) { this->launch_screen = launch_screen; } -int8_t Main::get_launch_screen() +int8_t alai::main::Main::get_launch_screen() { if (this->launch_screen == -1) { diff --git a/src/Main.h b/src/Main.h index 4c04cc9..a575dfb 100644 --- a/src/Main.h +++ b/src/Main.h @@ -3,20 +3,20 @@ #include #include +#include #include #include -#include #include -#include #include +#include #include /** - * @brief This is the godot namespace for all the code included in the library. + * @brief This is the alai namespace for all the code included in the game. * * @details This namespace is used a prefix when the Godot engine looks for classes, methods, and properties. */ -namespace godot +namespace alai { /** * @brief This namespace houses some global variables and the main class. @@ -38,7 +38,7 @@ namespace godot * @brief The default resolution for the game window. * */ - const Vector2 window_size = Vector2(1280, 720); + const godot::Vector2 window_size = godot::Vector2(1280, 720); /** * @brief The default screen the the game should open on. * @@ -49,44 +49,44 @@ namespace godot /** * @brief This class controls the Main node. * - * @details The main node is responsible for controling the window and the game iteself is a child of it. + * @details The main node is responsible for controlling the window and the game itself is a child of it. */ - class Main : public Node + class Main : public godot::Node { - GODOT_CLASS(Main, Node) + GODOT_CLASS(Main, godot::Node) private: /** * @brief OS singleton. * */ - OS *_os; + godot::OS *_os; /** * @brief Input singleton. * */ - Input *_input; + godot::Input *_input; /** * @brief ProjectSettings singleton. * */ - ProjectSettings *_project_settings; + godot::ProjectSettings *_project_settings; /** * @brief ResourceLoader singleton. * */ - ResourceLoader *_resource_loader; + godot::ResourceLoader *_resource_loader; /** * @brief The first level to load * */ - Ref level; + godot::Ref level; /** * @brief The current version of the game. * */ - String game_version; + godot::String game_version; /** * @brief If the window is full screen or not. * @@ -96,7 +96,7 @@ namespace godot * @brief The size of the window. * */ - Vector2 window_size; + godot::Vector2 window_size; /** * @brief The screen to launch the game on. * @@ -151,28 +151,28 @@ namespace godot * * @param[in] level The new level to load when starting. */ - void set_level(Ref level); + void set_level(godot::Ref level); /** * @brief Get the level object. * * @return Ref The level scene to load. */ - Ref get_level(); + godot::Ref get_level(); /** * @brief Set the game version object. * * @param[in] game_version The new version fo the game. */ - void set_game_version(String game_version); + void set_game_version(godot::String game_version); /** * @brief Get the game version object. * * @return String The current version of the game. */ - String get_game_version(); + godot::String get_game_version(); /** * @brief Set the full screen object. @@ -194,14 +194,14 @@ namespace godot * * @param[in] window_size The new window size. */ - void set_window_size(Vector2 window_size); + void set_window_size(godot::Vector2 window_size); /** * @brief Get the window size object. * * @return Vector2 The window size. */ - Vector2 get_window_size(); + godot::Vector2 get_window_size(); /** * @brief Set the launch screen object. @@ -217,9 +217,23 @@ namespace godot */ int8_t get_launch_screen(); + /** + * @brief Called when the monitor finishes loading. + * + */ void _on_monitor_loaded(); + /** + * @brief Loads the monitor and adds it to the scene. + * + */ void load_monitor(); + + /** + * @brief Loads the selected level. + * + * @return Node* The level node which we will later add the monitor to. + */ Node *load_level(); }; } diff --git a/src/godot.cpp b/src/godot.cpp index 1c56d09..a8a9017 100644 --- a/src/godot.cpp +++ b/src/godot.cpp @@ -1,24 +1,22 @@ #include -#include "state_machine/StateMachine.h" -#include "state_machine/State.h" -#include "Main.h" #include "CameraLimit.h" +#include "Main.h" +#include "state_machine/State.h" +#include "state_machine/StateMachine.h" #include "player/Player.h" #include "player/states/PlayerIdle.h" #include "player/states/PlayerMove.h" #include "player/states/PlayerJump.h" #include "player/states/PlayerFall.h" -using namespace godot; - /** * @brief This function connects the gdnative init function. * */ extern "C" void GDN_EXPORT godot_gdnative_init(godot_gdnative_init_options *o) { - Godot::gdnative_init(o); + godot::Godot::gdnative_init(o); } /** @@ -29,8 +27,8 @@ extern "C" void GDN_EXPORT godot_gdnative_terminate(godot_gdnative_terminate_opt { // This next line is a workaround to fix bug: // https://github.com/godotengine/godot/issues/48295 - Godot::nativescript_terminate(_RegisterState::nativescript_handle); - Godot::gdnative_terminate(o); + godot::Godot::nativescript_terminate(godot::_RegisterState::nativescript_handle); + godot::Godot::gdnative_terminate(o); } /** @@ -39,14 +37,15 @@ extern "C" void GDN_EXPORT godot_gdnative_terminate(godot_gdnative_terminate_opt */ extern "C" void GDN_EXPORT godot_nativescript_init(void *handle) { - Godot::nativescript_init(handle); - register_class(); - register_class(); - register_class(); - register_class(); - register_class(); - register_class(); - register_class(); - register_class(); - register_class(); + godot::Godot::nativescript_init(handle); + + godot::register_class(); + godot::register_class(); + godot::register_class(); + godot::register_class(); + godot::register_class(); + godot::register_class(); + godot::register_class(); + godot::register_class(); + godot::register_class(); } diff --git a/src/player/Player.cpp b/src/player/Player.cpp index 868156b..38348a2 100644 --- a/src/player/Player.cpp +++ b/src/player/Player.cpp @@ -1,48 +1,45 @@ #include "player/Player.h" #include -#include -#include +#include +#include #include #include +#include #include -#include -#include +#include -using namespace godot; -using namespace player; - -void Player::_register_methods() +void alai::player::Player::_register_methods() { - register_method("_ready", &Player::_ready); - register_method("_physics_process", &Player::_physics_process); - register_method("set_velocity", &Player::set_velocity); - register_method("get_velocity", &Player::get_velocity); - register_method("_on_player_touched", &Player::_on_player_touched); - register_method("_on_monitor_loaded", &Player::_on_monitor_loaded); - //register_property>("sprite_frames", &Player::set_sprite_frames, &Player::get_sprite_frames, Ref(), GODOT_METHOD_RPC_MODE_DISABLED, GODOT_PROPERTY_USAGE_DEFAULT, GODOT_PROPERTY_HINT_RESOURCE_TYPE, String("SpriteFrames")); - register_property("speed", &Player::set_speed, &Player::get_speed, player::speed); - register_property("jump_force", &Player::set_jump_force, &Player::get_jump_force, player::jump_force); - register_property("bounce_force", &Player::set_bounce_force, &Player::get_bounce_force, player::bounce_force); - register_property("gravity", &Player::set_gravity, &Player::get_gravity, player::gravity); - register_property("run_speed", &Player::set_run_speed, &Player::get_run_speed, player::run_speed); - register_property("double_jump", &Player::set_double_jump, &Player::get_double_jump, player::double_jump); - register_signal("object_created", "name", GODOT_VARIANT_TYPE_STRING, "state", GODOT_VARIANT_TYPE_STRING, "position", GODOT_VARIANT_TYPE_VECTOR2, "velocity", GODOT_VARIANT_TYPE_VECTOR2); - register_signal("object_updated", "name", GODOT_VARIANT_TYPE_STRING, "state", GODOT_VARIANT_TYPE_STRING, "position", GODOT_VARIANT_TYPE_VECTOR2, "velocity", GODOT_VARIANT_TYPE_VECTOR2); - register_signal("object_removed", "name", GODOT_VARIANT_TYPE_STRING); + godot::register_method("_ready", &Player::_ready); + godot::register_method("_physics_process", &Player::_physics_process); + godot::register_method("set_velocity", &Player::set_velocity); + godot::register_method("get_velocity", &Player::get_velocity); + godot::register_method("_on_player_touched", &Player::_on_player_touched); + godot::register_method("_on_monitor_loaded", &Player::_on_monitor_loaded); + //godot::register_property>("sprite_frames", &Player::set_sprite_frames, &Player::get_sprite_frames, godot::Ref(), GODOT_METHOD_RPC_MODE_DISABLED, GODOT_PROPERTY_USAGE_DEFAULT, GODOT_PROPERTY_HINT_RESOURCE_TYPE, godot::String("SpriteFrames")); + godot::register_property("speed", &Player::set_speed, &Player::get_speed, player::speed); + godot::register_property("jump_force", &Player::set_jump_force, &Player::get_jump_force, player::jump_force); + godot::register_property("bounce_force", &Player::set_bounce_force, &Player::get_bounce_force, player::bounce_force); + godot::register_property("gravity", &Player::set_gravity, &Player::get_gravity, player::gravity); + godot::register_property("run_speed", &Player::set_run_speed, &Player::get_run_speed, player::run_speed); + godot::register_property("double_jump", &Player::set_double_jump, &Player::get_double_jump, player::double_jump); + godot::register_signal("object_created", "name", GODOT_VARIANT_TYPE_STRING, "state", GODOT_VARIANT_TYPE_STRING, "position", GODOT_VARIANT_TYPE_VECTOR2, "velocity", GODOT_VARIANT_TYPE_VECTOR2); + godot::register_signal("object_updated", "name", GODOT_VARIANT_TYPE_STRING, "state", GODOT_VARIANT_TYPE_STRING, "position", GODOT_VARIANT_TYPE_VECTOR2, "velocity", GODOT_VARIANT_TYPE_VECTOR2); + godot::register_signal("object_removed", "name", GODOT_VARIANT_TYPE_STRING); } -Player::Player() +alai::player::Player::Player() { } -Player::~Player() +alai::player::Player::~Player() { } -void Player::_init() +void alai::player::Player::_init() { - _resource_loader = ResourceLoader::get_singleton(); + _resource_loader = godot::ResourceLoader::get_singleton(); //sprite_frames = _resource_loader->load(player::sprite_frames); set_speed(player::speed); @@ -54,23 +51,23 @@ void Player::_init() coins = 0; - velocity = Vector2(); + velocity = godot::Vector2(); } -void Player::_ready() +void alai::player::Player::_ready() { - animated_sprite = get_node("AnimatedSprite"); + animated_sprite = get_node("AnimatedSprite"); if (!animated_sprite) { ERR_PRINT("AnimateSprite not found!"); - animated_sprite = AnimatedSprite()._new(); + animated_sprite = godot::AnimatedSprite()._new(); } //animated_sprite->set_sprite_frames(sprite_frames); auto node = get_parent()->find_node("Middleground"); if (node != nullptr) { - auto tile_map = Object::cast_to(node); + auto tile_map = Object::cast_to(node); get_parent()->call_deferred("remove_child", this); tile_map->call_deferred("add_child", this); } @@ -80,7 +77,7 @@ void Player::_ready() } } -void Player::_on_monitor_loaded() { +void alai::player::Player::_on_monitor_loaded() { auto object_node = get_tree()->get_root()->find_node("Monitor", true, false); if (object_node != nullptr) { @@ -105,22 +102,22 @@ void Player::_on_monitor_loaded() { #endif } -void Player::_physics_process(float delta) +void alai::player::Player::_physics_process(float delta) { velocity.y += get_gravity(); - auto snap_vector = Vector2::ZERO; + auto snap_vector = godot::Vector2::ZERO; if (!is_on_floor()) { - snap_vector = Vector2::DOWN * 20.0; + snap_vector = godot::Vector2::DOWN * 20.0; } - auto platform_detector = get_node("PlatformDetector"); + auto platform_detector = get_node("PlatformDetector"); auto is_on_platform = platform_detector->is_colliding(); - velocity = move_and_slide_with_snap(velocity, snap_vector, Vector2::UP, !is_on_platform, 4, 0.9, false); + velocity = move_and_slide_with_snap(velocity, snap_vector, godot::Vector2::UP, !is_on_platform, 4, 0.9, false); //velocity = move_and_slide(velocity, Vector2::UP, !is_on_platform); - velocity.x = Math::lerp((float) velocity.x, (float) 0, (float) 0.2); + velocity.x = godot::Math::lerp((float) velocity.x, (float) 0, (float) 0.2); auto count = get_slide_count(); for (int64_t i = 0; i < count; i++) @@ -128,7 +125,7 @@ void Player::_physics_process(float delta) auto collision = get_slide_collision(i); auto collision_object = collision->get_collider(); auto collider = Object::cast_to(collision_object); - if (collider->is_in_group("squashable") && Vector2::UP.dot(collision->get_normal()) > 0.1) + if (collider->is_in_group("squashable") && godot::Vector2::UP.dot(collision->get_normal()) > 0.1) { collider->call_deferred("squash"); /*auto dup_node = collider->duplicate(); @@ -147,7 +144,7 @@ void Player::_physics_process(float delta) }*/ velocity.y = -get_bounce_force(); } - else if (collider->is_in_group("enemy") && (collider->is_in_group("rideable") && Vector2::DOWN.dot(collision->get_normal()) > 0)) + else if (collider->is_in_group("enemy") && (collider->is_in_group("rideable") && godot::Vector2::DOWN.dot(collision->get_normal()) > 0)) { _on_player_touched(); } @@ -158,23 +155,23 @@ void Player::_physics_process(float delta) } // Clamp the player's position inside the camera's limits - auto camera = get_node("Camera2D"); + auto camera = get_node("Camera2D"); auto position = get_global_position(); - auto sprite_node = get_node("AnimatedSprite"); + auto sprite_node = get_node("AnimatedSprite"); if (sprite_node != nullptr) { - position.x = Math::clamp((float) position.x, (float) camera->get_limit(0), (float) camera->get_limit(2) - sprite_node->get_sprite_frames()->get_frame("idle", 0)->get_size().x); - position.y = Math::clamp((float) position.y, (float) camera->get_limit(1), (float) camera->get_limit(3) + sprite_node->get_sprite_frames()->get_frame("idle", 0)->get_size().y); + position.x = godot::Math::clamp((float) position.x, (float) camera->get_limit(0), (float) camera->get_limit(2) - sprite_node->get_sprite_frames()->get_frame("idle", 0)->get_size().x); + position.y = godot::Math::clamp((float) position.y, (float) camera->get_limit(1), (float) camera->get_limit(3) + sprite_node->get_sprite_frames()->get_frame("idle", 0)->get_size().y); } else { WARN_PRINT("Could not clamp player based on sprite frame size!"); - position.x = Math::clamp((float) position.x, (float) camera->get_limit(0), (float) camera->get_limit(2)); - position.y = Math::clamp((float) position.y, (float) camera->get_limit(1), (float) camera->get_limit(3)); + position.x = godot::Math::clamp((float) position.x, (float) camera->get_limit(0), (float) camera->get_limit(2)); + position.y = godot::Math::clamp((float) position.y, (float) camera->get_limit(1), (float) camera->get_limit(3)); } set_global_position(position); // If the player is off screen reload the scene - auto notifier = get_node("Camera2D/VisibilityNotifier2D"); + auto notifier = get_node("Camera2D/VisibilityNotifier2D"); if (notifier != nullptr) { if (!notifier->is_on_screen()) @@ -182,9 +179,9 @@ void Player::_physics_process(float delta) if (get_parent()->get_class() == "TileMap") { auto error = get_tree()->change_scene("res://Main.tscn"); - if (error != Error::OK) + if (error != godot::Error::OK) { - ERR_PRINT(String().num((int) error) + " Could not load scene!"); + ERR_PRINT(godot::String().num((int) error) + " Could not load scene!"); } } } @@ -201,91 +198,91 @@ void Player::_physics_process(float delta) } } -void Player::set_sprite_frames(Ref sprite_frames) +void alai::player::Player::set_sprite_frames(godot::Ref sprite_frames) { this->sprite_frames = sprite_frames; } -Ref Player::get_sprite_frames() +godot::Ref alai::player::Player::get_sprite_frames() { return this->sprite_frames; } -void Player::set_speed(float speed) +void alai::player::Player::set_speed(float speed) { this->speed = speed; } -float Player::get_speed() +float alai::player::Player::get_speed() { return this->speed; } -void Player::set_jump_force(float jump_force) +void alai::player::Player::set_jump_force(float jump_force) { this->jump_force = jump_force; } -float Player::get_jump_force() +float alai::player::Player::get_jump_force() { return this->jump_force; } -void Player::set_bounce_force(float bounce_force) +void alai::player::Player::set_bounce_force(float bounce_force) { this->bounce_force = bounce_force; } -float Player::get_bounce_force() +float alai::player::Player::get_bounce_force() { return this->bounce_force; } -void Player::set_gravity(float gravity) +void alai::player::Player::set_gravity(float gravity) { this->gravity = gravity; } -float Player::get_gravity() +float alai::player::Player::get_gravity() { return this->gravity; } -void Player::set_run_speed(float run_speed) +void alai::player::Player::set_run_speed(float run_speed) { this->run_speed = run_speed; } -float Player::get_run_speed() +float alai::player::Player::get_run_speed() { return this->run_speed; } -void Player::set_double_jump(bool double_jump) +void alai::player::Player::set_double_jump(bool double_jump) { this->double_jump = double_jump; } -bool Player::get_double_jump() +bool alai::player::Player::get_double_jump() { return this->double_jump; } -void Player::set_velocity(Vector2 velocity) +void alai::player::Player::set_velocity(godot::Vector2 velocity) { this->velocity = velocity; } -Vector2 Player::get_velocity() +godot::Vector2 alai::player::Player::get_velocity() { return this->velocity; } -void Player::_on_player_touched() +void alai::player::Player::_on_player_touched() { auto error = get_tree()->change_scene("res://Main.tscn"); - if (error != Error::OK) + if (error != godot::Error::OK) { - ERR_PRINT(String().num((int) error) + " Could not load scene!"); + ERR_PRINT(godot::String().num((int) error) + " Could not load scene!"); } } diff --git a/src/player/Player.h b/src/player/Player.h index ee505a0..cedcfb5 100644 --- a/src/player/Player.h +++ b/src/player/Player.h @@ -1,14 +1,13 @@ -#ifndef ALAI_PLAYER_H -#define ALAI_PLAYER_H +#ifndef ALAI_PLAYER_PLAYER_H +#define ALAI_PLAYER_PLAYER_H +#include #include #include -#include -#include -#include #include +#include -namespace godot +namespace alai { /** * @brief This namespace contains the global variables related to the player and its states. @@ -57,27 +56,27 @@ namespace godot * * @details This class allows the player to move, run, and jump as well as controls the sprite displayed for those actions. */ - class Player : public KinematicBody2D + class Player : public godot::KinematicBody2D { - GODOT_CLASS(Player, KinematicBody2D) + GODOT_CLASS(Player, godot::KinematicBody2D) private: /** * @brief ResourceLoader singleton. * */ - ResourceLoader *_resource_loader; + godot::ResourceLoader *_resource_loader; /** * @brief The animated sprite connected to the KinematicBody2D. * */ - AnimatedSprite *animated_sprite; + godot::AnimatedSprite *animated_sprite; /** * @brief The sprite frames used in the animated sprite. * */ - Ref sprite_frames; + godot::Ref sprite_frames; /** * @brief The coins the player has collected. * @@ -87,7 +86,7 @@ namespace godot * @brief The velocity at which moves the player moves. * */ - Vector2 velocity; + godot::Vector2 velocity; /** * @brief The speed that the player moves in. * @@ -167,14 +166,14 @@ namespace godot * * @param[in] sprite_frames The new sprite frame. */ - void set_sprite_frames(Ref sprite_frames); + void set_sprite_frames(godot::Ref sprite_frames); /** * @brief Get the sprite frames object. * * @return Ref A reference to the sprite frames object. */ - Ref get_sprite_frames(); + godot::Ref get_sprite_frames(); /** * @brief Set the speed object. @@ -266,14 +265,14 @@ namespace godot * * @param[in] velocity The new velocity of the player. */ - void set_velocity(Vector2 velocity); + void set_velocity(godot::Vector2 velocity); /** * @brief Get the velocity object. * * @return Vector2 Returns the velocity of the player. */ - Vector2 get_velocity(); + godot::Vector2 get_velocity(); /** * @brief This function is called when an enemy touches the player. @@ -281,6 +280,10 @@ namespace godot */ void _on_player_touched(); + /** + * @brief Called when the monitor is loaded to connect the player to it for tracking. + * + */ void _on_monitor_loaded(); }; } diff --git a/src/player/states/PlayerFall.cpp b/src/player/states/PlayerFall.cpp index c3e6ff4..d218305 100644 --- a/src/player/states/PlayerFall.cpp +++ b/src/player/states/PlayerFall.cpp @@ -1,45 +1,42 @@ #include "player/states/PlayerFall.h" #include "player/Player.h" -using namespace godot; -using namespace player; - -void PlayerFall::_register_methods() +void alai::player::PlayerFall::_register_methods() { register_method("_state_enter", &PlayerFall::_state_enter); register_method("_state_exit", &PlayerFall::_state_exit); register_method("_physics_process", &PlayerFall::_physics_process); } -PlayerFall::PlayerFall() +alai::player::PlayerFall::PlayerFall() { } -PlayerFall::~PlayerFall() +alai::player::PlayerFall::~PlayerFall() { } -void PlayerFall::_init() +void alai::player::PlayerFall::_init() { - _input = Input::get_singleton(); + _input = godot::Input::get_singleton(); } -void PlayerFall::_state_enter() +void alai::player::PlayerFall::_state_enter() { - animated_sprite = get_parent()->get_node("AnimatedSprite"); + animated_sprite = get_parent()->get_node("AnimatedSprite"); animated_sprite->stop(); animated_sprite->set_animation("air"); } -void PlayerFall::_state_exit() +void alai::player::PlayerFall::_state_exit() { animated_sprite->set_animation("move"); animated_sprite->set_frame(1); } -void PlayerFall::_physics_process(float delta) +void alai::player::PlayerFall::_physics_process(float delta) { - auto parent = Object::cast_to(get_parent()); + auto parent = Object::cast_to(get_parent()); if (parent->is_on_floor()) { diff --git a/src/player/states/PlayerFall.h b/src/player/states/PlayerFall.h index b7d774a..5fbd54a 100644 --- a/src/player/states/PlayerFall.h +++ b/src/player/states/PlayerFall.h @@ -1,13 +1,13 @@ -#ifndef JUEGO_PLAYER_FALL_H -#define JUEGO_PLAYER_FALL_H +#ifndef ALAI_PLAYER_STATES_PLAYER_FALL_H +#define ALAI_PLAYER_STATES_PLAYER_FALL_H #include "state_machine/State.h" +#include #include #include -#include -namespace godot +namespace alai { namespace player { @@ -24,13 +24,13 @@ namespace godot * @brief Input singleton. * */ - Input *_input; + godot::Input *_input; /** * @brief The animated sprite connected to the Player. * */ - AnimatedSprite *animated_sprite; + godot::AnimatedSprite *animated_sprite; public: /** diff --git a/src/player/states/PlayerIdle.cpp b/src/player/states/PlayerIdle.cpp index 026b5cf..4a03de4 100644 --- a/src/player/states/PlayerIdle.cpp +++ b/src/player/states/PlayerIdle.cpp @@ -1,43 +1,40 @@ #include "player/states/PlayerIdle.h" #include "player/Player.h" -using namespace godot; -using namespace player; - -void PlayerIdle::_register_methods() +void alai::player::PlayerIdle::_register_methods() { register_method("_state_enter", &PlayerIdle::_state_enter); register_method("_state_exit", &PlayerIdle::_state_exit); register_method("_physics_process", &PlayerIdle::_physics_process); } -PlayerIdle::PlayerIdle() +alai::player::PlayerIdle::PlayerIdle() { } -PlayerIdle::~PlayerIdle() +alai::player::PlayerIdle::~PlayerIdle() { } -void PlayerIdle::_init() +void alai::player::PlayerIdle::_init() { - _input = Input::get_singleton(); + _input = godot::Input::get_singleton(); } -void PlayerIdle::_state_enter() +void alai::player::PlayerIdle::_state_enter() { - animated_sprite = get_parent()->get_node("AnimatedSprite"); + animated_sprite = get_parent()->get_node("AnimatedSprite"); animated_sprite->stop(); animated_sprite->set_animation("idle"); } -void PlayerIdle::_state_exit() +void alai::player::PlayerIdle::_state_exit() { } -void PlayerIdle::_physics_process(float delta) +void alai::player::PlayerIdle::_physics_process(float delta) { - auto parent = Object::cast_to(get_parent()); + auto parent = Object::cast_to(get_parent()); if (_input->is_action_pressed("right")) { diff --git a/src/player/states/PlayerIdle.h b/src/player/states/PlayerIdle.h index 8dc46d2..8a458b4 100644 --- a/src/player/states/PlayerIdle.h +++ b/src/player/states/PlayerIdle.h @@ -1,14 +1,13 @@ -#ifndef JUEGO_PLAYER_IDLE_H -#define JUEGO_PLAYER_IDLE_H +#ifndef ALAI_PLAYER_STATES_PLAYER_IDLE_H +#define ALAI_PLAYER_STATES_PLAYER_IDLE_H #include "state_machine/State.h" -#include -#include -#include #include +#include +#include -namespace godot +namespace alai { namespace player { @@ -25,12 +24,12 @@ namespace godot * @brief Input singleton. * */ - Input *_input; + godot::Input *_input; /** * @brief The animated sprite of the Player. * */ - AnimatedSprite *animated_sprite; + godot::AnimatedSprite *animated_sprite; public: /** diff --git a/src/player/states/PlayerJump.cpp b/src/player/states/PlayerJump.cpp index e9f9082..4a77147 100644 --- a/src/player/states/PlayerJump.cpp +++ b/src/player/states/PlayerJump.cpp @@ -3,35 +3,32 @@ #include -using namespace godot; -using namespace player; - -void PlayerJump::_register_methods() +void alai::player::PlayerJump::_register_methods() { register_method("_state_enter", &PlayerJump::_state_enter); register_method("_state_exit", &PlayerJump::_state_exit); register_method("_physics_process", &PlayerJump::_physics_process); } -PlayerJump::PlayerJump() +alai::player::PlayerJump::PlayerJump() { } -PlayerJump::~PlayerJump() +alai::player::PlayerJump::~PlayerJump() { } -void PlayerJump::_init() +void alai::player::PlayerJump::_init() { - _input = Input::get_singleton(); + _input = godot::Input::get_singleton(); } -void PlayerJump::_state_enter(const String state) +void alai::player::PlayerJump::_state_enter(const godot::String state) { - auto jump_sound = get_parent()->get_node("Sounds/Jump"); + auto jump_sound = get_parent()->get_node("Sounds/Jump"); jump_sound->play(); - animated_sprite = get_parent()->get_node("AnimatedSprite"); + animated_sprite = get_parent()->get_node("AnimatedSprite"); animated_sprite->stop(); animated_sprite->set_animation("air"); @@ -44,21 +41,21 @@ void PlayerJump::_state_enter(const String state) double_jumped = false; } - auto parent = Object::cast_to(get_parent()); + auto parent = Object::cast_to(get_parent()); auto velocity = parent->get_velocity(); velocity.y = -parent->get_jump_force(); parent->set_velocity(velocity); } -void PlayerJump::_state_exit() +void alai::player::PlayerJump::_state_exit() { animated_sprite->set_animation("move"); animated_sprite->set_frame(1); } -void PlayerJump::_physics_process(float delta) +void alai::player::PlayerJump::_physics_process(float delta) { - auto parent = Object::cast_to(get_parent()); + auto parent = Object::cast_to(get_parent()); if (parent->is_on_floor()) { get_state_machine()->change("Move"); diff --git a/src/player/states/PlayerJump.h b/src/player/states/PlayerJump.h index 4640085..b3c67ed 100644 --- a/src/player/states/PlayerJump.h +++ b/src/player/states/PlayerJump.h @@ -1,13 +1,13 @@ -#ifndef JUEGO_PLAYER_JUMP_H -#define JUEGO_PLAYER_JUMP_H +#ifndef ALAI_PLAYER_STATES_PLAYER_JUMP_H +#define ALAI_PLAYER_STATES_PLAYER_JUMP_H #include "state_machine/State.h" +#include #include #include -#include -namespace godot +namespace alai { namespace player { @@ -24,12 +24,12 @@ namespace godot * @brief Input singleton. * */ - Input *_input; + godot::Input *_input; /** * @brief The animated sprite connected to the Player. * */ - AnimatedSprite *animated_sprite; + godot::AnimatedSprite *animated_sprite; /** * @brief If the player has already performed a double jump or not. * @@ -70,7 +70,7 @@ namespace godot * * @param[in] state The previous state before this one was entered. */ - void _state_enter(const String state); + void _state_enter(const godot::String state); /** * @brief Called when the player exits the jump state. diff --git a/src/player/states/PlayerMove.cpp b/src/player/states/PlayerMove.cpp index 77df13e..7ad60ff 100644 --- a/src/player/states/PlayerMove.cpp +++ b/src/player/states/PlayerMove.cpp @@ -1,43 +1,40 @@ #include "player/states/PlayerMove.h" #include "player/Player.h" -using namespace godot; -using namespace player; - -void PlayerMove::_register_methods() +void alai::player::PlayerMove::_register_methods() { register_method("_state_enter", &PlayerMove::_state_enter); register_method("_state_exit", &PlayerMove::_state_exit); register_method("_physics_process", &PlayerMove::_physics_process); } -PlayerMove::PlayerMove() +alai::player::PlayerMove::PlayerMove() { } -PlayerMove::~PlayerMove() +alai::player::PlayerMove::~PlayerMove() { } -void PlayerMove::_init() +void alai::player::PlayerMove::_init() { - _input = Input::get_singleton(); + _input = godot::Input::get_singleton(); } -void PlayerMove::_state_enter() +void alai::player::PlayerMove::_state_enter() { - animated_sprite = get_parent()->get_node("AnimatedSprite"); + animated_sprite = get_parent()->get_node("AnimatedSprite"); animated_sprite->set_animation("move"); animated_sprite->play(); } -void PlayerMove::_state_exit() +void alai::player::PlayerMove::_state_exit() { } -void PlayerMove::_physics_process(float delta) +void alai::player::PlayerMove::_physics_process(float delta) { - auto parent = Object::cast_to(get_parent()); + auto parent = Object::cast_to(get_parent()); auto direction_pressed = false; diff --git a/src/player/states/PlayerMove.h b/src/player/states/PlayerMove.h index 610819d..a436a95 100644 --- a/src/player/states/PlayerMove.h +++ b/src/player/states/PlayerMove.h @@ -1,5 +1,5 @@ -#ifndef JUEGO_PLAYER_MOVE_H -#define JUEGO_PLAYER_MOVE_H +#ifndef ALAI_PLAYER_STATES_PLAYER_MOVE_H +#define ALAI_PLAYER_STATES_PLAYER_MOVE_H #include "state_machine/State.h" @@ -7,7 +7,7 @@ #include #include -namespace godot +namespace alai { namespace player { @@ -24,12 +24,12 @@ namespace godot * @brief Input singleton. * */ - Input *_input; + godot::Input *_input; /** * @brief The animated sprite of the Player. * */ - AnimatedSprite *animated_sprite; + godot::AnimatedSprite *animated_sprite; public: /** diff --git a/src/state_machine/State.cpp b/src/state_machine/State.cpp index 2763449..1c66968 100644 --- a/src/state_machine/State.cpp +++ b/src/state_machine/State.cpp @@ -1,8 +1,6 @@ #include "state_machine/State.h" -using namespace godot; - -void State::_register_methods() +void alai::State::_register_methods() { register_method("set_parent", &State::set_parent); register_method("get_parent", &State::get_parent); @@ -11,44 +9,44 @@ void State::_register_methods() register_method("_state_exit", &State::_state_exit); } -State::State() +alai::State::State() { } -State::~State() +alai::State::~State() { } -void State::_init() +void alai::State::_init() { } -void State::_state_enter(const String state, const Array args) +void alai::State::_state_enter(const godot::String state, const godot::Array args) { WARN_PRINT("State " + get_state_machine()->get_current_state() + " is missing its _state_enter method!"); } -void State::_state_exit(const String state, const Array args) +void alai::State::_state_exit(const godot::String state, const godot::Array args) { WARN_PRINT("State " + get_state_machine()->get_current_state() + " is missing its _state_exit method!"); } -void State::set_parent(Node *parent) +void alai::State::set_parent(Node *parent) { this->parent = parent; } -Node *State::get_parent() +godot::Node *alai::State::get_parent() { return parent; } -void State::set_state_machine(StateMachine *state_machine) +void alai::State::set_state_machine(alai::StateMachine *state_machine) { this->state_machine = state_machine; } -StateMachine *State::get_state_machine() +alai::StateMachine *alai::State::get_state_machine() { return this->state_machine; } diff --git a/src/state_machine/State.h b/src/state_machine/State.h index 2576f6a..f8f04b4 100644 --- a/src/state_machine/State.h +++ b/src/state_machine/State.h @@ -1,12 +1,11 @@ -#ifndef JUEGO_STATE_H -#define JUEGO_STATE_H +#ifndef ALAI_STATE_MACHINE_STATE_H +#define ALAI_STATE_MACHINE_STATE_H #include "state_machine/StateMachine.h" #include -#include -namespace godot +namespace alai { /** * @brief This class provides a virtual template state that real states should extend from and override. @@ -21,7 +20,7 @@ namespace godot * @brief The state's parent, this is the node 1 level above the state machine. * */ - Node *parent; + godot::Node *parent; /** * @brief The state machine itself, used to handle all state related work. * @@ -61,7 +60,7 @@ namespace godot * @param[in] state This will contain the previous state. * @param[in] args The arguments passed to the state. */ - virtual void _state_enter(const String state, const Array args = Array()); + virtual void _state_enter(const godot::String state, const godot::Array args = godot::Array()); /** * @brief This is called when a state is exited. @@ -69,14 +68,14 @@ namespace godot * @param[in] state The state we are going to. * @param[in] args The arguments passed to the state. */ - virtual void _state_exit(const String state, const Array args = Array()); + virtual void _state_exit(const godot::String state, const godot::Array args = godot::Array()); /** * @brief Set the parent object. * * @param[in] parent The parent of the state. */ - virtual void set_parent(Node *parent) final; + virtual void set_parent(godot::Node *parent) final; /** * @brief Get the parent object. diff --git a/src/state_machine/StateMachine.cpp b/src/state_machine/StateMachine.cpp index 73b1f9d..ef6cb34 100644 --- a/src/state_machine/StateMachine.cpp +++ b/src/state_machine/StateMachine.cpp @@ -1,35 +1,33 @@ #include "state_machine/StateMachine.h" #include "state_machine/State.h" -using namespace godot; - -void StateMachine::_register_methods() +void alai::StateMachine::_register_methods() { - register_method("_ready", &StateMachine::_ready); - register_method("_on_StateMachine_tree_entered", &StateMachine::_on_StateMachine_tree_entered); - register_method("_on_StateMachine_tree_exiting", &StateMachine::_on_StateMachine_tree_exiting); - register_property("default_state", &StateMachine::set_default_state, &StateMachine::get_default_state, String()); - register_property("debug", &StateMachine::set_debug, &StateMachine::get_debug, false); - register_signal("state_entered", "state", GODOT_VARIANT_TYPE_STRING); - register_signal("state_exited", "state", GODOT_VARIANT_TYPE_STRING); - register_signal("state_restarted", "state", GODOT_VARIANT_TYPE_STRING); + godot::register_method("_ready", &StateMachine::_ready); + godot::register_method("_on_StateMachine_tree_entered", &StateMachine::_on_StateMachine_tree_entered); + godot::register_method("_on_StateMachine_tree_exiting", &StateMachine::_on_StateMachine_tree_exiting); + godot::register_property("default_state", &StateMachine::set_default_state, &StateMachine::get_default_state, godot::String()); + godot::register_property("debug", &StateMachine::set_debug, &StateMachine::get_debug, false); + godot::register_signal("state_entered", "state", GODOT_VARIANT_TYPE_STRING); + godot::register_signal("state_exited", "state", GODOT_VARIANT_TYPE_STRING); + godot::register_signal("state_restarted", "state", GODOT_VARIANT_TYPE_STRING); } -StateMachine::StateMachine() +alai::StateMachine::StateMachine() { } -StateMachine::~StateMachine() +alai::StateMachine::~StateMachine() { } -void StateMachine::_init() +void alai::StateMachine::_init() { - set_default_state(String()); + set_default_state(godot::String()); set_debug(false); } -void StateMachine::_ready() +void alai::StateMachine::_ready() { connect("tree_entered", this, "_on_StateMachine_tree_entered"); connect("tree_exiting", this, "_on_StateMachine_tree_exiting"); @@ -46,7 +44,7 @@ void StateMachine::_ready() setup(); } -void StateMachine::setup() +void alai::StateMachine::setup() { auto children = get_children(); @@ -89,7 +87,7 @@ void StateMachine::setup() } } -void StateMachine::add_states() +void alai::StateMachine::add_states() { auto children = get_children(); for (uint8_t i = 0; i < children.size(); i++) @@ -99,12 +97,12 @@ void StateMachine::add_states() } } -void StateMachine::add_state(const String state, Node *child) +void alai::StateMachine::add_state(const godot::String state, Node *child) { states[state] = child; } -bool StateMachine::is_current(const String state) +bool alai::StateMachine::is_current(const godot::String state) { if (get_current_state() == "") { @@ -116,19 +114,19 @@ bool StateMachine::is_current(const String state) } } -bool StateMachine::has(const String state) +bool alai::StateMachine::has(const godot::String state) { return states.has(state); } -void StateMachine::restart(const String state, const Array& args) +void alai::StateMachine::restart(const godot::String state, const godot::Array& args) { this->call("_state_exit", state, args); this->call("_state_enter", state, args); this->emit_signal("state_restarted", get_current_state()); } -void StateMachine::change(const String state, const Array &args) +void alai::StateMachine::change(const godot::String state, const godot::Array &args) { if (is_current(state)) { @@ -143,7 +141,7 @@ void StateMachine::change(const String state, const Array &args) auto previous_state = get_current_state(); - Variant exiting; + godot::Variant exiting; Node *state_node = Object::cast_to(this->states[previous_state]); if (state_node) { @@ -171,7 +169,7 @@ void StateMachine::change(const String state, const Array &args) this->emit_signal("state_exited", get_current_state()); if (debug) { - Godot::print(get_current_state() + " exited!"); + godot::Godot::print(get_current_state() + " exited!"); } } @@ -199,11 +197,11 @@ void StateMachine::change(const String state, const Array &args) this->emit_signal("state_entered", get_current_state()); if (debug) { - Godot::print(get_current_state() + " entered!"); + godot::Godot::print(get_current_state() + " entered!"); } } -Variant StateMachine::call(const String method, const Array &args) +godot::Variant alai::StateMachine::call(const godot::String method, const godot::Array &args) { auto node = Object::cast_to(states[get_current_state()].operator Object*()); if (node) @@ -215,57 +213,57 @@ Variant StateMachine::call(const String method, const Array &args) else { WARN_PRINT("The state " + get_current_state() + " doesn't contain the method " + method + "!"); - return Variant(); + return godot::Variant(); } } else { ERR_PRINT("Could not get current state node for " + get_current_state() + "!"); - return Variant(); + return godot::Variant(); } } -Variant StateMachine::_call(const String method, const Array &args) +godot::Variant alai::StateMachine::_call(const godot::String method, const godot::Array &args) { return this->call(method, args); } -void StateMachine::set_default_state(const String default_state) +void alai::StateMachine::set_default_state(const godot::String default_state) { this->default_state = default_state; } -String StateMachine::get_default_state() +godot::String alai::StateMachine::get_default_state() { return this->default_state; } -void StateMachine::set_current_state(const String current_sate) +void alai::StateMachine::set_current_state(const godot::String current_sate) { this->current_state = current_sate; } -String StateMachine::get_current_state() +godot::String alai::StateMachine::get_current_state() { return this->current_state; } -void StateMachine::set_debug(bool debug) +void alai::StateMachine::set_debug(bool debug) { this->debug = debug; } -bool StateMachine::get_debug() +bool alai::StateMachine::get_debug() { return this->debug; } -void StateMachine::_on_StateMachine_tree_entered() +void alai::StateMachine::_on_StateMachine_tree_entered() { setup(); } -void StateMachine::_on_StateMachine_tree_exiting() +void alai::StateMachine::_on_StateMachine_tree_exiting() { auto keys = states.keys(); for (uint8_t i = 0; i < keys.size(); i++) diff --git a/src/state_machine/StateMachine.h b/src/state_machine/StateMachine.h index 8c42f55..36e3e4f 100644 --- a/src/state_machine/StateMachine.h +++ b/src/state_machine/StateMachine.h @@ -1,32 +1,32 @@ -#ifndef JUEGO_STATE_MACHINE_H -#define JUEGO_STATE_MACHINE_H +#ifndef ALAI_STATE_MACHINE_STATE_MACHINE_H +#define ALAI_STATE_MACHINE_STATE_MACHINE_H #include #include -namespace godot +namespace alai { /** * @brief This class provides a finite state machine that can be used with any scene and node. * */ - class StateMachine : public Node + class StateMachine : public godot::Node { - GODOT_CLASS(StateMachine, Node) + GODOT_CLASS(StateMachine, godot::Node) private: /** * @brief The parent node which is one level above the state machine. * */ - Node *parent; + godot::Node *parent; /** * @brief The default state for the state machine to run. * * @details If this is not set, the state machine will try to run the first state node. * If no state nodes are present, an error will be printed and the state machine will not work. */ - String default_state; + godot::String default_state; /** * @brief If set to true the state machine will print a message showing when it enters or exits a state. * @@ -36,12 +36,12 @@ namespace godot * @brief The current state the machine is in. * */ - String current_state; + godot::String current_state; /** * @brief A list of the states in the state machine. * */ - Dictionary states; + godot::Dictionary states; /** * @brief This adds all nodes of the states machine as states in the machine. @@ -55,14 +55,14 @@ namespace godot * @param[in] state The new state. * @param[in] child The godot node which represents the state. */ - void add_state(const String state, Node *child); + void add_state(const godot::String state, godot::Node *child); /** * @brief Set the current state object. * * @param[in] current_state The current state that is running. */ - void set_current_state(const String current_state); + void set_current_state(const godot::String current_state); public: /** @@ -109,7 +109,7 @@ namespace godot * @return true If the running state and given state are the same. * @return false If the running state and given state are not the same. */ - bool is_current(const String state); + bool is_current(const godot::String state); /** * @brief Check if the state machine has a given state. @@ -118,7 +118,7 @@ namespace godot * @return true If the state exists. * @return false If the state doesn't exist. */ - bool has(const String state); + bool has(const godot::String state); /** * @brief Restar the running state by calling its enter and exit methods. @@ -126,7 +126,7 @@ namespace godot * @param[in] state The state that is being restarted. * @param[in] args The arguments to pass to the state on exit and enter. */ - void restart(const String state, const Array& args = Array()); + void restart(const godot::String state, const godot::Array& args = godot::Array()); /** * @brief Change to a different state. @@ -136,7 +136,7 @@ namespace godot * @param[in] state The state to change to. * @param[in] args The arguments to pass to the exiting state and the entering state. */ - void change(const String state, const Array &args = Array()); + void change(const godot::String state, const godot::Array &args = godot::Array()); /** * @brief Call a registered godot method in the class. @@ -145,7 +145,7 @@ namespace godot * @param[in] args The arguments to pass to the method. * @return Variant Returns a Variant based off what the method returns. */ - Variant call(const String method, const Array &args = Array()); + godot::Variant call(const godot::String method, const godot::Array &args = godot::Array()); /** * @brief This method is to link up a signal call back. @@ -154,28 +154,28 @@ namespace godot * @param[in] args The arguments to pass to the method. * @return Variant Returns a Variant based off what the method returns. */ - Variant _call(const String method, const Array &args = Array()); + godot::Variant _call(const godot::String method, const godot::Array &args = godot::Array()); /** * @brief Set the default state object. * * @param[in] default_state The new default state. */ - void set_default_state(const String default_state); + void set_default_state(const godot::String default_state); /** * @brief Get the default state object. * * @return String The default state. */ - String get_default_state(); + godot::String get_default_state(); /** * @brief Get the current state object. * * @return String The current running state. */ - String get_current_state(); + godot::String get_current_state(); /** * @brief Set the debug object. @@ -210,51 +210,51 @@ namespace godot /** * @brief Restarts the running state. * - * @tparam Args Variable number of arguments to pass to restart. + * @param Args Variable number of arguments to pass to restart. * @param[in] state The state being restarted. * @param[in] args The arguments to pass when restarting. */ - template void restart(const String state, Args ...args) + template void restart(const godot::String state, Args ...args) { - return restart(state, Array::make(args...)); + return restart(state, godot::Array::make(args...)); } /** * @brief Changes to a new state. * - * @tparam Args Variable number of arguments to pass when chaning states. + * @param Args Variable number of arguments to pass when changing states. * @param[in] state The state to change to. * @param[in] args The arguments to pass to the new state. */ - template void change(const String state, Args ...args) + template void change(const godot::String state, Args ...args) { - return change(state, Array::make(args...)); + return change(state, godot::Array::make(args...)); } /** * @brief Call a registered godot method in the class. * - * @tparam Args The variable arguments to pass to the method. + * @param Args The variable arguments to pass to the method. * @param[in] method The method to call. * @param[in] args The arguments to pass to it. * @return Variant The Variant object returned by the method called. */ - template Variant call(const String method, Args ...args) + template godot::Variant call(const godot::String method, Args ...args) { - return call(method, Array::make(args...)); + return call(method, godot::Array::make(args...)); } /** * @brief This is used to connect a callback from a signal. * - * @tparam Args The arguments to pass to the callback method. + * @param Args The arguments to pass to the callback method. * @param[in] method The method to call. * @param[in] args The arguments to pass. * @return Variant The Variant object returned by the method called. */ - template Variant _call(const String method, Args ...args) + template godot::Variant _call(const godot::String method, Args ...args) { - return _call(method, Array::make(args...)); + return _call(method, godot::Array::make(args...)); } }; } From 3478127e86e65d41d0d9a9a7900057b657a42615 Mon Sep 17 00:00:00 2001 From: Chris Cromer Date: Fri, 26 Aug 2022 21:02:40 -0400 Subject: [PATCH 18/28] remove main namespace --- src/Main.cpp | 54 +++---- src/Main.h | 381 +++++++++++++++++++++++++------------------------- src/godot.cpp | 2 +- 3 files changed, 215 insertions(+), 222 deletions(-) diff --git a/src/Main.cpp b/src/Main.cpp index 00d622f..5f5d179 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -2,41 +2,41 @@ #include -void alai::main::Main::_register_methods() +void alai::Main::_register_methods() { godot::register_method("_ready", &Main::_ready); godot::register_method("_physics_process", &Main::_physics_process); godot::register_method("_on_monitor_loaded", &Main::_on_monitor_loaded); - godot::register_property("game_version", &Main::set_game_version, &Main::get_game_version, godot::String(main::game_version.c_str())); + godot::register_property("game_version", &Main::set_game_version, &Main::get_game_version, godot::String(alai::game_version.c_str())); godot::register_property>("level", &Main::set_level, &Main::get_level, NULL, GODOT_METHOD_RPC_MODE_DISABLED, GODOT_PROPERTY_USAGE_DEFAULT, GODOT_PROPERTY_HINT_RESOURCE_TYPE, godot::String("PackedScene")); - godot::register_property("full_screen", &Main::set_full_screen, &Main::get_full_screen, main::full_screen); - godot::register_property("window_size", &Main::set_window_size, &Main::get_window_size, main::window_size); - godot::register_property("launch_screen", &Main::set_launch_screen, &Main::get_launch_screen, main::launch_screen); + godot::register_property("full_screen", &Main::set_full_screen, &Main::get_full_screen, alai::full_screen); + godot::register_property("window_size", &Main::set_window_size, &Main::get_window_size, alai::window_size); + godot::register_property("launch_screen", &Main::set_launch_screen, &Main::get_launch_screen, alai::launch_screen); godot::register_signal
("monitor_loaded"); } -alai::main::Main::Main() +alai::Main::Main() { } -alai::main::Main::~Main() +alai::Main::~Main() { } -void alai::main::Main::_init() +void alai::Main::_init() { _os = godot::OS::get_singleton(); _input = godot::Input::get_singleton(); _project_settings = godot::ProjectSettings::get_singleton(); _resource_loader = godot::ResourceLoader::get_singleton(); - game_version = godot::String(main::game_version.c_str()); - full_screen = main::full_screen; - window_size = main::window_size; - launch_screen = main::launch_screen; + game_version = godot::String(alai::game_version.c_str()); + full_screen = alai::full_screen; + window_size = alai::window_size; + launch_screen = alai::launch_screen; } -void alai::main::Main::_ready() +void alai::Main::_ready() { auto success = _project_settings->load_resource_pack("monitor.pck"); if (success) @@ -84,7 +84,7 @@ void alai::main::Main::_ready() } } -void alai::main::Main::_on_monitor_loaded() +void alai::Main::_on_monitor_loaded() { if (level != nullptr) { @@ -94,7 +94,7 @@ void alai::main::Main::_on_monitor_loaded() } } -void alai::main::Main::load_monitor() +void alai::Main::load_monitor() { godot::Ref monitor_scene = _resource_loader->load("res://monitor/Monitor.tscn"); add_child(monitor_scene->instance()); @@ -103,7 +103,7 @@ void alai::main::Main::load_monitor() get_tree()->set_pause(true); } -godot::Node *alai::main::Main::load_level() +godot::Node *alai::Main::load_level() { if (level != nullptr) { @@ -116,7 +116,7 @@ godot::Node *alai::main::Main::load_level() return nullptr; } -void alai::main::Main::_physics_process(float delta) +void alai::Main::_physics_process(float delta) { if (_input->is_action_just_pressed("ui_cancel")) { @@ -124,52 +124,52 @@ void alai::main::Main::_physics_process(float delta) } } -void alai::main::Main::set_level(godot::Ref level) +void alai::Main::set_level(godot::Ref level) { this->level = level; } -godot::Ref alai::main::Main::get_level() +godot::Ref alai::Main::get_level() { return this->level; } -void alai::main::Main::set_game_version(godot::String game_version) +void alai::Main::set_game_version(godot::String game_version) { this->game_version = game_version; } -godot::String alai::main::Main::get_game_version() +godot::String alai::Main::get_game_version() { return this->game_version; } -void alai::main::Main::set_full_screen(bool full_screen) +void alai::Main::set_full_screen(bool full_screen) { this->full_screen = full_screen; } -bool alai::main::Main::get_full_screen() +bool alai::Main::get_full_screen() { return this->full_screen; } -void alai::main::Main::set_window_size(godot::Vector2 window_size) +void alai::Main::set_window_size(godot::Vector2 window_size) { this-> window_size = window_size; } -godot::Vector2 alai::main::Main::get_window_size() +godot::Vector2 alai::Main::get_window_size() { return this->window_size; } -void alai::main::Main::set_launch_screen(int8_t launch_screen) +void alai::Main::set_launch_screen(int8_t launch_screen) { this->launch_screen = launch_screen; } -int8_t alai::main::Main::get_launch_screen() +int8_t alai::Main::get_launch_screen() { if (this->launch_screen == -1) { diff --git a/src/Main.h b/src/Main.h index a575dfb..5964f18 100644 --- a/src/Main.h +++ b/src/Main.h @@ -19,224 +19,217 @@ namespace alai { /** - * @brief This namespace houses some global variables and the main class. + * @brief The default value for the game version. * */ - namespace main + const std::string game_version = "0.1.0"; + /** + * @brief The default value for if the game should start in full screen. + * + */ + const bool full_screen = false; + /** + * @brief The default resolution for the game window. + * + */ + const godot::Vector2 window_size = godot::Vector2(1280, 720); + /** + * @brief The default screen the the game should open on. + * + * @details -1 opens it on the currently active screen. And 0 and above are the screens to use. + */ + const int8_t launch_screen = -1; + + /** + * @brief This class controls the Main node. + * + * @details The main node is responsible for controlling the window and the game itself is a child of it. + */ + class Main : public godot::Node { - /** - * @brief The default value for the game version. - * - */ - const std::string game_version = "0.1.0"; - /** - * @brief The default value for if the game should start in full screen. - * - */ - const bool full_screen = false; - /** - * @brief The default resolution for the game window. - * - */ - const godot::Vector2 window_size = godot::Vector2(1280, 720); - /** - * @brief The default screen the the game should open on. - * - * @details -1 opens it on the currently active screen. And 0 and above are the screens to use. - */ - const int8_t launch_screen = -1; + GODOT_CLASS(Main, godot::Node) - /** - * @brief This class controls the Main node. - * - * @details The main node is responsible for controlling the window and the game itself is a child of it. - */ - class Main : public godot::Node - { - GODOT_CLASS(Main, godot::Node) + private: + /** + * @brief OS singleton. + * + */ + godot::OS *_os; + /** + * @brief Input singleton. + * + */ + godot::Input *_input; + /** + * @brief ProjectSettings singleton. + * + */ + godot::ProjectSettings *_project_settings; + /** + * @brief ResourceLoader singleton. + * + */ + godot::ResourceLoader *_resource_loader; - private: - /** - * @brief OS singleton. - * - */ - godot::OS *_os; - /** - * @brief Input singleton. - * - */ - godot::Input *_input; - /** - * @brief ProjectSettings singleton. - * - */ - godot::ProjectSettings *_project_settings; - /** - * @brief ResourceLoader singleton. - * - */ - godot::ResourceLoader *_resource_loader; + /** + * @brief The first level to load + * + */ + godot::Ref level; + /** + * @brief The current version of the game. + * + */ + godot::String game_version; + /** + * @brief If the window is full screen or not. + * + */ + bool full_screen; + /** + * @brief The size of the window. + * + */ + godot::Vector2 window_size; + /** + * @brief The screen to launch the game on. + * + */ + int8_t launch_screen; - /** - * @brief The first level to load - * - */ - godot::Ref level; - /** - * @brief The current version of the game. - * - */ - godot::String game_version; - /** - * @brief If the window is full screen or not. - * - */ - bool full_screen; - /** - * @brief The size of the window. - * - */ - godot::Vector2 window_size; - /** - * @brief The screen to launch the game on. - * - */ - int8_t launch_screen; + 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 Main object. + * + */ + Main(); - /** - * @brief Construct a new Main object. - * - */ - Main(); + /** + * @brief Destroy the Main object. + * + */ + ~Main(); - /** - * @brief Destroy the Main object. - * - */ - ~Main(); + /** + * @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 Code to be run when ready. + * + * @details This method is run when all the children of this node are ready. + */ + void _ready(); - /** - * @brief Code to be run when ready. - * - * @details This method is run when all the children of this node are ready. - */ - void _ready(); + /** + * @brief This class handles the physics processing. + * + * @details Every delta time, this function is called to check for input and update positioning. + * + * @param[in] delta The difference in time that passed since the last call to this method. + */ + void _physics_process(float delta); - /** - * @brief This class handles the physics processing. - * - * @details Every delta time, this function is called to check for input and update positioning. - * - * @param[in] delta The difference in time that passed since the last call to this method. - */ - void _physics_process(float delta); + /** + * @brief Set the level object. + * + * @param[in] level The new level to load when starting. + */ + void set_level(godot::Ref level); - /** - * @brief Set the level object. - * - * @param[in] level The new level to load when starting. - */ - void set_level(godot::Ref level); + /** + * @brief Get the level object. + * + * @return Ref The level scene to load. + */ + godot::Ref get_level(); - /** - * @brief Get the level object. - * - * @return Ref The level scene to load. - */ - godot::Ref get_level(); + /** + * @brief Set the game version object. + * + * @param[in] game_version The new version fo the game. + */ + void set_game_version(godot::String game_version); - /** - * @brief Set the game version object. - * - * @param[in] game_version The new version fo the game. - */ - void set_game_version(godot::String game_version); + /** + * @brief Get the game version object. + * + * @return String The current version of the game. + */ + godot::String get_game_version(); - /** - * @brief Get the game version object. - * - * @return String The current version of the game. - */ - godot::String get_game_version(); + /** + * @brief Set the full screen object. + * + * @param[in] full_screen The new full screen state. + */ + void set_full_screen(bool full_screen); - /** - * @brief Set the full screen object. - * - * @param[in] full_screen The new full screen state. - */ - void set_full_screen(bool full_screen); + /** + * @brief Get the full screen object. + * + * @return true If full screen. + * @return false If not full screen. + */ + bool get_full_screen(); - /** - * @brief Get the full screen object. - * - * @return true If full screen. - * @return false If not full screen. - */ - bool get_full_screen(); + /** + * @brief Set the window size object. + * + * @param[in] window_size The new window size. + */ + void set_window_size(godot::Vector2 window_size); - /** - * @brief Set the window size object. - * - * @param[in] window_size The new window size. - */ - void set_window_size(godot::Vector2 window_size); + /** + * @brief Get the window size object. + * + * @return Vector2 The window size. + */ + godot::Vector2 get_window_size(); - /** - * @brief Get the window size object. - * - * @return Vector2 The window size. - */ - godot::Vector2 get_window_size(); + /** + * @brief Set the launch screen object. + * + * @param[in] launch_screen The launch screen to use. + */ + void set_launch_screen(int8_t launch_screen); - /** - * @brief Set the launch screen object. - * - * @param[in] launch_screen The launch screen to use. - */ - void set_launch_screen(int8_t launch_screen); + /** + * @brief Get the launch screen object. + * + * @return int8_t The launch screen. + */ + int8_t get_launch_screen(); - /** - * @brief Get the launch screen object. - * - * @return int8_t The launch screen. - */ - int8_t get_launch_screen(); + /** + * @brief Called when the monitor finishes loading. + * + */ + void _on_monitor_loaded(); - /** - * @brief Called when the monitor finishes loading. - * - */ - void _on_monitor_loaded(); + /** + * @brief Loads the monitor and adds it to the scene. + * + */ + void load_monitor(); - /** - * @brief Loads the monitor and adds it to the scene. - * - */ - void load_monitor(); - - /** - * @brief Loads the selected level. - * - * @return Node* The level node which we will later add the monitor to. - */ - Node *load_level(); - }; - } + /** + * @brief Loads the selected level. + * + * @return Node* The level node which we will later add the monitor to. + */ + Node *load_level(); + }; } #endif diff --git a/src/godot.cpp b/src/godot.cpp index a8a9017..f83b9d3 100644 --- a/src/godot.cpp +++ b/src/godot.cpp @@ -41,7 +41,7 @@ extern "C" void GDN_EXPORT godot_nativescript_init(void *handle) godot::register_class(); godot::register_class(); - godot::register_class(); + godot::register_class(); godot::register_class(); godot::register_class(); godot::register_class(); From ddb630ca3e881cb60db301d2d68216471715da72 Mon Sep 17 00:00:00 2001 From: Chris Cromer Date: Fri, 26 Aug 2022 21:43:09 -0400 Subject: [PATCH 19/28] change NULL to nullptr --- src/Main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Main.cpp b/src/Main.cpp index 5f5d179..87f1d87 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -8,7 +8,7 @@ void alai::Main::_register_methods() godot::register_method("_physics_process", &Main::_physics_process); godot::register_method("_on_monitor_loaded", &Main::_on_monitor_loaded); godot::register_property("game_version", &Main::set_game_version, &Main::get_game_version, godot::String(alai::game_version.c_str())); - godot::register_property>("level", &Main::set_level, &Main::get_level, NULL, GODOT_METHOD_RPC_MODE_DISABLED, GODOT_PROPERTY_USAGE_DEFAULT, GODOT_PROPERTY_HINT_RESOURCE_TYPE, godot::String("PackedScene")); + godot::register_property>("level", &Main::set_level, &Main::get_level, nullptr, GODOT_METHOD_RPC_MODE_DISABLED, GODOT_PROPERTY_USAGE_DEFAULT, GODOT_PROPERTY_HINT_RESOURCE_TYPE, godot::String("PackedScene")); godot::register_property("full_screen", &Main::set_full_screen, &Main::get_full_screen, alai::full_screen); godot::register_property("window_size", &Main::set_window_size, &Main::get_window_size, alai::window_size); godot::register_property("launch_screen", &Main::set_launch_screen, &Main::get_launch_screen, alai::launch_screen); From 1a2c5eab98c33f81bc15998cc6f50874516736d2 Mon Sep 17 00:00:00 2001 From: Chris Cromer Date: Fri, 26 Aug 2022 23:56:30 -0400 Subject: [PATCH 20/28] improve default values --- src/Main.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Main.cpp b/src/Main.cpp index 87f1d87..5c87b29 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -7,11 +7,11 @@ void alai::Main::_register_methods() godot::register_method("_ready", &Main::_ready); godot::register_method("_physics_process", &Main::_physics_process); godot::register_method("_on_monitor_loaded", &Main::_on_monitor_loaded); - godot::register_property("game_version", &Main::set_game_version, &Main::get_game_version, godot::String(alai::game_version.c_str())); - godot::register_property>("level", &Main::set_level, &Main::get_level, nullptr, GODOT_METHOD_RPC_MODE_DISABLED, GODOT_PROPERTY_USAGE_DEFAULT, GODOT_PROPERTY_HINT_RESOURCE_TYPE, godot::String("PackedScene")); - godot::register_property("full_screen", &Main::set_full_screen, &Main::get_full_screen, alai::full_screen); - godot::register_property("window_size", &Main::set_window_size, &Main::get_window_size, alai::window_size); - godot::register_property("launch_screen", &Main::set_launch_screen, &Main::get_launch_screen, alai::launch_screen); + godot::register_property("game_version", &Main::set_game_version, &Main::get_game_version, godot::String(default_game_version.c_str())); + godot::register_property>("level", &Main::set_level, &Main::get_level, nullptr, GODOT_METHOD_RPC_MODE_DISABLED, GODOT_PROPERTY_USAGE_DEFAULT, GODOT_PROPERTY_HINT_RESOURCE_TYPE, "PackedScene"); + godot::register_property("full_screen", &Main::set_full_screen, &Main::get_full_screen, default_full_screen); + godot::register_property("window_size", &Main::set_window_size, &Main::get_window_size, default_window_size); + godot::register_property("launch_screen", &Main::set_launch_screen, &Main::get_launch_screen, default_launch_screen); godot::register_signal
("monitor_loaded"); } @@ -30,10 +30,10 @@ void alai::Main::_init() _project_settings = godot::ProjectSettings::get_singleton(); _resource_loader = godot::ResourceLoader::get_singleton(); - game_version = godot::String(alai::game_version.c_str()); - full_screen = alai::full_screen; - window_size = alai::window_size; - launch_screen = alai::launch_screen; + set_game_version(godot::String(default_game_version.c_str())); + set_full_screen(default_full_screen); + set_window_size(default_window_size); + set_launch_screen(default_launch_screen); } void alai::Main::_ready() From 9e0d428ffae9ec381f7fd8cdee7be90d45b6f5ff Mon Sep 17 00:00:00 2001 From: Chris Cromer Date: Fri, 26 Aug 2022 23:57:12 -0400 Subject: [PATCH 21/28] include forgotten header --- src/Main.h | 44 +++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/src/Main.h b/src/Main.h index 5964f18..9487338 100644 --- a/src/Main.h +++ b/src/Main.h @@ -18,28 +18,6 @@ */ namespace alai { - /** - * @brief The default value for the game version. - * - */ - const std::string game_version = "0.1.0"; - /** - * @brief The default value for if the game should start in full screen. - * - */ - const bool full_screen = false; - /** - * @brief The default resolution for the game window. - * - */ - const godot::Vector2 window_size = godot::Vector2(1280, 720); - /** - * @brief The default screen the the game should open on. - * - * @details -1 opens it on the currently active screen. And 0 and above are the screens to use. - */ - const int8_t launch_screen = -1; - /** * @brief This class controls the Main node. * @@ -70,7 +48,27 @@ namespace alai * */ godot::ResourceLoader *_resource_loader; - + /** + * @brief The default value for the game version. + * + */ + inline static const std::string default_game_version = "0.1.0"; + /** + * @brief The default value for if the game should start in full screen. + * + */ + inline static const bool default_full_screen = false; + /** + * @brief The default resolution for the game window. + * + */ + inline static const godot::Vector2 default_window_size = godot::Vector2(1280, 720); + /** + * @brief The default screen the the game should open on. + * + * @details -1 opens it on the currently active screen. And 0 and above are the screens to use. + */ + inline static const int8_t default_launch_screen = -1; /** * @brief The first level to load * From c102c2ad3f7d54d199b8ab7cc505f3e2adb8660e Mon Sep 17 00:00:00 2001 From: Chris Cromer Date: Sat, 27 Aug 2022 00:25:15 -0400 Subject: [PATCH 22/28] use empty PackedScene instead of nullptr --- src/Main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Main.cpp b/src/Main.cpp index 5c87b29..4f895bd 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -8,7 +8,7 @@ void alai::Main::_register_methods() godot::register_method("_physics_process", &Main::_physics_process); godot::register_method("_on_monitor_loaded", &Main::_on_monitor_loaded); godot::register_property("game_version", &Main::set_game_version, &Main::get_game_version, godot::String(default_game_version.c_str())); - godot::register_property>("level", &Main::set_level, &Main::get_level, nullptr, GODOT_METHOD_RPC_MODE_DISABLED, GODOT_PROPERTY_USAGE_DEFAULT, GODOT_PROPERTY_HINT_RESOURCE_TYPE, "PackedScene"); + godot::register_property>("level", &Main::set_level, &Main::get_level, godot::Ref(nullptr), GODOT_METHOD_RPC_MODE_DISABLED, GODOT_PROPERTY_USAGE_DEFAULT, GODOT_PROPERTY_HINT_RESOURCE_TYPE, "PackedScene"); godot::register_property("full_screen", &Main::set_full_screen, &Main::get_full_screen, default_full_screen); godot::register_property("window_size", &Main::set_window_size, &Main::get_window_size, default_window_size); godot::register_property("launch_screen", &Main::set_launch_screen, &Main::get_launch_screen, default_launch_screen); From 3eb3d8765af625188841b5fc3c028575c6d0fc09 Mon Sep 17 00:00:00 2001 From: Chris Cromer Date: Sat, 27 Aug 2022 18:10:36 -0400 Subject: [PATCH 23/28] add event bus --- godot/Event.gdns | 8 +++++++ godot/monitor/Monitor.gd | 4 ++++ godot/monitor/Monitor.tscn | 1 + godot/project.godot | 4 ++++ src/Event.cpp | 20 ++++++++++++++++ src/Event.h | 47 ++++++++++++++++++++++++++++++++++++++ src/godot.cpp | 2 ++ src/player/Player.cpp | 30 ++++++++---------------- 8 files changed, 95 insertions(+), 21 deletions(-) create mode 100644 godot/Event.gdns create mode 100644 src/Event.cpp create mode 100644 src/Event.h diff --git a/godot/Event.gdns b/godot/Event.gdns new file mode 100644 index 0000000..5668ff6 --- /dev/null +++ b/godot/Event.gdns @@ -0,0 +1,8 @@ +[gd_resource type="NativeScript" load_steps=2 format=2] + +[ext_resource path="res://gdnative/alai.tres" type="GDNativeLibrary" id=1] + +[resource] +resource_name = "Event" +class_name = "Event" +library = ExtResource( 1 ) diff --git a/godot/monitor/Monitor.gd b/godot/monitor/Monitor.gd index 004c1f9..a9ff7d7 100644 --- a/godot/monitor/Monitor.gd +++ b/godot/monitor/Monitor.gd @@ -50,6 +50,10 @@ var game: Dictionary = {} func _ready() -> void: + Event.connect("object_created", self, "_object_created") + Event.connect("object_updated", self, "_object_updated") + Event.connect("object_removed", self, "_object_removed") + game_version = get_parent().game_version player["rut"] = "" diff --git a/godot/monitor/Monitor.tscn b/godot/monitor/Monitor.tscn index 58f135d..b987a56 100644 --- a/godot/monitor/Monitor.tscn +++ b/godot/monitor/Monitor.tscn @@ -6,6 +6,7 @@ [node name="Monitor" type="Node"] pause_mode = 2 script = ExtResource( 1 ) +monitor_enabled = true [node name="MonitorGUI" parent="." instance=ExtResource( 3 )] visible = false diff --git a/godot/project.godot b/godot/project.godot index b01c12e..3a913d7 100644 --- a/godot/project.godot +++ b/godot/project.godot @@ -15,6 +15,10 @@ config/description="This game is for testing an Artificial Intelligence." run/main_scene="res://Main.tscn" config/icon="res://icon.png" +[autoload] + +Event="*res://Event.gdns" + [display] window/size/width=512 diff --git a/src/Event.cpp b/src/Event.cpp new file mode 100644 index 0000000..3e9e186 --- /dev/null +++ b/src/Event.cpp @@ -0,0 +1,20 @@ +#include "Event.h" + +void alai::Event::_register_methods() +{ + godot::register_signal("object_created", "name", GODOT_VARIANT_TYPE_STRING, "state", GODOT_VARIANT_TYPE_STRING, "position", GODOT_VARIANT_TYPE_VECTOR2, "velocity", GODOT_VARIANT_TYPE_VECTOR2); + godot::register_signal("object_updated", "name", GODOT_VARIANT_TYPE_STRING, "state", GODOT_VARIANT_TYPE_STRING, "position", GODOT_VARIANT_TYPE_VECTOR2, "velocity", GODOT_VARIANT_TYPE_VECTOR2); + godot::register_signal("object_removed", "name", GODOT_VARIANT_TYPE_STRING); +} + +alai::Event::Event() +{ +} + +alai::Event::~Event() +{ +} + +void alai::Event::_init() +{ +} diff --git a/src/Event.h b/src/Event.h new file mode 100644 index 0000000..87607c6 --- /dev/null +++ b/src/Event.h @@ -0,0 +1,47 @@ +#ifndef ALAI_EVENT_H +#define ALAI_EVENT_H + +#include +#include + +namespace alai +{ + /** + * @brief This class provides an event bus for the project. + * + * @details This class should be an auto-loaded singleton for the project. + * To use this use Event.connect() and Event.emit_signal() to have global signals. + */ + class Event : public godot::Node + { + GODOT_CLASS(Event, godot::Node) + 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 Event object. + * + */ + Event(); + + /** + * @brief Destroy the Event object. + * + */ + ~Event(); + + /** + * @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(); + }; +} + +#endif diff --git a/src/godot.cpp b/src/godot.cpp index 1c56d09..80bfa16 100644 --- a/src/godot.cpp +++ b/src/godot.cpp @@ -1,5 +1,6 @@ #include +#include "Event.h" #include "state_machine/StateMachine.h" #include "state_machine/State.h" #include "Main.h" @@ -40,6 +41,7 @@ extern "C" void GDN_EXPORT godot_gdnative_terminate(godot_gdnative_terminate_opt extern "C" void GDN_EXPORT godot_nativescript_init(void *handle) { Godot::nativescript_init(handle); + register_class(); register_class(); register_class(); register_class(); diff --git a/src/player/Player.cpp b/src/player/Player.cpp index 868156b..17da42d 100644 --- a/src/player/Player.cpp +++ b/src/player/Player.cpp @@ -1,5 +1,7 @@ #include "player/Player.h" +#include "Event.h" + #include #include #include @@ -27,9 +29,6 @@ void Player::_register_methods() register_property("gravity", &Player::set_gravity, &Player::get_gravity, player::gravity); register_property("run_speed", &Player::set_run_speed, &Player::get_run_speed, player::run_speed); register_property("double_jump", &Player::set_double_jump, &Player::get_double_jump, player::double_jump); - register_signal("object_created", "name", GODOT_VARIANT_TYPE_STRING, "state", GODOT_VARIANT_TYPE_STRING, "position", GODOT_VARIANT_TYPE_VECTOR2, "velocity", GODOT_VARIANT_TYPE_VECTOR2); - register_signal("object_updated", "name", GODOT_VARIANT_TYPE_STRING, "state", GODOT_VARIANT_TYPE_STRING, "position", GODOT_VARIANT_TYPE_VECTOR2, "velocity", GODOT_VARIANT_TYPE_VECTOR2); - register_signal("object_removed", "name", GODOT_VARIANT_TYPE_STRING); } Player::Player() @@ -81,28 +80,16 @@ void Player::_ready() } void Player::_on_monitor_loaded() { - auto object_node = get_tree()->get_root()->find_node("Monitor", true, false); - if (object_node != nullptr) + auto state = get_node("StateMachine")->get_child(0); + if (state != nullptr) { - auto state = get_node("StateMachine")->get_child(0); - if (state != nullptr) - { - connect("object_created", object_node, "_object_created"); - connect("object_updated", object_node, "_object_updated"); - connect("object_removed", object_node, "_object_removed"); - emit_signal("object_created", this->get_name(), state->get_name(), get_global_position(), velocity); - } - else - { - WARN_PRINT("State not found!"); - } + auto event = get_node("/root/Event"); + event->emit_signal("object_created", this->get_name(), state->get_name(), get_global_position(), velocity); } -#ifndef NDEBUG else { - WARN_PRINT("Monitor not found!"); + WARN_PRINT("State not found!"); } -#endif } void Player::_physics_process(float delta) @@ -193,7 +180,8 @@ void Player::_physics_process(float delta) auto state = get_node("StateMachine")->get_child(0); if (state != nullptr) { - emit_signal("object_updated", this->get_name(), state->get_name(), get_global_position(), velocity); + auto event = get_node("/root/Event"); + event->emit_signal("object_updated", this->get_name(), state->get_name(), get_global_position(), velocity); } else { From a27f96829771f581663652fb702f1d90cf84a1e9 Mon Sep 17 00:00:00 2001 From: Martin Araneda Date: Sat, 27 Aug 2022 18:14:21 -0400 Subject: [PATCH 24/28] add gameover --- godot/Main.tscn | 6 +- src/gui/game_over/GameOverScreen.cpp | 23 ++++++-- src/gui/game_over/GameOverScreen.h | 88 +++++++++++++++------------- 3 files changed, 70 insertions(+), 47 deletions(-) diff --git a/godot/Main.tscn b/godot/Main.tscn index d288642..5babece 100644 --- a/godot/Main.tscn +++ b/godot/Main.tscn @@ -1,7 +1,8 @@ -[gd_scene load_steps=3 format=2] +[gd_scene load_steps=4 format=2] [ext_resource path="res://Main.gdns" type="Script" id=1] [ext_resource path="res://levels/Prototype.tscn" type="PackedScene" id=2] +[ext_resource path="res://GUI/GameOver.tscn" type="PackedScene" id=3] [node name="Main" type="Node"] pause_mode = 2 @@ -10,3 +11,6 @@ level = ExtResource( 2 ) [node name="Level" type="Node" parent="."] pause_mode = 1 + +[node name="GameOver" parent="." instance=ExtResource( 3 )] +visible = false diff --git a/src/gui/game_over/GameOverScreen.cpp b/src/gui/game_over/GameOverScreen.cpp index 66bc484..e497503 100644 --- a/src/gui/game_over/GameOverScreen.cpp +++ b/src/gui/game_over/GameOverScreen.cpp @@ -1,12 +1,16 @@ #include "gui/game_over/GameOverScreen.h" +#include +#include #include #include +#include +#include using namespace godot; void GameOverScreen::_register_methods() -{ - register_method("_on_restart_button_pressed", &GameOverScreen::_on_restart_button_pressed); +{ + register_method("_on_animation_finished", &GameOverScreen::_on_botonreiniciar_pressed); } GameOverScreen::GameOverScreen() @@ -19,9 +23,20 @@ GameOverScreen::~GameOverScreen() void GameOverScreen::_init() { + _resource_loader = ResourceLoader::get_singleton(); } -void GameOverScreen::_on_restart_button_pressed() + +void GameOverScreen::_on_botonreiniciar_pressed() { - get_tree()->change_scene("res://monitor/GUI.tscn"); + + if (_resource_loader->exists("res://levels/Prototype.tscn")) //CAMBIAR A DINAMICO + { + Ref level_scene = _resource_loader->load("res://levels/Prototype.tscn"); + auto level = level_scene->instance(); + auto level_node = get_tree()->get_root()->find_node("Level"); + level_node->add_child(level); + } } + + diff --git a/src/gui/game_over/GameOverScreen.h b/src/gui/game_over/GameOverScreen.h index 1a40b2e..a03a2b2 100644 --- a/src/gui/game_over/GameOverScreen.h +++ b/src/gui/game_over/GameOverScreen.h @@ -1,56 +1,60 @@ -#ifndef ALAI_GAME_OVER_SCREEN -#define ALAI_GAME_OVER_SCREEN - +#ifndef ALAI_GAME_OVER_SCREEN_H +#define ALAI_GAME_OVER_SCREEN_H #include -#include #include +#include + namespace godot { - /** - * @brief This class controls what happens when the Coin is in the collected . - * - */ - class GameOverScreen : public Control - { - GODOT_CLASS(GameOverScreen, Control) + /** + * @brief This class controls what happens when the Coin is in the collected . + * + */ + class GameOverScreen : public Control + { + GODOT_CLASS(GameOverScreen, Control) - private: + private: + ResourceLoader *_resource_loader; + + 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 GameOverScreen object. + * + */ + GameOverScreen(); - /** - * @brief Construct a new GameOverScreen object. - * - */ - GameOverScreen(); + /** + * @brief Destroy the GameOverScreen object. + * + */ + ~GameOverScreen(); - /** - * @brief Destroy the GameOverScreen object. - * - */ - ~GameOverScreen(); + /** + * @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. + * + */ + void _on_botonreiniciar_pressed(); - /** - * @brief Called when the collected of the coin is entered. - * - */ - void _on_restart_button_pressed(); - }; + + }; + } -#endif +#endif \ No newline at end of file From 705ed4e89753ac34f89cc875ccd36ad2e8c0f31e Mon Sep 17 00:00:00 2001 From: Martin Araneda Date: Sat, 27 Aug 2022 18:32:33 -0400 Subject: [PATCH 25/28] Use event bus for coins --- src/Event.cpp | 3 +++ src/coin/CoinCollected.cpp | 5 +++-- src/coin/CoinCounter.cpp | 10 +++------- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Event.cpp b/src/Event.cpp index 3e9e186..6561979 100644 --- a/src/Event.cpp +++ b/src/Event.cpp @@ -5,6 +5,9 @@ void alai::Event::_register_methods() godot::register_signal("object_created", "name", GODOT_VARIANT_TYPE_STRING, "state", GODOT_VARIANT_TYPE_STRING, "position", GODOT_VARIANT_TYPE_VECTOR2, "velocity", GODOT_VARIANT_TYPE_VECTOR2); godot::register_signal("object_updated", "name", GODOT_VARIANT_TYPE_STRING, "state", GODOT_VARIANT_TYPE_STRING, "position", GODOT_VARIANT_TYPE_VECTOR2, "velocity", GODOT_VARIANT_TYPE_VECTOR2); godot::register_signal("object_removed", "name", GODOT_VARIANT_TYPE_STRING); + godot::register_signal("coin_collected", "amount", GODOT_VARIANT_TYPE_INT); + godot::register_signal("player_died"); + } alai::Event::Event() diff --git a/src/coin/CoinCollected.cpp b/src/coin/CoinCollected.cpp index 9f3a9a4..22a65b8 100644 --- a/src/coin/CoinCollected.cpp +++ b/src/coin/CoinCollected.cpp @@ -1,5 +1,6 @@ #include "coin/CoinCollected.h" #include +#include "Event.h" using namespace godot; @@ -8,7 +9,6 @@ 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("coin_collected", "amount", GODOT_VARIANT_TYPE_INT); } CoinCollected::CoinCollected() @@ -43,7 +43,8 @@ void CoinCollected::_state_exit() void CoinCollected::_on_animation_finished(String anim_name) { - emit_signal("coin_collected", 1); + auto event = get_node("/root/Event"); + event->emit_signal("coin_collected", 1); this->get_parent()->queue_free(); diff --git a/src/coin/CoinCounter.cpp b/src/coin/CoinCounter.cpp index 22fc8e4..7bcdbf0 100644 --- a/src/coin/CoinCounter.cpp +++ b/src/coin/CoinCounter.cpp @@ -1,6 +1,7 @@ #include "coin/CoinCounter.h" #include #include "coin/CoinCollected.h" +#include "Event.h" using namespace godot; void CoinCounter::_register_methods() @@ -35,13 +36,8 @@ void CoinCounter::_on_coin_collected(int amount) 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"); - } + auto event = get_node("/root/Event"); + event->connect("coin_collected", this, "_on_coin_collected"); } From 3bcbde816102878a9b3935b7af7533d8ed4c47c6 Mon Sep 17 00:00:00 2001 From: Martin Araneda Date: Sat, 27 Aug 2022 22:34:18 -0400 Subject: [PATCH 26/28] Game over screen finished --- godot/GUI/GameOver.tscn | 19 +++++---- godot/monitor/Monitor.gd | 2 +- src/godot.cpp | 2 + src/gui/game_over/GameOverScreen.cpp | 64 ++++++++++++++++++++++++++-- src/gui/game_over/GameOverScreen.h | 10 +++-- src/player/Player.cpp | 8 ++-- 6 files changed, 84 insertions(+), 21 deletions(-) diff --git a/godot/GUI/GameOver.tscn b/godot/GUI/GameOver.tscn index d9729bf..401d521 100644 --- a/godot/GUI/GameOver.tscn +++ b/godot/GUI/GameOver.tscn @@ -14,18 +14,20 @@ font_data = ExtResource( 2 ) [sub_resource type="StyleBoxFlat" id=3] bg_color = Color( 0.0705882, 0.917647, 0, 1 ) -[node name="GameOver" type="Control"] -anchor_right = 1.0 -anchor_bottom = 1.0 +[node name="GameOver" type="CanvasLayer"] +script = ExtResource( 3 ) -[node name="ColorRect" type="ColorRect" parent="."] +[node name="Control" type="Control" parent="."] +margin_right = 40.0 +margin_bottom = 40.0 + +[node name="ColorRect" type="ColorRect" parent="Control"] margin_right = 512.0 margin_bottom = 288.0 rect_min_size = Vector2( 512, 288 ) -rect_rotation = -0.338293 color = Color( 0, 0, 0, 1 ) -[node name="Label" type="Label" parent="."] +[node name="Label" type="Label" parent="Control"] margin_left = 66.0 margin_top = 17.0 margin_right = 456.0 @@ -34,7 +36,7 @@ custom_fonts/font = SubResource( 1 ) text = "GAME OVER" align = 1 -[node name="botonreiniciar" type="Button" parent="."] +[node name="botonreiniciar" type="Button" parent="Control"] margin_left = 194.0 margin_top = 150.0 margin_right = 338.0 @@ -42,6 +44,5 @@ margin_bottom = 180.0 custom_fonts/font = SubResource( 2 ) custom_styles/hover = SubResource( 3 ) text = "REINICIAR" -script = ExtResource( 3 ) -[connection signal="pressed" from="botonreiniciar" to="botonreiniciar" method="_on_botonreiniciar_pressed"] +[connection signal="pressed" from="Control/botonreiniciar" to="." method="_on_botonreiniciar_pressed"] diff --git a/godot/monitor/Monitor.gd b/godot/monitor/Monitor.gd index a9ff7d7..80ada27 100644 --- a/godot/monitor/Monitor.gd +++ b/godot/monitor/Monitor.gd @@ -53,7 +53,7 @@ func _ready() -> void: Event.connect("object_created", self, "_object_created") Event.connect("object_updated", self, "_object_updated") Event.connect("object_removed", self, "_object_removed") - + Event.connect("coin_collected", self, "_on_coin_update") game_version = get_parent().game_version player["rut"] = "" diff --git a/src/godot.cpp b/src/godot.cpp index 787b6b5..2b06182 100644 --- a/src/godot.cpp +++ b/src/godot.cpp @@ -15,6 +15,7 @@ #include "coin/CoinCounter.h" #include "goal/GoalReached.h" #include "goal/GoalNotReached.h" +#include "gui/game_over/GameOverScreen.h" using namespace godot; @@ -61,4 +62,5 @@ extern "C" void GDN_EXPORT godot_nativescript_init(void *handle) register_class(); register_class(); register_class(); + register_class(); } diff --git a/src/gui/game_over/GameOverScreen.cpp b/src/gui/game_over/GameOverScreen.cpp index e497503..203558e 100644 --- a/src/gui/game_over/GameOverScreen.cpp +++ b/src/gui/game_over/GameOverScreen.cpp @@ -1,4 +1,6 @@ #include "gui/game_over/GameOverScreen.h" +#include "Event.h" + #include #include #include @@ -6,11 +8,15 @@ #include #include + using namespace godot; void GameOverScreen::_register_methods() { - register_method("_on_animation_finished", &GameOverScreen::_on_botonreiniciar_pressed); + register_method("_on_botonreiniciar_pressed", &GameOverScreen::_on_botonreiniciar_pressed); + register_method("_ready", &GameOverScreen::_ready); + register_method("connect_signal", &GameOverScreen::connect_signal); + register_method("_on_player_died", &GameOverScreen::_on_player_died); } GameOverScreen::GameOverScreen() @@ -27,16 +33,66 @@ void GameOverScreen::_init() } +void GameOverScreen::_ready() +{ + connect_signal(); +} + void GameOverScreen::_on_botonreiniciar_pressed() { - if (_resource_loader->exists("res://levels/Prototype.tscn")) //CAMBIAR A DINAMICO { Ref level_scene = _resource_loader->load("res://levels/Prototype.tscn"); auto level = level_scene->instance(); - auto level_node = get_tree()->get_root()->find_node("Level"); - level_node->add_child(level); + auto level_node = get_tree()->get_root()->get_node("Main")->find_node("Level"); + + if (level_node != nullptr) + { + + level_node->add_child(level); + set_visible(false); + call_deferred("connect_signal"); + } + else + { + WARN_PRINT("Node level not found!"); + } + } + +} + +void GameOverScreen::_on_player_died() //eliminar nivel +{ + auto event = get_node("/root/Event"); + event->disconnect("player_died", this, "_on_player_died"); + Godot::print("player ded"); + set_visible(true); + auto level_node = get_tree()->get_root()->get_node("Main")->find_node("Level"); + if (level_node != nullptr) + { + auto child = level_node->get_child(0); + if (child != nullptr) + { + child->queue_free(); + } + else + { + WARN_PRINT("Child not found!"); + } + } + else + { + WARN_PRINT("Node level not found!"); + } + +} + +void GameOverScreen::connect_signal() +{ + auto event = get_node("/root/Event"); + event->connect("player_died", this, "_on_player_died"); } + diff --git a/src/gui/game_over/GameOverScreen.h b/src/gui/game_over/GameOverScreen.h index a03a2b2..79c5ad9 100644 --- a/src/gui/game_over/GameOverScreen.h +++ b/src/gui/game_over/GameOverScreen.h @@ -2,7 +2,7 @@ #define ALAI_GAME_OVER_SCREEN_H #include -#include +#include #include @@ -12,9 +12,9 @@ namespace godot * @brief This class controls what happens when the Coin is in the collected . * */ - class GameOverScreen : public Control + class GameOverScreen : public CanvasLayer { - GODOT_CLASS(GameOverScreen, Control) + GODOT_CLASS(GameOverScreen, CanvasLayer) private: ResourceLoader *_resource_loader; @@ -50,8 +50,10 @@ namespace godot * @brief Called when the collected of the coin is entered. * */ + void _ready(); + void _on_player_died(); void _on_botonreiniciar_pressed(); - + void connect_signal(); }; diff --git a/src/player/Player.cpp b/src/player/Player.cpp index 17da42d..1ea201b 100644 --- a/src/player/Player.cpp +++ b/src/player/Player.cpp @@ -52,7 +52,7 @@ void Player::_init() set_double_jump(player::double_jump); coins = 0; - + velocity = Vector2(); } @@ -166,14 +166,16 @@ void Player::_physics_process(float delta) { if (!notifier->is_on_screen()) { - if (get_parent()->get_class() == "TileMap") + auto event = get_node("/root/Event"); + event->emit_signal("player_died"); + /*if (get_parent()->get_class() == "TileMap") { auto error = get_tree()->change_scene("res://Main.tscn"); if (error != Error::OK) { ERR_PRINT(String().num((int) error) + " Could not load scene!"); } - } + }*/ } } From 3c8107ba9f96ea4fba8215e9fe6dccc8e16cd32f Mon Sep 17 00:00:00 2001 From: Chris Cromer Date: Sun, 28 Aug 2022 01:04:47 -0400 Subject: [PATCH 27/28] disable monitor by default in development --- godot/monitor/Monitor.tscn | 1 - 1 file changed, 1 deletion(-) diff --git a/godot/monitor/Monitor.tscn b/godot/monitor/Monitor.tscn index b987a56..58f135d 100644 --- a/godot/monitor/Monitor.tscn +++ b/godot/monitor/Monitor.tscn @@ -6,7 +6,6 @@ [node name="Monitor" type="Node"] pause_mode = 2 script = ExtResource( 1 ) -monitor_enabled = true [node name="MonitorGUI" parent="." instance=ExtResource( 3 )] visible = false From 39173cef213b319307dad8b846553b7d76e493c7 Mon Sep 17 00:00:00 2001 From: Chris Cromer Date: Sun, 28 Aug 2022 01:08:04 -0400 Subject: [PATCH 28/28] cleanup code --- src/coin/CoinCollected.cpp | 27 +++---- src/coin/CoinCollected.h | 114 +++++++++++++------------- src/coin/CoinCounter.cpp | 32 +++----- src/coin/CoinCounter.h | 91 ++++++++++----------- src/coin/CoinNotCollected.cpp | 30 +++---- src/coin/CoinNotCollected.h | 116 +++++++++++++-------------- src/goal/GoalNotReached.cpp | 31 +++---- src/goal/GoalNotReached.h | 116 +++++++++++++-------------- src/goal/GoalReached.cpp | 22 ++--- src/goal/GoalReached.h | 112 +++++++++++++------------- src/godot.cpp | 12 +-- src/gui/game_over/GameOverScreen.cpp | 43 ++++------ src/gui/game_over/GameOverScreen.h | 93 +++++++++++---------- src/player/states/PlayerFall.cpp | 1 + src/player/states/PlayerIdle.cpp | 1 + src/player/states/PlayerJump.cpp | 1 + src/player/states/PlayerMove.cpp | 1 + src/state_machine/StateMachine.cpp | 1 + 18 files changed, 393 insertions(+), 451 deletions(-) diff --git a/src/coin/CoinCollected.cpp b/src/coin/CoinCollected.cpp index 22a65b8..5c30b82 100644 --- a/src/coin/CoinCollected.cpp +++ b/src/coin/CoinCollected.cpp @@ -1,55 +1,48 @@ #include "coin/CoinCollected.h" -#include + #include "Event.h" -using namespace godot; +#include -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(node); + auto animation_player = Object::cast_to(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("/root/Event"); event->emit_signal("coin_collected", 1); this->get_parent()->queue_free(); - - - // get_state_machine()->change("CoinCounter"); - } - - diff --git a/src/coin/CoinCollected.h b/src/coin/CoinCollected.h index 0e8f359..119acae 100644 --- a/src/coin/CoinCollected.h +++ b/src/coin/CoinCollected.h @@ -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 -#include #include +#include -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 diff --git a/src/coin/CoinCounter.cpp b/src/coin/CoinCounter.cpp index 7bcdbf0..667ea9e 100644 --- a/src/coin/CoinCounter.cpp +++ b/src/coin/CoinCounter.cpp @@ -1,43 +1,37 @@ #include "coin/CoinCounter.h" -#include -#include "coin/CoinCollected.h" -#include "Event.h" -using namespace godot; -void CoinCounter::_register_methods() +#include "Event.h" + +#include + +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("/root/Event"); event->connect("coin_collected", this, "_on_coin_collected"); - - } diff --git a/src/coin/CoinCounter.h b/src/coin/CoinCounter.h index 006aa93..8702887 100644 --- a/src/coin/CoinCounter.h +++ b/src/coin/CoinCounter.h @@ -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 -#include #include -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(); + + }; } diff --git a/src/coin/CoinNotCollected.cpp b/src/coin/CoinNotCollected.cpp index cb7487b..c03aa0b 100644 --- a/src/coin/CoinNotCollected.cpp +++ b/src/coin/CoinNotCollected.cpp @@ -1,56 +1,46 @@ #include "coin/CoinNotCollected.h" + #include -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"); + animated_sprite = get_parent()->get_node("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(parent_node); + auto coin = Object::cast_to(parent_node); coin->set_collision_mask_bit(0, false); } get_state_machine()->change("CoinCollected"); - - } - - - diff --git a/src/coin/CoinNotCollected.h b/src/coin/CoinNotCollected.h index 4739cf0..1b3c5ff 100644 --- a/src/coin/CoinNotCollected.h +++ b/src/coin/CoinNotCollected.h @@ -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 -#include #include +#include -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 diff --git a/src/goal/GoalNotReached.cpp b/src/goal/GoalNotReached.cpp index 4248066..08d55f3 100644 --- a/src/goal/GoalNotReached.cpp +++ b/src/goal/GoalNotReached.cpp @@ -1,55 +1,46 @@ #include "goal/GoalNotReached.h" + #include -using namespace godot; - - -void GoalNotReached::_register_methods() +void alai::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() +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"); + animated_sprite = get_parent()->get_node("AnimatedSprite"); animated_sprite->set_animation("flagmove"); 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(); if (parent_node != nullptr) { - auto goal = Object::cast_to(parent_node); + auto goal = Object::cast_to(parent_node); goal->set_collision_mask_bit(0, false); } - + get_state_machine()->change("GoalReached"); - - } - - - diff --git a/src/goal/GoalNotReached.h b/src/goal/GoalNotReached.h index 82c9628..e858261 100644 --- a/src/goal/GoalNotReached.h +++ b/src/goal/GoalNotReached.h @@ -1,76 +1,74 @@ -#ifndef ALAI_GOAL_NOT_REACHED -#define ALAI_GOAL_NOT_REACHED +#ifndef ALAI_GOAL_GOAL_NOT_REACHED_H +#define ALAI_GOAL_GOAL_NOT_REACHED_H #include "state_machine/State.h" -#include -#include #include +#include -namespace godot +namespace alai { - /** - * @brief This class controls what happens when the Coin is in the not collected state. - * - */ - class GoalNotReached : public State - { - GODOT_CLASS(GoalNotReached, State) + /** + * @brief This class controls what happens when the Coin is in the not collected state. + * + */ + class GoalNotReached : public alai::State + { + GODOT_CLASS(GoalNotReached, 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 GoalNotReached object. - * - */ - GoalNotReached(); + /** + * @brief Construct a new GoalNotReached object. + * + */ + GoalNotReached(); - /** - * @brief Destroy the 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 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_Goal_body_entered(Node *node); - }; - + /** + * @brief Method called on body entered. + * + * @param[in] node Node interacting with whoever + */ + void _on_Goal_body_entered(Node *node); + }; } #endif diff --git a/src/goal/GoalReached.cpp b/src/goal/GoalReached.cpp index 239f1e4..06f882c 100644 --- a/src/goal/GoalReached.cpp +++ b/src/goal/GoalReached.cpp @@ -1,36 +1,30 @@ #include "goal/GoalReached.h" + #include -using namespace godot; - -void GoalReached::_register_methods() +void alai::GoalReached::_register_methods() { register_method("_state_enter", &GoalReached::_state_enter); 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() { - } - diff --git a/src/goal/GoalReached.h b/src/goal/GoalReached.h index 2c854bb..c86677d 100644 --- a/src/goal/GoalReached.h +++ b/src/goal/GoalReached.h @@ -1,74 +1,72 @@ -#ifndef ALAI_GOAL_REACHED -#define ALAI_GOAL_REACHED +#ifndef ALAI_GOAL_GOAL_REACHED_H +#define ALAI_GOAL_GOAL_REACHED_H #include "state_machine/State.h" -#include -#include #include +#include -namespace godot +namespace alai { - /** - * @brief This class controls what happens when the goal flag is in the reached state. - * - */ - class GoalReached : public State - { - GODOT_CLASS(GoalReached, State) + /** + * @brief This class controls what happens when the goal flag is in the reached state. + * + */ + class GoalReached : public alai::State + { + GODOT_CLASS(GoalReached, 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 GoalReached object. - * - */ - GoalReached(); + /** + * @brief Construct a new GoalReached object. + * + */ + GoalReached(); - /** - * @brief Destroy the 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 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. - * - */ - }; - + /** + * @brief Called when the animation of the collected coin has finished. + * + */ + }; } #endif diff --git a/src/godot.cpp b/src/godot.cpp index ca4934b..bb724e7 100644 --- a/src/godot.cpp +++ b/src/godot.cpp @@ -56,10 +56,10 @@ extern "C" void GDN_EXPORT godot_nativescript_init(void *handle) godot::register_class(); godot::register_class(); godot::register_class(); - godot::register_class(); - godot::register_class(); - godot::register_class(); - godot::register_class(); - godot::register_class(); - godot::register_class(); + godot::register_class(); + godot::register_class(); + godot::register_class(); + godot::register_class(); + godot::register_class(); + godot::register_class(); } diff --git a/src/gui/game_over/GameOverScreen.cpp b/src/gui/game_over/GameOverScreen.cpp index 203558e..fc35153 100644 --- a/src/gui/game_over/GameOverScreen.cpp +++ b/src/gui/game_over/GameOverScreen.cpp @@ -1,54 +1,49 @@ #include "gui/game_over/GameOverScreen.h" #include "Event.h" -#include -#include #include -#include #include +#include +#include +#include #include - -using namespace godot; - -void GameOverScreen::_register_methods() +void alai::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("connect_signal", &GameOverScreen::connect_signal); 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(); } -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 level_scene = _resource_loader->load("res://levels/Prototype.tscn"); + godot::Ref level_scene = _resource_loader->load("res://levels/Prototype.tscn"); auto level = level_scene->instance(); auto level_node = get_tree()->get_root()->get_node("Main")->find_node("Level"); if (level_node != nullptr) { - level_node->add_child(level); set_visible(false); call_deferred("connect_signal"); @@ -57,16 +52,13 @@ void GameOverScreen::_on_botonreiniciar_pressed() { WARN_PRINT("Node level not found!"); } - } - } -void GameOverScreen::_on_player_died() //eliminar nivel +void alai::GameOverScreen::_on_player_died() { auto event = get_node("/root/Event"); event->disconnect("player_died", this, "_on_player_died"); - Godot::print("player ded"); set_visible(true); auto level_node = get_tree()->get_root()->get_node("Main")->find_node("Level"); if (level_node != nullptr) @@ -74,6 +66,7 @@ void GameOverScreen::_on_player_died() //eliminar nivel auto child = level_node->get_child(0); if (child != nullptr) { + // Delete the currently active level from the tree. child->queue_free(); } else @@ -85,14 +78,10 @@ void GameOverScreen::_on_player_died() //eliminar nivel { WARN_PRINT("Node level not found!"); } - } -void GameOverScreen::connect_signal() +void alai::GameOverScreen::connect_signal() { auto event = get_node("/root/Event"); event->connect("player_died", this, "_on_player_died"); } - - - diff --git a/src/gui/game_over/GameOverScreen.h b/src/gui/game_over/GameOverScreen.h index 79c5ad9..892a316 100644 --- a/src/gui/game_over/GameOverScreen.h +++ b/src/gui/game_over/GameOverScreen.h @@ -1,62 +1,59 @@ #ifndef ALAI_GAME_OVER_SCREEN_H #define ALAI_GAME_OVER_SCREEN_H -#include #include +#include #include - -namespace godot +namespace alai { - /** - * @brief This class controls what happens when the Coin is in the collected . - * - */ - class GameOverScreen : public CanvasLayer - { - GODOT_CLASS(GameOverScreen, CanvasLayer) + /** + * @brief This class controls what happens when the Coin is in the collected . + * + */ + class GameOverScreen : public godot::CanvasLayer + { + GODOT_CLASS(GameOverScreen, godot::CanvasLayer) - private: - ResourceLoader *_resource_loader; - - public: - /** - * @brief This method registers classes with Godot. - * - * @details This method registers methods, properties, and signals with the Godot engine. - */ - static void _register_methods(); + private: + godot::ResourceLoader *_resource_loader; - /** - * @brief Construct a new GameOverScreen object. - * - */ - GameOverScreen(); + 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 Destroy the GameOverScreen object. - * - */ - ~GameOverScreen(); + /** + * @brief Construct a new GameOverScreen object. + * + */ + GameOverScreen(); - /** - * @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 Destroy the GameOverScreen object. + * + */ + ~GameOverScreen(); - /** - * @brief Called when the collected of the coin is entered. - * - */ - void _ready(); - void _on_player_died(); - void _on_botonreiniciar_pressed(); - void connect_signal(); - - }; - + /** + * @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. + * + */ + void _ready(); + void _on_player_died(); + void _on_restart_button_pressed(); + void connect_signal(); + }; } -#endif \ No newline at end of file +#endif diff --git a/src/player/states/PlayerFall.cpp b/src/player/states/PlayerFall.cpp index d218305..cd6775e 100644 --- a/src/player/states/PlayerFall.cpp +++ b/src/player/states/PlayerFall.cpp @@ -1,4 +1,5 @@ #include "player/states/PlayerFall.h" + #include "player/Player.h" void alai::player::PlayerFall::_register_methods() diff --git a/src/player/states/PlayerIdle.cpp b/src/player/states/PlayerIdle.cpp index 4a03de4..bc8a5ed 100644 --- a/src/player/states/PlayerIdle.cpp +++ b/src/player/states/PlayerIdle.cpp @@ -1,4 +1,5 @@ #include "player/states/PlayerIdle.h" + #include "player/Player.h" void alai::player::PlayerIdle::_register_methods() diff --git a/src/player/states/PlayerJump.cpp b/src/player/states/PlayerJump.cpp index 4a77147..28e5e24 100644 --- a/src/player/states/PlayerJump.cpp +++ b/src/player/states/PlayerJump.cpp @@ -1,4 +1,5 @@ #include "player/states/PlayerJump.h" + #include "player/Player.h" #include diff --git a/src/player/states/PlayerMove.cpp b/src/player/states/PlayerMove.cpp index 7ad60ff..720ce91 100644 --- a/src/player/states/PlayerMove.cpp +++ b/src/player/states/PlayerMove.cpp @@ -1,4 +1,5 @@ #include "player/states/PlayerMove.h" + #include "player/Player.h" void alai::player::PlayerMove::_register_methods() diff --git a/src/state_machine/StateMachine.cpp b/src/state_machine/StateMachine.cpp index ef6cb34..803972f 100644 --- a/src/state_machine/StateMachine.cpp +++ b/src/state_machine/StateMachine.cpp @@ -1,4 +1,5 @@ #include "state_machine/StateMachine.h" + #include "state_machine/State.h" void alai::StateMachine::_register_methods()