From b718c0f31b6d2162522da69521cf100f2c62ddfe Mon Sep 17 00:00:00 2001 From: Martin Araneda Date: Sun, 28 Aug 2022 15:02:28 -0400 Subject: [PATCH 01/36] no changes --- godot/Main.tscn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/godot/Main.tscn b/godot/Main.tscn index 5babece..e3fc9ab 100644 --- a/godot/Main.tscn +++ b/godot/Main.tscn @@ -1,7 +1,7 @@ [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://levels/PrototypeEnemies.tscn" type="PackedScene" id=2] [ext_resource path="res://GUI/GameOver.tscn" type="PackedScene" id=3] [node name="Main" type="Node"] -- 2.30.2 From 7e57e782051045c435835d3cfa9f7da24e9b57e7 Mon Sep 17 00:00:00 2001 From: Martin Araneda Date: Sun, 28 Aug 2022 15:04:50 -0400 Subject: [PATCH 02/36] Revert "no changes" This reverts commit b718c0f31b6d2162522da69521cf100f2c62ddfe. --- godot/Main.tscn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/godot/Main.tscn b/godot/Main.tscn index e3fc9ab..5babece 100644 --- a/godot/Main.tscn +++ b/godot/Main.tscn @@ -1,7 +1,7 @@ [gd_scene load_steps=4 format=2] [ext_resource path="res://Main.gdns" type="Script" id=1] -[ext_resource path="res://levels/PrototypeEnemies.tscn" type="PackedScene" id=2] +[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"] -- 2.30.2 From 0e4bad4823dd71b9e3d3f701358554a8322f6369 Mon Sep 17 00:00:00 2001 From: Martin Araneda Date: Sun, 28 Aug 2022 20:15:40 -0400 Subject: [PATCH 03/36] R prototype lvl made. Coins and coinHUD added --- godot/Main.tscn | 2 +- godot/levels/Prototype.tscn | 1 - godot/levels/PrototypeR.tmx | 19 ++++++++ godot/levels/PrototypeR.tmx.import | 24 ++++++++++ godot/levels/PrototypeR.tscn | 72 ++++++++++++++++++++++++++++ src/gui/game_over/GameOverScreen.cpp | 5 +- 6 files changed, 119 insertions(+), 4 deletions(-) create mode 100644 godot/levels/PrototypeR.tmx create mode 100644 godot/levels/PrototypeR.tmx.import create mode 100644 godot/levels/PrototypeR.tscn diff --git a/godot/Main.tscn b/godot/Main.tscn index 5babece..d63b2cb 100644 --- a/godot/Main.tscn +++ b/godot/Main.tscn @@ -1,7 +1,7 @@ [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://levels/PrototypeR.tscn" type="PackedScene" id=2] [ext_resource path="res://GUI/GameOver.tscn" type="PackedScene" id=3] [node name="Main" type="Node"] diff --git a/godot/levels/Prototype.tscn b/godot/levels/Prototype.tscn index b71e0c7..320b814 100644 --- a/godot/levels/Prototype.tscn +++ b/godot/levels/Prototype.tscn @@ -14,7 +14,6 @@ collision_layer = 5 [node name="Camera2D" type="Camera2D" parent="Player"] -current = true limit_left = 0 limit_top = 0 limit_right = 512 diff --git a/godot/levels/PrototypeR.tmx b/godot/levels/PrototypeR.tmx new file mode 100644 index 0000000..57d9e74 --- /dev/null +++ b/godot/levels/PrototypeR.tmx @@ -0,0 +1,19 @@ + + + + + + KLUv/WAAO9UGAOQDABIAAAATFAAnEiYoEjo8YgAAADs6dQA6iwAAAIwAOnUAihIoADd/YwAAAGQAAAB4AAAAdiY3ADqLYwAAgAA8oBCVNdsBwAKTQCJcY8XxUYoarT8gQjyeu5O6nkqpOlT1gMJhyWO43xyk5jp+D3SGOxcoT52U4vScQx63fcb98i+k3jK5QUu8pNUR8O+i4l7VPW51R5d4k1T3FuabG4vErcrOI+U6fRflI6vfRsa41pUIv1HPe0OudqI1qDNHH2bcTSH3r27pd6Tac6lM+3bwXaj+q2cxvogB + + + + + KLUv/WAAOz0FAIQCADEAAAAyMwACAAAAAwQAAhYAAAAXGAB6AAAAe3wAF4ZfAHuIAIZeiCygMLF1UIIUiARiZAelj/9XjXZV/ipp0q1TfoI4FDJcav6xkgcm3cqld/XLYVzNgPGrRkX6pwiG831dQsKVhvGrM0E5nOTUdZpyl96SqGcYDzh1mVBuKT0+fmorpXmjgBlElduJp59uitTebrC/onYW//xER7myT2JL+hkD + + + + + KLUv/WAAO70CAKgAdAB0AIiINzeIN0YjWjcjNyNuNwAaoJD2AWBDhVoO4YKf+iiKEtrHJVQSqc4GzhDlVlFe0Tb1bDJ629TRhBsftwpQtCpKtEu19HH9uSSqrEzywUAhHQ== + + + diff --git a/godot/levels/PrototypeR.tmx.import b/godot/levels/PrototypeR.tmx.import new file mode 100644 index 0000000..17122e4 --- /dev/null +++ b/godot/levels/PrototypeR.tmx.import @@ -0,0 +1,24 @@ +[remap] + +importer="vnen.tiled_importer" +type="PackedScene" +path="res://.import/PrototypeR.tmx-dfb7d18f520c5c44182a13443fe1b69c.scn" + +[deps] + +source_file="res://levels/PrototypeR.tmx" +dest_files=[ "res://.import/PrototypeR.tmx-dfb7d18f520c5c44182a13443fe1b69c.scn" ] + +[params] + +custom_properties=true +tile_metadata=false +uv_clip=true +y_sort=false +image_flags=0 +collision_layer=2 +collision_mask=0 +embed_internal_images=false +save_tiled_properties=false +add_background=true +post_import_script="" diff --git a/godot/levels/PrototypeR.tscn b/godot/levels/PrototypeR.tscn new file mode 100644 index 0000000..299779a --- /dev/null +++ b/godot/levels/PrototypeR.tscn @@ -0,0 +1,72 @@ +[gd_scene load_steps=7 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/PrototypeR.tmx" type="PackedScene" id=3] +[ext_resource path="res://assets/backgrounds/hills.png" type="Texture" id=4] +[ext_resource path="res://hud/CoinHUD.tscn" type="PackedScene" id=5] +[ext_resource path="res://collectables/coin/Coin.tscn" type="PackedScene" id=6] + +[node name="Prototype" type="Node2D"] + +[node name="Player" parent="." instance=ExtResource( 2 )] +collision_layer = 5 + +[node name="Camera2D" type="Camera2D" parent="Player"] +current = true +limit_left = 0 +limit_top = 0 +limit_right = 512 +limit_bottom = 288 +drag_margin_h_enabled = true +drag_margin_v_enabled = true +__meta__ = { +"_edit_bone_": true +} + +[node name="VisibilityNotifier2D" type="VisibilityNotifier2D" parent="Player/Camera2D"] +rect = Rect2( 0, 0, 24, 24 ) + +[node name="ParallaxBackground" type="ParallaxBackground" parent="."] + +[node name="ParallaxLayer" type="ParallaxLayer" parent="ParallaxBackground"] +motion_scale = Vector2( 0.2, 0.1 ) +motion_offset = Vector2( 0, -288 ) +motion_mirroring = Vector2( 528, 0 ) + +[node name="Sprite" type="Sprite" parent="ParallaxBackground/ParallaxLayer"] +texture = ExtResource( 4 ) +centered = false + +[node name="Map" type="Node2D" parent="."] + +[node name="PrototypeR" parent="Map" instance=ExtResource( 3 )] +script = ExtResource( 1 ) + +[node name="CoinHUD" parent="." instance=ExtResource( 5 )] + +[node name="Coins" type="Node" parent="."] + +[node name="Coin" parent="Coins" instance=ExtResource( 6 )] +position = Vector2( 270, 432 ) + +[node name="Coin2" parent="Coins" instance=ExtResource( 6 )] +position = Vector2( 846, 252 ) + +[node name="Coin3" parent="Coins" instance=ExtResource( 6 )] +position = Vector2( 1278, 342 ) + +[node name="Coin4" parent="Coins" instance=ExtResource( 6 )] +position = Vector2( 1278, 180 ) + +[node name="Coin5" parent="Coins" instance=ExtResource( 6 )] +position = Vector2( 522, 270 ) + +[node name="Coin6" parent="Coins" instance=ExtResource( 6 )] +position = Vector2( 990, 324 ) + +[node name="Coin7" parent="Coins" instance=ExtResource( 6 )] +position = Vector2( 468, 306 ) + +[node name="Coin8" parent="Coins" instance=ExtResource( 6 )] +position = Vector2( 576, 306 ) diff --git a/src/gui/game_over/GameOverScreen.cpp b/src/gui/game_over/GameOverScreen.cpp index fc35153..ca87875 100644 --- a/src/gui/game_over/GameOverScreen.cpp +++ b/src/gui/game_over/GameOverScreen.cpp @@ -36,9 +36,10 @@ void alai::GameOverScreen::_ready() void alai::GameOverScreen::_on_restart_button_pressed() { - if (_resource_loader->exists("res://levels/Prototype.tscn")) + /*_r*/ + if (_resource_loader->exists("res://levels/PrototypeR.tscn")) { - godot::Ref level_scene = _resource_loader->load("res://levels/Prototype.tscn"); + godot::Ref level_scene = _resource_loader->load("res://levels/PrototypeR.tscn"); auto level = level_scene->instance(); auto level_node = get_tree()->get_root()->get_node("Main")->find_node("Level"); -- 2.30.2 From 0f94363266dcfd7e032d9c8ad3d7d2ceb744fefb Mon Sep 17 00:00:00 2001 From: Chris Cromer Date: Tue, 30 Aug 2022 23:58:02 -0400 Subject: [PATCH 04/36] refactor game over screen --- godot/Main.tscn | 2 +- godot/gui/GameOver.tscn | 48 +++++++++++++++++++++++++++++++++++ godot/gui/GameOverScreen.gdns | 8 ++++++ 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 godot/gui/GameOver.tscn create mode 100644 godot/gui/GameOverScreen.gdns diff --git a/godot/Main.tscn b/godot/Main.tscn index 5babece..2cdfefa 100644 --- a/godot/Main.tscn +++ b/godot/Main.tscn @@ -2,7 +2,7 @@ [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] +[ext_resource path="res://gui/GameOver.tscn" type="PackedScene" id=3] [node name="Main" type="Node"] pause_mode = 2 diff --git a/godot/gui/GameOver.tscn b/godot/gui/GameOver.tscn new file mode 100644 index 0000000..bff3216 --- /dev/null +++ b/godot/gui/GameOver.tscn @@ -0,0 +1,48 @@ +[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/GameOverScreen.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="CanvasLayer"] +script = ExtResource( 3 ) + +[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 ) +color = Color( 0, 0, 0, 1 ) + +[node name="Label" type="Label" parent="Control"] +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="RestartButton" type="Button" parent="Control"] +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" + +[connection signal="pressed" from="Control/RestartButton" to="." method="_on_restart_button_pressed"] diff --git a/godot/gui/GameOverScreen.gdns b/godot/gui/GameOverScreen.gdns new file mode 100644 index 0000000..750e9bf --- /dev/null +++ b/godot/gui/GameOverScreen.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 ) -- 2.30.2 From bc82d3d08cc33fa564efeaf043cf22a17b054241 Mon Sep 17 00:00:00 2001 From: Chris Cromer Date: Wed, 31 Aug 2022 00:05:08 -0400 Subject: [PATCH 05/36] fix header guards --- src/gui/game_over/GameOverScreen.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/game_over/GameOverScreen.h b/src/gui/game_over/GameOverScreen.h index 892a316..cb79374 100644 --- a/src/gui/game_over/GameOverScreen.h +++ b/src/gui/game_over/GameOverScreen.h @@ -1,5 +1,5 @@ -#ifndef ALAI_GAME_OVER_SCREEN_H -#define ALAI_GAME_OVER_SCREEN_H +#ifndef ALAI_GAME_OVER_GAME_OVER_SCREEN_H +#define ALAI_GAME_OVER_GAME_OVER_SCREEN_H #include #include -- 2.30.2 From 8863a74c0990891272f37b84ee4862d1087e1392 Mon Sep 17 00:00:00 2001 From: Chris Cromer Date: Wed, 31 Aug 2022 00:24:02 -0400 Subject: [PATCH 06/36] remove node include --- src/gui/game_over/GameOverScreen.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/gui/game_over/GameOverScreen.cpp b/src/gui/game_over/GameOverScreen.cpp index fc35153..a379fbb 100644 --- a/src/gui/game_over/GameOverScreen.cpp +++ b/src/gui/game_over/GameOverScreen.cpp @@ -1,7 +1,6 @@ #include "gui/game_over/GameOverScreen.h" #include "Event.h" -#include #include #include #include -- 2.30.2 From ee34563424f421461aebc6ff290a1b68b47a88e2 Mon Sep 17 00:00:00 2001 From: Chris Cromer Date: Wed, 31 Aug 2022 00:24:38 -0400 Subject: [PATCH 07/36] add player won signal --- src/Event.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Event.cpp b/src/Event.cpp index 6561979..e457ae7 100644 --- a/src/Event.cpp +++ b/src/Event.cpp @@ -7,7 +7,7 @@ void alai::Event::_register_methods() 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"); - + godot::register_signal("player_won"); } alai::Event::Event() -- 2.30.2 From eb14adbb0ea99fca1008b4d1adaf5acaa3b51a88 Mon Sep 17 00:00:00 2001 From: Chris Cromer Date: Wed, 31 Aug 2022 00:36:01 -0400 Subject: [PATCH 08/36] add the godot namespace to the calls so it is more clear where the method resides --- src/CameraLimit.cpp | 2 +- src/coin/CoinCollected.cpp | 7 +++---- src/coin/CoinCounter.cpp | 4 ++-- src/coin/CoinNotCollected.cpp | 6 +++--- src/goal/GoalNotReached.cpp | 6 +++--- src/goal/GoalReached.cpp | 4 ++-- src/gui/game_over/GameOverScreen.cpp | 8 ++++---- src/player/states/PlayerFall.cpp | 6 +++--- src/player/states/PlayerIdle.cpp | 6 +++--- src/player/states/PlayerJump.cpp | 6 +++--- src/player/states/PlayerMove.cpp | 6 +++--- src/state_machine/State.cpp | 10 +++++----- 12 files changed, 35 insertions(+), 36 deletions(-) diff --git a/src/CameraLimit.cpp b/src/CameraLimit.cpp index cdc4add..e981127 100644 --- a/src/CameraLimit.cpp +++ b/src/CameraLimit.cpp @@ -7,7 +7,7 @@ void alai::CameraLimit::_register_methods() { - register_method("_ready", &CameraLimit::_ready); + godot::register_method("_ready", &CameraLimit::_ready); } alai::CameraLimit::CameraLimit() diff --git a/src/coin/CoinCollected.cpp b/src/coin/CoinCollected.cpp index 5c30b82..cc6155e 100644 --- a/src/coin/CoinCollected.cpp +++ b/src/coin/CoinCollected.cpp @@ -6,9 +6,9 @@ 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); + godot::register_method("_state_enter", &CoinCollected::_state_enter); + godot::register_method("_state_exit", &CoinCollected::_state_exit); + godot::register_method("_on_animation_finished", &CoinCollected::_on_animation_finished); } alai::CoinCollected::CoinCollected() @@ -37,7 +37,6 @@ void alai::CoinCollected::_state_enter() void alai::CoinCollected::_state_exit() { - } void alai::CoinCollected::_on_animation_finished(godot::String anim_name) diff --git a/src/coin/CoinCounter.cpp b/src/coin/CoinCounter.cpp index 667ea9e..c0f5cbe 100644 --- a/src/coin/CoinCounter.cpp +++ b/src/coin/CoinCounter.cpp @@ -6,8 +6,8 @@ void alai::CoinCounter::_register_methods() { - register_method("_on_coin_collected", &CoinCounter::_on_coin_collected); - register_method("_ready", &CoinCounter::_ready); + godot::register_method("_on_coin_collected", &CoinCounter::_on_coin_collected); + godot::register_method("_ready", &CoinCounter::_ready); } alai::CoinCounter::CoinCounter() diff --git a/src/coin/CoinNotCollected.cpp b/src/coin/CoinNotCollected.cpp index c03aa0b..b1c84ee 100644 --- a/src/coin/CoinNotCollected.cpp +++ b/src/coin/CoinNotCollected.cpp @@ -4,9 +4,9 @@ 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); + godot::register_method("_state_enter", &CoinNotCollected::_state_enter); + godot::register_method("_state_exit", &CoinNotCollected::_state_exit); + godot::register_method("_on_body_entered", &CoinNotCollected::_on_body_entered); } alai::CoinNotCollected::CoinNotCollected() diff --git a/src/goal/GoalNotReached.cpp b/src/goal/GoalNotReached.cpp index 08d55f3..8fbec1f 100644 --- a/src/goal/GoalNotReached.cpp +++ b/src/goal/GoalNotReached.cpp @@ -4,9 +4,9 @@ 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); + godot::register_method("_state_enter", &GoalNotReached::_state_enter); + godot::register_method("_state_exit", &GoalNotReached::_state_exit); + godot::register_method("_on_Goal_body_entered", &GoalNotReached::_on_Goal_body_entered); } alai::GoalNotReached::GoalNotReached() diff --git a/src/goal/GoalReached.cpp b/src/goal/GoalReached.cpp index 06f882c..38fb8fa 100644 --- a/src/goal/GoalReached.cpp +++ b/src/goal/GoalReached.cpp @@ -4,8 +4,8 @@ void alai::GoalReached::_register_methods() { - register_method("_state_enter", &GoalReached::_state_enter); - register_method("_state_exit", &GoalReached::_state_exit); + godot::register_method("_state_enter", &GoalReached::_state_enter); + godot::register_method("_state_exit", &GoalReached::_state_exit); } alai::GoalReached::GoalReached() diff --git a/src/gui/game_over/GameOverScreen.cpp b/src/gui/game_over/GameOverScreen.cpp index a379fbb..f6f604f 100644 --- a/src/gui/game_over/GameOverScreen.cpp +++ b/src/gui/game_over/GameOverScreen.cpp @@ -9,10 +9,10 @@ void alai::GameOverScreen::_register_methods() { - 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); + godot::register_method("_on_restart_button_pressed", &GameOverScreen::_on_restart_button_pressed); + godot::register_method("_ready", &GameOverScreen::_ready); + godot::register_method("connect_signal", &GameOverScreen::connect_signal); + godot::register_method("_on_player_died", &GameOverScreen::_on_player_died); } alai::GameOverScreen::GameOverScreen() diff --git a/src/player/states/PlayerFall.cpp b/src/player/states/PlayerFall.cpp index cd6775e..adc9671 100644 --- a/src/player/states/PlayerFall.cpp +++ b/src/player/states/PlayerFall.cpp @@ -4,9 +4,9 @@ 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); + godot::register_method("_state_enter", &PlayerFall::_state_enter); + godot::register_method("_state_exit", &PlayerFall::_state_exit); + godot::register_method("_physics_process", &PlayerFall::_physics_process); } alai::player::PlayerFall::PlayerFall() diff --git a/src/player/states/PlayerIdle.cpp b/src/player/states/PlayerIdle.cpp index bc8a5ed..1043f52 100644 --- a/src/player/states/PlayerIdle.cpp +++ b/src/player/states/PlayerIdle.cpp @@ -4,9 +4,9 @@ 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); + godot::register_method("_state_enter", &PlayerIdle::_state_enter); + godot::register_method("_state_exit", &PlayerIdle::_state_exit); + godot::register_method("_physics_process", &PlayerIdle::_physics_process); } alai::player::PlayerIdle::PlayerIdle() diff --git a/src/player/states/PlayerJump.cpp b/src/player/states/PlayerJump.cpp index 28e5e24..b5417ac 100644 --- a/src/player/states/PlayerJump.cpp +++ b/src/player/states/PlayerJump.cpp @@ -6,9 +6,9 @@ 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); + godot::register_method("_state_enter", &PlayerJump::_state_enter); + godot::register_method("_state_exit", &PlayerJump::_state_exit); + godot::register_method("_physics_process", &PlayerJump::_physics_process); } alai::player::PlayerJump::PlayerJump() diff --git a/src/player/states/PlayerMove.cpp b/src/player/states/PlayerMove.cpp index 720ce91..23014db 100644 --- a/src/player/states/PlayerMove.cpp +++ b/src/player/states/PlayerMove.cpp @@ -4,9 +4,9 @@ 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); + godot::register_method("_state_enter", &PlayerMove::_state_enter); + godot::register_method("_state_exit", &PlayerMove::_state_exit); + godot::register_method("_physics_process", &PlayerMove::_physics_process); } alai::player::PlayerMove::PlayerMove() diff --git a/src/state_machine/State.cpp b/src/state_machine/State.cpp index 1c66968..eff2576 100644 --- a/src/state_machine/State.cpp +++ b/src/state_machine/State.cpp @@ -2,11 +2,11 @@ void alai::State::_register_methods() { - register_method("set_parent", &State::set_parent); - register_method("get_parent", &State::get_parent); - register_method("set_state_machine", &State::set_state_machine); - register_method("_state_enter", &State::_state_enter); - register_method("_state_exit", &State::_state_exit); + godot::register_method("set_parent", &State::set_parent); + godot::register_method("get_parent", &State::get_parent); + godot::register_method("set_state_machine", &State::set_state_machine); + godot::register_method("_state_enter", &State::_state_enter); + godot::register_method("_state_exit", &State::_state_exit); } alai::State::State() -- 2.30.2 From 08216d061ca4f12b11e4eef8072ee6bfc49f65ad Mon Sep 17 00:00:00 2001 From: Chris Cromer Date: Wed, 31 Aug 2022 01:07:56 -0400 Subject: [PATCH 09/36] add a win screen when the flag is reached --- godot/Main.tscn | 6 ++- godot/gui/GameWon.tscn | 48 ++++++++++++++++++++++ godot/gui/GameWonScreen.gdns | 8 ++++ src/goal/GoalReached.cpp | 5 ++- src/godot.cpp | 2 + src/gui/game_won/GameWonScreen.cpp | 65 ++++++++++++++++++++++++++++++ src/gui/game_won/GameWonScreen.h | 51 +++++++++++++++++++++++ 7 files changed, 183 insertions(+), 2 deletions(-) create mode 100644 godot/gui/GameWon.tscn create mode 100644 godot/gui/GameWonScreen.gdns create mode 100644 src/gui/game_won/GameWonScreen.cpp create mode 100644 src/gui/game_won/GameWonScreen.h diff --git a/godot/Main.tscn b/godot/Main.tscn index 2cdfefa..de0bf8a 100644 --- a/godot/Main.tscn +++ b/godot/Main.tscn @@ -1,8 +1,9 @@ -[gd_scene load_steps=4 format=2] +[gd_scene load_steps=5 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] +[ext_resource path="res://gui/GameWon.tscn" type="PackedScene" id=4] [node name="Main" type="Node"] pause_mode = 2 @@ -14,3 +15,6 @@ pause_mode = 1 [node name="GameOver" parent="." instance=ExtResource( 3 )] visible = false + +[node name="GameWon" parent="." instance=ExtResource( 4 )] +visible = false diff --git a/godot/gui/GameWon.tscn b/godot/gui/GameWon.tscn new file mode 100644 index 0000000..49889fc --- /dev/null +++ b/godot/gui/GameWon.tscn @@ -0,0 +1,48 @@ +[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/GameWonScreen.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="GameWon" type="CanvasLayer"] +script = ExtResource( 3 ) + +[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 ) +color = Color( 0, 0, 0, 1 ) + +[node name="Label" type="Label" parent="Control"] +margin_left = 66.0 +margin_top = 17.0 +margin_right = 456.0 +margin_bottom = 71.0 +custom_fonts/font = SubResource( 1 ) +text = "GANASTE!" +align = 1 + +[node name="QuitButton" type="Button" parent="Control"] +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 = "SALIR" + +[connection signal="pressed" from="Control/QuitButton" to="." method="_on_quit_button_pressed"] diff --git a/godot/gui/GameWonScreen.gdns b/godot/gui/GameWonScreen.gdns new file mode 100644 index 0000000..1d6223b --- /dev/null +++ b/godot/gui/GameWonScreen.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 = "GameWonScreen" +class_name = "GameWonScreen" +library = ExtResource( 1 ) diff --git a/src/goal/GoalReached.cpp b/src/goal/GoalReached.cpp index 38fb8fa..6afb5f0 100644 --- a/src/goal/GoalReached.cpp +++ b/src/goal/GoalReached.cpp @@ -1,5 +1,7 @@ #include "goal/GoalReached.h" +#include "Event.h" + #include void alai::GoalReached::_register_methods() @@ -22,7 +24,8 @@ void alai::GoalReached::_init() void alai::GoalReached::_state_enter() { - godot::Godot::print("Flag touched"); + auto event = get_node("/root/Event"); + event->emit_signal("player_won"); } void alai::GoalReached::_state_exit() diff --git a/src/godot.cpp b/src/godot.cpp index bb724e7..5793fee 100644 --- a/src/godot.cpp +++ b/src/godot.cpp @@ -16,6 +16,7 @@ #include "goal/GoalReached.h" #include "goal/GoalNotReached.h" #include "gui/game_over/GameOverScreen.h" +#include "gui/game_won/GameWonScreen.h" /** * @brief This function connects the gdnative init function. @@ -62,4 +63,5 @@ extern "C" void GDN_EXPORT godot_nativescript_init(void *handle) godot::register_class(); godot::register_class(); godot::register_class(); + godot::register_class(); } diff --git a/src/gui/game_won/GameWonScreen.cpp b/src/gui/game_won/GameWonScreen.cpp new file mode 100644 index 0000000..d57f950 --- /dev/null +++ b/src/gui/game_won/GameWonScreen.cpp @@ -0,0 +1,65 @@ +#include "gui/game_won/GameWonScreen.h" +#include "Event.h" + +#include +#include + +void alai::GameWonScreen::_register_methods() +{ + godot::register_method("_ready", &GameWonScreen::_ready); + godot::register_method("connect_signal", &GameWonScreen::connect_signal); + godot::register_method("_on_player_won", &GameWonScreen::_on_player_won); + godot::register_method("_on_quit_button_pressed", &GameWonScreen::_on_quit_button_pressed); +} + +alai::GameWonScreen::GameWonScreen() +{ +} + +alai::GameWonScreen::~GameWonScreen() +{ +} + +void alai::GameWonScreen::_init() +{ +} + +void alai::GameWonScreen::_ready() +{ + connect_signal(); +} + +void alai::GameWonScreen::_on_quit_button_pressed() +{ + get_tree()->quit(); +} + +void alai::GameWonScreen::_on_player_won() +{ + auto event = get_node("/root/Event"); + event->disconnect("player_won", this, "_on_player_won"); + 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 alai::GameWonScreen::connect_signal() +{ + auto event = get_node("/root/Event"); + event->connect("player_won", this, "_on_player_won"); +} diff --git a/src/gui/game_won/GameWonScreen.h b/src/gui/game_won/GameWonScreen.h new file mode 100644 index 0000000..987b7a1 --- /dev/null +++ b/src/gui/game_won/GameWonScreen.h @@ -0,0 +1,51 @@ +#ifndef ALAI_GAME_WON_GAME_WON_SCREEN_H +#define ALAI_GAME_WON_GAME_WON_SCREEN_H + +#include +#include + +namespace alai +{ + /** + * @brief This class controls what happens when the game is won. + * + */ + class GameWonScreen : public godot::CanvasLayer + { + GODOT_CLASS(GameWonScreen, godot::CanvasLayer) + + 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 GameWonScreen object. + * + */ + GameWonScreen(); + + /** + * @brief Destroy the GameWonScreen object. + * + */ + ~GameWonScreen(); + + /** + * @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(); + + void _ready(); + void _on_player_won(); + void _on_quit_button_pressed(); + void connect_signal(); + }; +} + +#endif -- 2.30.2 From ea83bf8660901b918dd28990f6c14ef18ee940ea Mon Sep 17 00:00:00 2001 From: Chris Cromer Date: Thu, 1 Sep 2022 11:24:46 -0400 Subject: [PATCH 10/36] add new events --- src/Event.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Event.cpp b/src/Event.cpp index e457ae7..8795d1e 100644 --- a/src/Event.cpp +++ b/src/Event.cpp @@ -2,6 +2,9 @@ void alai::Event::_register_methods() { + godot::register_signal("game_started"); + godot::register_signal("monitor_loaded"); + godot::register_signal("level_loaded"); 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); -- 2.30.2 From cb8173427979dda0285170c1541fbb2086519f3a Mon Sep 17 00:00:00 2001 From: Chris Cromer Date: Thu, 1 Sep 2022 11:26:34 -0400 Subject: [PATCH 11/36] make enemies use the event bus --- godot/characters/enemies/WalkingEnemy.gd | 8 ++++++++ godot/characters/enemies/blightwing/Blightwing.gd | 13 +++++++++++-- godot/characters/enemies/blockface/Blockface.gd | 10 ++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/godot/characters/enemies/WalkingEnemy.gd b/godot/characters/enemies/WalkingEnemy.gd index c1c54b5..94a01b5 100644 --- a/godot/characters/enemies/WalkingEnemy.gd +++ b/godot/characters/enemies/WalkingEnemy.gd @@ -16,6 +16,7 @@ func _ready() -> void: $AnimatedSprite.flip_h = true $FloorChecker.position.x = $CollisionShape2D.shape.get_extents().x * direction $FloorChecker.enabled = detect_edges + Event.connect("level_loaded", self, "_on_level_loaded") func _physics_process(_delta: float) -> void: @@ -33,6 +34,13 @@ func _physics_process(_delta: float) -> void: if collision.collider.name == "Player": emit_signal("player_touched") + Event.emit_signal("object_updated", self.get_name(), "Walking", global_position, velocity) + func squash() -> void: + Event.emit_signal("object_removed", self.get_name()) queue_free() + + +func _on_level_loaded() -> void: + Event.emit_signal("object_created", self.get_name(), "Walking", global_position, Vector2(0, 0)) diff --git a/godot/characters/enemies/blightwing/Blightwing.gd b/godot/characters/enemies/blightwing/Blightwing.gd index 6186bea..1446628 100644 --- a/godot/characters/enemies/blightwing/Blightwing.gd +++ b/godot/characters/enemies/blightwing/Blightwing.gd @@ -22,6 +22,8 @@ func _ready() -> void: if direction == 1: $AnimatedSprite.flip_h = true + Event.connect("level_loaded", self, "_on_level_loaded") + func _physics_process(delta: float) -> void: if $LeftWallChecker.is_colliding(): @@ -29,17 +31,18 @@ func _physics_process(delta: float) -> void: elif $RightWallChecker.is_colliding(): wall_checker_collided($RightWallChecker) + var velocity: Vector2 = Vector2(0, 0) if not follow_path: var target_position = position target_position.x *= 2 * direction position = position.move_toward(target_position, round(speed * delta)) - var velocity = get_velocity_towards_target(delta) + velocity = get_velocity_towards_target(delta) var collision = move_and_collide(velocity, true, true, true) if collision and collision.collider.name != "Player": var _collision = move_and_collide(velocity) else: - var velocity = get_velocity_towards_target(delta) + velocity = get_velocity_towards_target(delta) var collision = move_and_collide(velocity, true, true, true) if collision and collision.collider.name != "Player": @@ -60,6 +63,8 @@ func _physics_process(delta: float) -> void: elif start_position.x + target.x < position.x: $AnimatedSprite.flip_h = false + Event.emit_signal("object_updated", self.get_name(), "Flying", global_position, velocity) + func get_velocity_towards_target(delta: float) -> Vector2: var velocity = Vector2(0, 0) @@ -80,3 +85,7 @@ func wall_checker_collided(wall_checker: RayCast2D) -> void: emit_signal("player_touched") direction *= -1 $AnimatedSprite.flip_h = not $AnimatedSprite.flip_h + + +func _on_level_loaded() -> void: + Event.emit_signal("object_created", self.get_name(), "Flying", global_position, Vector2(0, 0)) diff --git a/godot/characters/enemies/blockface/Blockface.gd b/godot/characters/enemies/blockface/Blockface.gd index b307882..3f52a5a 100644 --- a/godot/characters/enemies/blockface/Blockface.gd +++ b/godot/characters/enemies/blockface/Blockface.gd @@ -11,9 +11,14 @@ export var fall_speed = 75.0 var return_to_start: bool = false +func _ready() -> void: + Event.connect("level_loaded", self, "_on_level_loaded") + + func _physics_process(delta: float) -> void: if return_to_start: position = position.move_toward(start_position, speed * delta) + Event.emit_signal("object_updated", self.get_name(), "Rising", global_position, velocity) else: var collision = move_and_collide(Vector2(0, (position.y + fall_speed) * delta)) if collision: @@ -21,7 +26,12 @@ func _physics_process(delta: float) -> void: $AnimatedSprite.play("normal") if collision.collider.name == "Player": emit_signal("player_touched") + Event.emit_signal("object_updated", self.get_name(), "Falling", global_position, velocity) if position.y <= start_position.y: return_to_start = false $AnimatedSprite.play("angry") + + +func _on_level_loaded() -> void: + Event.emit_signal("object_created", self.get_name(), "Falling", global_position, Vector2(0, 0)) -- 2.30.2 From e29492447db42b2cc64cf8da7716d30d31ae73ef Mon Sep 17 00:00:00 2001 From: Chris Cromer Date: Thu, 1 Sep 2022 11:30:01 -0400 Subject: [PATCH 12/36] change the way level gets loaded and use the event bus --- godot/monitor/Monitor.gd | 43 ++++++++++++++++++++++++++++++++++------ src/Main.cpp | 21 +++++++++----------- src/Main.h | 3 +-- src/player/Player.cpp | 7 +++++-- src/player/Player.h | 2 +- 5 files changed, 53 insertions(+), 23 deletions(-) diff --git a/godot/monitor/Monitor.gd b/godot/monitor/Monitor.gd index 5e34c64..99404ac 100644 --- a/godot/monitor/Monitor.gd +++ b/godot/monitor/Monitor.gd @@ -1,10 +1,8 @@ extends Node -signal monitor_loaded() - - export var monitor_enabled: bool = false +export var debug: bool = false export var development_url: String = "http://localhost:4050/api/v1" var url_real: String = "https://alai.cromer.cl/api/v1" export var use_development_url: bool = false @@ -53,7 +51,11 @@ 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("game_started", self, "_on_game_started") + Event.connect("player_died", self, "_on_game_over") + Event.connect("player_won", self, "_on_game_won") Event.connect("coin_collected", self, "_on_coin_update") + game_version = get_parent().game_version player["rut"] = "" @@ -108,7 +110,7 @@ func _physics_process(_delta: float) -> void: if monitor_enabled: if has_node("MonitorGUI") and not $MonitorGUI.visible: $MonitorGUI.visible = true - emit_signal("monitor_loaded") + Event.emit_signal("monitor_loaded") if started and not get_tree().paused: var frame = empty_frame.duplicate(true) @@ -130,13 +132,14 @@ func _physics_process(_delta: float) -> void: start_monitor() else: get_tree().paused = false - emit_signal("monitor_loaded") + Event.emit_signal("monitor_loaded") queue_free() func _on_input_validated(validated_player: Dictionary) -> void: $MonitorGUI.queue_free() get_tree().paused = false + Event.emit_signal("game_started") player = validated_player.duplicate(true) game["player"] = player @@ -188,6 +191,7 @@ func remove_object(name: String) -> void: for i in range(0, objects.size()): if objects[i]["name"] == name: objects.remove(i) + return func _on_coin_update(amount: int) -> void: @@ -219,7 +223,16 @@ func send_data() -> void: print("Body B: " + String(body.length())) print("Body MB: " + String(body.length() / pow(2, 20))) - $HTTPRequest.request(url + "/game", headers, false, HTTPClient.METHOD_POST, body) + if not debug: + $HTTPRequest.request(url + "/game", headers, false, HTTPClient.METHOD_POST, body) + else: + var file = File.new() + if file.open("user://game.json", File.WRITE) != 0: + print_debug("Could not open game.json for writing!") + return + + file.store_string(json) + file.close() func compress_payload(payload: String) -> String: @@ -231,3 +244,21 @@ func compress_payload(payload: String) -> String: return new_payload +func _on_game_started() -> void: + print_debug("started game") + if not started: + start_monitor() + + +func _on_game_over() -> void: + if started: + stop_monitor() + game["won"] = false + send_data() + + +func _on_game_won() -> void: + if started: + stop_monitor() + game["won"] = true + send_data() diff --git a/src/Main.cpp b/src/Main.cpp index 4f895bd..661e0e0 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -1,5 +1,7 @@ #include "Main.h" +#include "Event.h" + #include void alai::Main::_register_methods() @@ -86,24 +88,21 @@ void alai::Main::_ready() void alai::Main::_on_monitor_loaded() { - if (level != nullptr) - { - auto level_node = load_level(); - connect("monitor_loaded", level_node->get_child(0)->find_node("Player", true, false), "_on_monitor_loaded"); - emit_signal("monitor_loaded"); - } + load_level(); + auto event = get_node("/root/Event"); + event->emit_signal("level_loaded"); + get_tree()->set_pause(true); } void alai::Main::load_monitor() { + auto event = get_node("/root/Event"); + event->connect("monitor_loaded", this, "_on_monitor_loaded"); 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); } -godot::Node *alai::Main::load_level() +void alai::Main::load_level() { if (level != nullptr) { @@ -111,9 +110,7 @@ godot::Node *alai::Main::load_level() auto loaded_level = level->instance(); auto level_node = get_node("Level"); level_node->add_child(loaded_level); - return level_node; } - return nullptr; } void alai::Main::_physics_process(float delta) diff --git a/src/Main.h b/src/Main.h index 9487338..a3cb313 100644 --- a/src/Main.h +++ b/src/Main.h @@ -224,9 +224,8 @@ namespace alai /** * @brief Loads the selected level. * - * @return Node* The level node which we will later add the monitor to. */ - Node *load_level(); + void load_level(); }; } diff --git a/src/player/Player.cpp b/src/player/Player.cpp index 68df74f..fc3336c 100644 --- a/src/player/Player.cpp +++ b/src/player/Player.cpp @@ -19,7 +19,7 @@ void alai::player::Player::_register_methods() 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_method("_on_level_loaded", &Player::_on_level_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); @@ -56,6 +56,9 @@ void alai::player::Player::_init() void alai::player::Player::_ready() { + auto event = get_node("/root/Event"); + event->connect("level_loaded", this, "_on_level_loaded"); + animated_sprite = get_node("AnimatedSprite"); if (!animated_sprite) { @@ -77,7 +80,7 @@ void alai::player::Player::_ready() } } -void alai::player::Player::_on_monitor_loaded() { +void alai::player::Player::_on_level_loaded() { auto state = get_node("StateMachine")->get_child(0); if (state != nullptr) { diff --git a/src/player/Player.h b/src/player/Player.h index cedcfb5..ee9067d 100644 --- a/src/player/Player.h +++ b/src/player/Player.h @@ -284,7 +284,7 @@ namespace alai * @brief Called when the monitor is loaded to connect the player to it for tracking. * */ - void _on_monitor_loaded(); + void _on_level_loaded(); }; } } -- 2.30.2 From 5d611f790dd74aece432be3ec2be45eec3a89b1a Mon Sep 17 00:00:00 2001 From: Chris Cromer Date: Thu, 1 Sep 2022 11:30:58 -0400 Subject: [PATCH 13/36] make the restart button send the game started event --- src/gui/game_over/GameOverScreen.cpp | 11 ++++++++++- src/gui/game_over/GameOverScreen.h | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/gui/game_over/GameOverScreen.cpp b/src/gui/game_over/GameOverScreen.cpp index f6f604f..9627b2c 100644 --- a/src/gui/game_over/GameOverScreen.cpp +++ b/src/gui/game_over/GameOverScreen.cpp @@ -1,4 +1,5 @@ #include "gui/game_over/GameOverScreen.h" + #include "Event.h" #include @@ -11,6 +12,7 @@ void alai::GameOverScreen::_register_methods() { godot::register_method("_on_restart_button_pressed", &GameOverScreen::_on_restart_button_pressed); godot::register_method("_ready", &GameOverScreen::_ready); + godot::register_method("restart_game", &GameOverScreen::restart_game); godot::register_method("connect_signal", &GameOverScreen::connect_signal); godot::register_method("_on_player_died", &GameOverScreen::_on_player_died); } @@ -45,7 +47,7 @@ void alai::GameOverScreen::_on_restart_button_pressed() { level_node->add_child(level); set_visible(false); - call_deferred("connect_signal"); + call_deferred("restart_game"); } else { @@ -79,6 +81,13 @@ void alai::GameOverScreen::_on_player_died() } } +void alai::GameOverScreen::restart_game() +{ + auto event = get_node("/root/Event"); + event->emit_signal("game_started"); + connect_signal(); +} + void alai::GameOverScreen::connect_signal() { auto event = get_node("/root/Event"); diff --git a/src/gui/game_over/GameOverScreen.h b/src/gui/game_over/GameOverScreen.h index cb79374..d3315c6 100644 --- a/src/gui/game_over/GameOverScreen.h +++ b/src/gui/game_over/GameOverScreen.h @@ -52,6 +52,7 @@ namespace alai void _ready(); void _on_player_died(); void _on_restart_button_pressed(); + void restart_game(); void connect_signal(); }; } -- 2.30.2 From 629c41c235e551670e03061d684bdd65ef2bdda4 Mon Sep 17 00:00:00 2001 From: Chris Cromer Date: Thu, 1 Sep 2022 11:31:23 -0400 Subject: [PATCH 14/36] fix spacing --- src/gui/game_won/GameWonScreen.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/gui/game_won/GameWonScreen.cpp b/src/gui/game_won/GameWonScreen.cpp index d57f950..f51822e 100644 --- a/src/gui/game_won/GameWonScreen.cpp +++ b/src/gui/game_won/GameWonScreen.cpp @@ -1,4 +1,5 @@ #include "gui/game_won/GameWonScreen.h" + #include "Event.h" #include -- 2.30.2 From 083db48f040786af9d554d62073ddef90c1f2d82 Mon Sep 17 00:00:00 2001 From: Chris Cromer Date: Thu, 1 Sep 2022 11:31:47 -0400 Subject: [PATCH 15/36] rename directory to lowercase --- godot/GUI/GameOver.tscn | 48 ----------------------------------- godot/GUI/botonreiniciar.gdns | 8 ------ 2 files changed, 56 deletions(-) delete mode 100644 godot/GUI/GameOver.tscn delete mode 100644 godot/GUI/botonreiniciar.gdns diff --git a/godot/GUI/GameOver.tscn b/godot/GUI/GameOver.tscn deleted file mode 100644 index ba0990d..0000000 --- a/godot/GUI/GameOver.tscn +++ /dev/null @@ -1,48 +0,0 @@ -[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="CanvasLayer"] -script = ExtResource( 3 ) - -[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 ) -color = Color( 0, 0, 0, 1 ) - -[node name="Label" type="Label" parent="Control"] -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="RestartButton" type="Button" parent="Control"] -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" - -[connection signal="pressed" from="Control/RestartButton" to="." method="_on_restart_button_pressed"] diff --git a/godot/GUI/botonreiniciar.gdns b/godot/GUI/botonreiniciar.gdns deleted file mode 100644 index 750e9bf..0000000 --- a/godot/GUI/botonreiniciar.gdns +++ /dev/null @@ -1,8 +0,0 @@ -[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 ) -- 2.30.2 From d560d13627551d871e402a3c818dae40c0a1fefe Mon Sep 17 00:00:00 2001 From: Chris Cromer Date: Thu, 1 Sep 2022 12:26:26 -0400 Subject: [PATCH 16/36] fix pause bug when monitor isn't present --- src/Main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Main.cpp b/src/Main.cpp index 661e0e0..353882b 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -90,8 +90,7 @@ void alai::Main::_on_monitor_loaded() { load_level(); auto event = get_node("/root/Event"); - event->emit_signal("level_loaded"); - get_tree()->set_pause(true); + event->emit_signal("level_loaded"); } void alai::Main::load_monitor() @@ -100,6 +99,7 @@ void alai::Main::load_monitor() event->connect("monitor_loaded", this, "_on_monitor_loaded"); godot::Ref monitor_scene = _resource_loader->load("res://monitor/Monitor.tscn"); add_child(monitor_scene->instance()); + get_tree()->set_pause(true); } void alai::Main::load_level() -- 2.30.2 From fe9cebc620de7f0a496b8592a82f252f70410ada Mon Sep 17 00:00:00 2001 From: Chris Cromer Date: Thu, 1 Sep 2022 12:26:59 -0400 Subject: [PATCH 17/36] fix notifier bug, it only effected the exported game --- src/player/Player.cpp | 15 ++++++++++++--- src/player/Player.h | 5 +++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/player/Player.cpp b/src/player/Player.cpp index fc3336c..9a128f9 100644 --- a/src/player/Player.cpp +++ b/src/player/Player.cpp @@ -51,6 +51,8 @@ void alai::player::Player::_init() coins = 0; + notifier_initialized = false; + velocity = godot::Vector2(); } @@ -189,10 +191,17 @@ void alai::player::Player::_physics_process(float delta) auto notifier = get_node("Camera2D/VisibilityNotifier2D"); if (notifier != nullptr) { - if (!notifier->is_on_screen()) + if (notifier->is_inside_tree() && !notifier->is_on_screen()) { - auto event = get_node("/root/Event"); - event->emit_signal("player_died"); + // The first time the notifier is checked always returns false in the first frame + // So skip the check from the first frame + if (notifier_initialized) { + auto event = get_node("/root/Event"); + event->emit_signal("player_died"); + } + else { + notifier_initialized = true; + } } } else diff --git a/src/player/Player.h b/src/player/Player.h index ee9067d..578840a 100644 --- a/src/player/Player.h +++ b/src/player/Player.h @@ -117,6 +117,11 @@ namespace alai * */ bool double_jump; + /** + * @brief If the notifier for the player being on screen has been initialized or not. + * + */ + bool notifier_initialized; public: /** -- 2.30.2 From e981295e5fc7735da656d8dc831037ecc2509063 Mon Sep 17 00:00:00 2001 From: Chris Cromer Date: Thu, 1 Sep 2022 12:28:00 -0400 Subject: [PATCH 18/36] fix windows build gnu++17 doesn't support inline variables but c++17 does --- SConstruct | 2 ++ 1 file changed, 2 insertions(+) diff --git a/SConstruct b/SConstruct index a17df99..27e219b 100644 --- a/SConstruct +++ b/SConstruct @@ -82,6 +82,8 @@ elif env['platform'] == "windows": # that way you can run scons in a vs 2017 prompt and it will find all the required tools env.Append(ENV=os.environ) + env.Append(CXXFLAGS=['-std=c++17']) + env.Append(LINKFLAGS=[ '--static', '-Wl,--no-undefined', -- 2.30.2 From 7236428157b0556bf12c4c0d80c846c5b9fb6c54 Mon Sep 17 00:00:00 2001 From: Martin Araneda Date: Thu, 1 Sep 2022 15:55:02 -0400 Subject: [PATCH 19/36] coin and bgm added, game over music still not done --- godot/GUI/GameOver.tscn | 8 +++++++- godot/assets/music/Magic Fx 7.ogg | 3 +++ godot/assets/music/Magic Fx 7.ogg.import | 15 +++++++++++++++ godot/characters/player/Player.tscn | 2 +- godot/collectables/coin/Coin.tscn | 7 ++++++- godot/levels/Prototype.tscn | 11 ++++++++++- src/coin/CoinCollected.cpp | 4 +++- src/gui/game_over/GameOverScreen.cpp | 22 ++++++++++++++++++++++ src/gui/game_over/GameOverScreen.h | 2 ++ 9 files changed, 69 insertions(+), 5 deletions(-) create mode 100644 godot/assets/music/Magic Fx 7.ogg create mode 100644 godot/assets/music/Magic Fx 7.ogg.import diff --git a/godot/GUI/GameOver.tscn b/godot/GUI/GameOver.tscn index ba0990d..fde9238 100644 --- a/godot/GUI/GameOver.tscn +++ b/godot/GUI/GameOver.tscn @@ -1,8 +1,9 @@ -[gd_scene load_steps=7 format=2] +[gd_scene load_steps=8 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] +[ext_resource path="res://assets/sounds/died.wav" type="AudioStream" id=4] [sub_resource type="DynamicFont" id=1] size = 50 @@ -45,4 +46,9 @@ custom_fonts/font = SubResource( 2 ) custom_styles/hover = SubResource( 3 ) text = "REINICIAR" +[node name="GameOverMusic" type="AudioStreamPlayer" parent="."] +stream = ExtResource( 4 ) +volume_db = -23.524 + +[connection signal="visibility_changed" from="." to="." method="_play_music"] [connection signal="pressed" from="Control/RestartButton" to="." method="_on_restart_button_pressed"] diff --git a/godot/assets/music/Magic Fx 7.ogg b/godot/assets/music/Magic Fx 7.ogg new file mode 100644 index 0000000..a9c0020 --- /dev/null +++ b/godot/assets/music/Magic Fx 7.ogg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:212b33aef7ed3befca6912a1fcd86e7166a9bbbe55a3422a7d10bbf1afbf5020 +size 2189889 diff --git a/godot/assets/music/Magic Fx 7.ogg.import b/godot/assets/music/Magic Fx 7.ogg.import new file mode 100644 index 0000000..d27d30e --- /dev/null +++ b/godot/assets/music/Magic Fx 7.ogg.import @@ -0,0 +1,15 @@ +[remap] + +importer="ogg_vorbis" +type="AudioStreamOGGVorbis" +path="res://.import/Magic Fx 7.ogg-8a3ae422bac9ed88f48079377b8e81ff.oggstr" + +[deps] + +source_file="res://assets/music/Magic Fx 7.ogg" +dest_files=[ "res://.import/Magic Fx 7.ogg-8a3ae422bac9ed88f48079377b8e81ff.oggstr" ] + +[params] + +loop=true +loop_offset=0 diff --git a/godot/characters/player/Player.tscn b/godot/characters/player/Player.tscn index bbd2fc2..87f7b58 100644 --- a/godot/characters/player/Player.tscn +++ b/godot/characters/player/Player.tscn @@ -52,4 +52,4 @@ collision_mask = 24 [node name="Jump" type="AudioStreamPlayer" parent="Sounds"] stream = ExtResource( 8 ) -volume_db = -45.0 +volume_db = -23.953 diff --git a/godot/collectables/coin/Coin.tscn b/godot/collectables/coin/Coin.tscn index 6d52bb0..1c40bc1 100644 --- a/godot/collectables/coin/Coin.tscn +++ b/godot/collectables/coin/Coin.tscn @@ -1,9 +1,10 @@ -[gd_scene load_steps=10 format=2] +[gd_scene load_steps=11 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] +[ext_resource path="res://assets/sounds/coin.wav" type="AudioStream" id=5] [sub_resource type="CircleShape2D" id=1] radius = 6.0 @@ -67,5 +68,9 @@ script = ExtResource( 4 ) [node name="AnimationPlayer" type="AnimationPlayer" parent="."] anims/jump = SubResource( 5 ) +[node name="CoinCollectedSound" type="AudioStreamPlayer" parent="."] +stream = ExtResource( 5 ) +volume_db = -6.19 + [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/levels/Prototype.tscn b/godot/levels/Prototype.tscn index b71e0c7..39fe9ce 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=9 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,6 +6,7 @@ [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://hud/CoinHUD.tscn" type="PackedScene" id=6] +[ext_resource path="res://assets/music/Magic Fx 7.ogg" type="AudioStream" id=7] [ext_resource path="res://goal/Goal.tscn" type="PackedScene" id=8] [node name="Prototype" type="Node2D"] @@ -51,9 +52,17 @@ script = ExtResource( 1 ) [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" parent="." instance=ExtResource( 8 )] +[node name="BGM" type="AudioStreamPlayer" parent="."] +stream = ExtResource( 7 ) +volume_db = -29.714 +autoplay = true + [editable path="Coins/coin"] diff --git a/src/coin/CoinCollected.cpp b/src/coin/CoinCollected.cpp index 5c30b82..110be15 100644 --- a/src/coin/CoinCollected.cpp +++ b/src/coin/CoinCollected.cpp @@ -2,6 +2,7 @@ #include "Event.h" +#include #include void alai::CoinCollected::_register_methods() @@ -32,7 +33,8 @@ void alai::CoinCollected::_state_enter() auto animation_player = Object::cast_to(node); animation_player->play("jump"); } - + auto coin_collected_sound = get_parent()->get_node("CoinCollectedSound"); + coin_collected_sound->play(); } void alai::CoinCollected::_state_exit() diff --git a/src/gui/game_over/GameOverScreen.cpp b/src/gui/game_over/GameOverScreen.cpp index fc35153..299ccae 100644 --- a/src/gui/game_over/GameOverScreen.cpp +++ b/src/gui/game_over/GameOverScreen.cpp @@ -7,6 +7,8 @@ #include #include #include +#include +#include void alai::GameOverScreen::_register_methods() { @@ -14,6 +16,7 @@ void alai::GameOverScreen::_register_methods() register_method("_ready", &GameOverScreen::_ready); register_method("connect_signal", &GameOverScreen::connect_signal); register_method("_on_player_died", &GameOverScreen::_on_player_died); + register_method("_play music", &GameOverScreen::_play_music); } alai::GameOverScreen::GameOverScreen() @@ -29,9 +32,11 @@ void alai::GameOverScreen::_init() _resource_loader = godot::ResourceLoader::get_singleton(); } + void alai::GameOverScreen::_ready() { connect_signal(); + } void alai::GameOverScreen::_on_restart_button_pressed() @@ -85,3 +90,20 @@ void alai::GameOverScreen::connect_signal() auto event = get_node("/root/Event"); event->connect("player_died", this, "_on_player_died"); } + +void alai::GameOverScreen::_play_music() +{ + if (this->is_on_screen() == true) + { + auto game_over_sound = get_node("GameOverMusic"); + game_over_sound->play(); + + } + else + { + auto game_over_sound = get_node("GameOverMusic"); + game_over_sound->stop(); + } + + +} diff --git a/src/gui/game_over/GameOverScreen.h b/src/gui/game_over/GameOverScreen.h index 892a316..6e4b657 100644 --- a/src/gui/game_over/GameOverScreen.h +++ b/src/gui/game_over/GameOverScreen.h @@ -5,6 +5,7 @@ #include #include + namespace alai { /** @@ -53,6 +54,7 @@ namespace alai void _on_player_died(); void _on_restart_button_pressed(); void connect_signal(); + void _play_music(); }; } -- 2.30.2 From 2e07679b52611a0bbfa4edf8f6aec36ce26d4e84 Mon Sep 17 00:00:00 2001 From: Martin Araneda Date: Thu, 1 Sep 2022 16:18:38 -0400 Subject: [PATCH 20/36] minor fix --- src/gui/game_over/GameOverScreen.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/game_over/GameOverScreen.cpp b/src/gui/game_over/GameOverScreen.cpp index 2c59ea7..622a032 100644 --- a/src/gui/game_over/GameOverScreen.cpp +++ b/src/gui/game_over/GameOverScreen.cpp @@ -16,7 +16,7 @@ void alai::GameOverScreen::_register_methods() godot::register_method("restart_game", &GameOverScreen::restart_game); godot::register_method("connect_signal", &GameOverScreen::connect_signal); godot::register_method("_on_player_died", &GameOverScreen::_on_player_died); - godot::register_method("_play music", &GameOverScreen::_play_music); + godot::register_method("_play_music", &GameOverScreen::_play_music); } alai::GameOverScreen::GameOverScreen() -- 2.30.2 From 1f63f5e00ad5de26db34da000263c0063e5d2b26 Mon Sep 17 00:00:00 2001 From: Martin Araneda Date: Thu, 1 Sep 2022 16:37:50 -0400 Subject: [PATCH 21/36] Player touched signal added --- src/Event.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Event.cpp b/src/Event.cpp index 8795d1e..9605468 100644 --- a/src/Event.cpp +++ b/src/Event.cpp @@ -11,6 +11,8 @@ void alai::Event::_register_methods() godot::register_signal("coin_collected", "amount", GODOT_VARIANT_TYPE_INT); godot::register_signal("player_died"); godot::register_signal("player_won"); + godot::register_signal("player_touched", "damage", GODOT_VARIANT_TYPE_INT); + } alai::Event::Event() -- 2.30.2 From 3ca5f4e7b2e7e01d4c4b57dac5bd146644cd2e45 Mon Sep 17 00:00:00 2001 From: Chris Cromer Date: Thu, 1 Sep 2022 18:34:37 -0400 Subject: [PATCH 22/36] improve coin counter HUD --- godot/hud/CoinHUD.tscn | 39 ++++++++++--------- .../coin/{Counter.gdns => CoinCounter.gdns} | 0 godot/levels/Prototype.tscn | 2 - src/coin/CoinCounter.cpp | 23 +++++++---- 4 files changed, 37 insertions(+), 27 deletions(-) rename godot/hud/coin/{Counter.gdns => CoinCounter.gdns} (100%) diff --git a/godot/hud/CoinHUD.tscn b/godot/hud/CoinHUD.tscn index 512a8cd..c14b61c 100644 --- a/godot/hud/CoinHUD.tscn +++ b/godot/hud/CoinHUD.tscn @@ -1,7 +1,7 @@ [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/coin/CoinCounter.gdns" type="Script" id=2] [ext_resource path="res://hud/CoinHUD.gd" type="Script" id=3] [sub_resource type="StyleBoxFlat" id=1] @@ -28,31 +28,34 @@ 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 +anchor_left = 0.5 +anchor_right = 0.5 +margin_left = -44.5 +margin_top = 5.0 +margin_right = 44.5 +margin_bottom = 25.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 +[node name="X" type="Label" parent="Panel"] +margin_left = 40.0 +margin_top = 4.0 +margin_right = 53.0 +margin_bottom = 24.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 +[node name="Coins" type="Label" parent="Panel"] +anchor_left = 0.5 +anchor_right = 0.5 +margin_left = 13.5 +margin_top = 4.0 +margin_right = 36.0 +margin_bottom = 18.0 text = "##" script = ExtResource( 2 ) -[node name="AnimatedSprite" type="AnimatedSprite" parent="."] -position = Vector2( 162, 18 ) +[node name="AnimatedSprite" type="AnimatedSprite" parent="Panel"] +position = Vector2( 12, 1 ) frames = SubResource( 4 ) animation = "spin" -frame = 1 playing = true centered = false diff --git a/godot/hud/coin/Counter.gdns b/godot/hud/coin/CoinCounter.gdns similarity index 100% rename from godot/hud/coin/Counter.gdns rename to godot/hud/coin/CoinCounter.gdns diff --git a/godot/levels/Prototype.tscn b/godot/levels/Prototype.tscn index b71e0c7..2d3dce5 100644 --- a/godot/levels/Prototype.tscn +++ b/godot/levels/Prototype.tscn @@ -55,5 +55,3 @@ position = Vector2( 72, 450 ) position = Vector2( 234, 450 ) [node name="Goal" parent="." instance=ExtResource( 8 )] - -[editable path="Coins/coin"] diff --git a/src/coin/CoinCounter.cpp b/src/coin/CoinCounter.cpp index c0f5cbe..da39b39 100644 --- a/src/coin/CoinCounter.cpp +++ b/src/coin/CoinCounter.cpp @@ -23,15 +23,24 @@ void alai::CoinCounter::_init() coins = 0; } -void alai::CoinCounter::_on_coin_collected(int amount) -{ - coins = coins + amount; - set_text(godot::String::num(coins)); -} - void alai::CoinCounter::_ready() { - set_text("0"); + set_text("00"); auto event = get_node("/root/Event"); event->connect("coin_collected", this, "_on_coin_collected"); } + + +void alai::CoinCounter::_on_coin_collected(int amount) +{ + coins = coins + amount; + godot::String coin_string = godot::String(); + if (coins <= 9) + { + coin_string = "0" + godot::String::num(coins); + } + else{ + coin_string = godot::String::num(coins); + } + set_text(coin_string); +} -- 2.30.2 From 011a1b8007a266cac6b0eb2e2dfc5c5337bdd925 Mon Sep 17 00:00:00 2001 From: Martin Araneda Date: Thu, 1 Sep 2022 21:59:21 -0400 Subject: [PATCH 23/36] make the enemies use the event bus --- godot/characters/enemies/WalkingEnemy.gd | 5 +---- godot/characters/enemies/blightwing/Blightwing.gd | 5 +---- godot/characters/enemies/blockface/Blockface.gd | 5 +---- 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/godot/characters/enemies/WalkingEnemy.gd b/godot/characters/enemies/WalkingEnemy.gd index 94a01b5..15707dc 100644 --- a/godot/characters/enemies/WalkingEnemy.gd +++ b/godot/characters/enemies/WalkingEnemy.gd @@ -1,9 +1,6 @@ extends KinematicBody2D -signal player_touched - - var velocity = Vector2() export var direction = -1 export var detect_edges = true @@ -32,7 +29,7 @@ func _physics_process(_delta: float) -> void: for i in get_slide_count(): var collision = get_slide_collision(i) if collision.collider.name == "Player": - emit_signal("player_touched") + Event.emit_signal("player_touched", 3) Event.emit_signal("object_updated", self.get_name(), "Walking", global_position, velocity) diff --git a/godot/characters/enemies/blightwing/Blightwing.gd b/godot/characters/enemies/blightwing/Blightwing.gd index 1446628..a41b7a1 100644 --- a/godot/characters/enemies/blightwing/Blightwing.gd +++ b/godot/characters/enemies/blightwing/Blightwing.gd @@ -1,9 +1,6 @@ extends KinematicBody2D -signal player_touched - - export var direction = -1 export var speed = 50 export var follow_path = false @@ -82,7 +79,7 @@ func get_velocity_towards_target(delta: float) -> Vector2: func wall_checker_collided(wall_checker: RayCast2D) -> void: if wall_checker.get_collider().name == "Player": - emit_signal("player_touched") + Event.emit_signal("player_touched", 3) direction *= -1 $AnimatedSprite.flip_h = not $AnimatedSprite.flip_h diff --git a/godot/characters/enemies/blockface/Blockface.gd b/godot/characters/enemies/blockface/Blockface.gd index 3f52a5a..fab7b04 100644 --- a/godot/characters/enemies/blockface/Blockface.gd +++ b/godot/characters/enemies/blockface/Blockface.gd @@ -1,9 +1,6 @@ extends KinematicBody2D -signal player_touched - - onready var start_position = position var velocity = Vector2() export var speed = 50.0 @@ -25,7 +22,7 @@ func _physics_process(delta: float) -> void: return_to_start = true $AnimatedSprite.play("normal") if collision.collider.name == "Player": - emit_signal("player_touched") + Event.emit_signal("player_touched", 3) Event.emit_signal("object_updated", self.get_name(), "Falling", global_position, velocity) if position.y <= start_position.y: -- 2.30.2 From 6c0b656d798433635fee709c5a5bcf47a0994eda Mon Sep 17 00:00:00 2001 From: Martin Araneda Date: Thu, 1 Sep 2022 21:59:58 -0400 Subject: [PATCH 24/36] change music file name --- godot/assets/music/Magic Fx 7.ogg.import | 15 --------------- .../music/{Magic Fx 7.ogg => prototype_r.ogg} | 0 godot/assets/music/prototype_r.ogg.import | 15 +++++++++++++++ godot/levels/Prototype.tscn | 2 +- 4 files changed, 16 insertions(+), 16 deletions(-) delete mode 100644 godot/assets/music/Magic Fx 7.ogg.import rename godot/assets/music/{Magic Fx 7.ogg => prototype_r.ogg} (100%) create mode 100644 godot/assets/music/prototype_r.ogg.import diff --git a/godot/assets/music/Magic Fx 7.ogg.import b/godot/assets/music/Magic Fx 7.ogg.import deleted file mode 100644 index d27d30e..0000000 --- a/godot/assets/music/Magic Fx 7.ogg.import +++ /dev/null @@ -1,15 +0,0 @@ -[remap] - -importer="ogg_vorbis" -type="AudioStreamOGGVorbis" -path="res://.import/Magic Fx 7.ogg-8a3ae422bac9ed88f48079377b8e81ff.oggstr" - -[deps] - -source_file="res://assets/music/Magic Fx 7.ogg" -dest_files=[ "res://.import/Magic Fx 7.ogg-8a3ae422bac9ed88f48079377b8e81ff.oggstr" ] - -[params] - -loop=true -loop_offset=0 diff --git a/godot/assets/music/Magic Fx 7.ogg b/godot/assets/music/prototype_r.ogg similarity index 100% rename from godot/assets/music/Magic Fx 7.ogg rename to godot/assets/music/prototype_r.ogg diff --git a/godot/assets/music/prototype_r.ogg.import b/godot/assets/music/prototype_r.ogg.import new file mode 100644 index 0000000..4e378c2 --- /dev/null +++ b/godot/assets/music/prototype_r.ogg.import @@ -0,0 +1,15 @@ +[remap] + +importer="ogg_vorbis" +type="AudioStreamOGGVorbis" +path="res://.import/prototype_r.ogg-fe1f80b61f2acb1c2ae620457cf8aac9.oggstr" + +[deps] + +source_file="res://assets/music/prototype_r.ogg" +dest_files=[ "res://.import/prototype_r.ogg-fe1f80b61f2acb1c2ae620457cf8aac9.oggstr" ] + +[params] + +loop=true +loop_offset=0 diff --git a/godot/levels/Prototype.tscn b/godot/levels/Prototype.tscn index fed11b3..8880230 100644 --- a/godot/levels/Prototype.tscn +++ b/godot/levels/Prototype.tscn @@ -6,7 +6,7 @@ [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://hud/CoinHUD.tscn" type="PackedScene" id=6] -[ext_resource path="res://assets/music/Magic Fx 7.ogg" type="AudioStream" id=7] +[ext_resource path="res://assets/music/prototype_r.ogg" type="AudioStream" id=7] [ext_resource path="res://goal/Goal.tscn" type="PackedScene" id=8] [node name="Prototype" type="Node2D"] -- 2.30.2 From ba46d6c65bc48446a40648a640f4bf78043ebc78 Mon Sep 17 00:00:00 2001 From: Martin Araneda Date: Thu, 1 Sep 2022 22:00:59 -0400 Subject: [PATCH 25/36] Make player using the event bus for enemies touching him --- src/player/Player.cpp | 7 ++++--- src/player/Player.h | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/player/Player.cpp b/src/player/Player.cpp index 9a128f9..43dce2e 100644 --- a/src/player/Player.cpp +++ b/src/player/Player.cpp @@ -60,6 +60,7 @@ void alai::player::Player::_ready() { auto event = get_node("/root/Event"); event->connect("level_loaded", this, "_on_level_loaded"); + event->connect("player_touched", this, "_on_player_touched"); animated_sprite = get_node("AnimatedSprite"); if (!animated_sprite) @@ -156,11 +157,11 @@ void alai::player::Player::_physics_process(float delta) } else if (collider->is_in_group("enemy") && (collider->is_in_group("rideable") && godot::Vector2::DOWN.dot(collision->get_normal()) > 0)) { - _on_player_touched(); + _on_player_touched(3); } else if (collider->is_in_group("enemy") && !collider->is_in_group("rideable")) { - _on_player_touched(); + _on_player_touched(3); } } @@ -301,7 +302,7 @@ godot::Vector2 alai::player::Player::get_velocity() return this->velocity; } -void alai::player::Player::_on_player_touched() +void alai::player::Player::_on_player_touched(uint8_t damage) { auto event = get_node("/root/Event"); event->emit_signal("player_died"); diff --git a/src/player/Player.h b/src/player/Player.h index 578840a..9510e09 100644 --- a/src/player/Player.h +++ b/src/player/Player.h @@ -283,7 +283,7 @@ namespace alai * @brief This function is called when an enemy touches the player. * */ - void _on_player_touched(); + void _on_player_touched(uint8_t damage); /** * @brief Called when the monitor is loaded to connect the player to it for tracking. -- 2.30.2 From 8adf91247e3d012975ca5f4907782b0610355413 Mon Sep 17 00:00:00 2001 From: Martin Araneda Date: Thu, 1 Sep 2022 22:01:16 -0400 Subject: [PATCH 26/36] Adjust jump volume --- godot/characters/player/Player.tscn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/godot/characters/player/Player.tscn b/godot/characters/player/Player.tscn index 87f7b58..5ac8d15 100644 --- a/godot/characters/player/Player.tscn +++ b/godot/characters/player/Player.tscn @@ -52,4 +52,4 @@ collision_mask = 24 [node name="Jump" type="AudioStreamPlayer" parent="Sounds"] stream = ExtResource( 8 ) -volume_db = -23.953 +volume_db = -20.0 -- 2.30.2 From bc572df9f957dfec8ded19a1e4cbd41baf3ff2a6 Mon Sep 17 00:00:00 2001 From: Martin Araneda Date: Thu, 1 Sep 2022 22:01:45 -0400 Subject: [PATCH 27/36] Added coins and enemies to the PrototypeR map --- godot/levels/PrototypeR.tscn | 63 ++++++++++++++++++++++++++++++++++-- 1 file changed, 61 insertions(+), 2 deletions(-) diff --git a/godot/levels/PrototypeR.tscn b/godot/levels/PrototypeR.tscn index 299779a..f93944e 100644 --- a/godot/levels/PrototypeR.tscn +++ b/godot/levels/PrototypeR.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=7 format=2] +[gd_scene load_steps=14 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,8 +6,15 @@ [ext_resource path="res://assets/backgrounds/hills.png" type="Texture" id=4] [ext_resource path="res://hud/CoinHUD.tscn" type="PackedScene" id=5] [ext_resource path="res://collectables/coin/Coin.tscn" type="PackedScene" id=6] +[ext_resource path="res://assets/music/prototype_r.ogg" type="AudioStream" id=7] +[ext_resource path="res://goal/Goal.tscn" type="PackedScene" id=8] +[ext_resource path="res://characters/enemies/blockface/Blockface.tscn" type="PackedScene" id=9] +[ext_resource path="res://characters/enemies/shelly/Shelly.tscn" type="PackedScene" id=10] +[ext_resource path="res://characters/enemies/dreadtooth/Dreadtooth.tscn" type="PackedScene" id=11] +[ext_resource path="res://characters/enemies/spikeball/Spikeball.tscn" type="PackedScene" id=12] +[ext_resource path="res://characters/enemies/super_shelly/SuperShelly.tscn" type="PackedScene" id=13] -[node name="Prototype" type="Node2D"] +[node name="PrototypeR" type="Node2D"] [node name="Player" parent="." instance=ExtResource( 2 )] collision_layer = 5 @@ -59,14 +66,66 @@ position = Vector2( 1278, 342 ) [node name="Coin4" parent="Coins" instance=ExtResource( 6 )] position = Vector2( 1278, 180 ) +[node name="Coin9" parent="Coins" instance=ExtResource( 6 )] +position = Vector2( 1278, 108 ) + +[node name="Coin10" parent="Coins" instance=ExtResource( 6 )] +position = Vector2( 1800, 378 ) + +[node name="Coin11" parent="Coins" instance=ExtResource( 6 )] +position = Vector2( 1872, 378 ) + +[node name="Coin12" parent="Coins" instance=ExtResource( 6 )] +position = Vector2( 1836, 315 ) + [node name="Coin5" parent="Coins" instance=ExtResource( 6 )] position = Vector2( 522, 270 ) [node name="Coin6" parent="Coins" instance=ExtResource( 6 )] position = Vector2( 990, 324 ) +[node name="Coin13" parent="Coins" instance=ExtResource( 6 )] +position = Vector2( 1134, 414 ) + [node name="Coin7" parent="Coins" instance=ExtResource( 6 )] position = Vector2( 468, 306 ) [node name="Coin8" parent="Coins" instance=ExtResource( 6 )] position = Vector2( 576, 306 ) + +[node name="BGM" type="AudioStreamPlayer" parent="."] +stream = ExtResource( 7 ) +volume_db = -25.0 +autoplay = true + +[node name="Goal" parent="." instance=ExtResource( 8 )] +position = Vector2( 2052, 396 ) + +[node name="Enemies" type="Node" parent="."] + +[node name="Blockface" parent="Enemies" instance=ExtResource( 9 )] +position = Vector2( 531, 228 ) + +[node name="Blockface2" parent="Enemies" instance=ExtResource( 9 )] +position = Vector2( 1287, 72 ) + +[node name="Shelly" parent="Enemies" instance=ExtResource( 10 )] +position = Vector2( 918, 258 ) + +[node name="Shelly2" parent="Enemies" instance=ExtResource( 10 )] +position = Vector2( 612, 360 ) + +[node name="Dreadtooth" parent="Enemies" instance=ExtResource( 11 )] +position = Vector2( 1337, 217 ) + +[node name="Spikeball" parent="Enemies" instance=ExtResource( 12 )] +position = Vector2( 1458, 336 ) + +[node name="Spikeball2" parent="Enemies" instance=ExtResource( 12 )] +position = Vector2( 1428, 348 ) + +[node name="Spikeball3" parent="Enemies" instance=ExtResource( 12 )] +position = Vector2( 1845, 366 ) + +[node name="SuperShelly" parent="Enemies" instance=ExtResource( 13 )] +position = Vector2( 1962, 432 ) -- 2.30.2 From 9388e6f6f54f01a7f4b498edb4d602c5f9d44f16 Mon Sep 17 00:00:00 2001 From: Martin Araneda Date: Thu, 1 Sep 2022 22:21:13 -0400 Subject: [PATCH 28/36] Added some enemies --- godot/levels/PrototypeR.tscn | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/godot/levels/PrototypeR.tscn b/godot/levels/PrototypeR.tscn index f93944e..ada3c23 100644 --- a/godot/levels/PrototypeR.tscn +++ b/godot/levels/PrototypeR.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=14 format=2] +[gd_scene load_steps=15 format=2] [ext_resource path="res://CameraLimit.gdns" type="Script" id=1] [ext_resource path="res://characters/player/Player.tscn" type="PackedScene" id=2] @@ -13,6 +13,7 @@ [ext_resource path="res://characters/enemies/dreadtooth/Dreadtooth.tscn" type="PackedScene" id=11] [ext_resource path="res://characters/enemies/spikeball/Spikeball.tscn" type="PackedScene" id=12] [ext_resource path="res://characters/enemies/super_shelly/SuperShelly.tscn" type="PackedScene" id=13] +[ext_resource path="res://characters/enemies/blightwing/Blightwing.tscn" type="PackedScene" id=14] [node name="PrototypeR" type="Node2D"] @@ -129,3 +130,24 @@ position = Vector2( 1845, 366 ) [node name="SuperShelly" parent="Enemies" instance=ExtResource( 13 )] position = Vector2( 1962, 432 ) + +[node name="Blightwing" parent="Enemies" instance=ExtResource( 14 )] +position = Vector2( 1206, 450 ) +follow_path = true + +[node name="Path" type="Node2D" parent="Enemies/Blightwing"] + +[node name="Node2D" type="Node2D" parent="Enemies/Blightwing/Path"] +position = Vector2( -126, 0 ) + +[node name="Blightwing2" parent="Enemies" instance=ExtResource( 14 )] +position = Vector2( 1846, 324 ) +follow_path = true + +[node name="Path" type="Node2D" parent="Enemies/Blightwing2"] + +[node name="Node2D" type="Node2D" parent="Enemies/Blightwing2/Path"] +position = Vector2( -36, 63 ) + +[node name="Node2D2" type="Node2D" parent="Enemies/Blightwing2/Path"] +position = Vector2( 36, 63 ) -- 2.30.2 From e6b170e4d886ad30d3ee8cf2545dc08a07218974 Mon Sep 17 00:00:00 2001 From: Martin Araneda Date: Thu, 1 Sep 2022 22:32:52 -0400 Subject: [PATCH 29/36] Remove unused signals --- godot/levels/PrototypeEnemies.tscn | 7 ------- 1 file changed, 7 deletions(-) diff --git a/godot/levels/PrototypeEnemies.tscn b/godot/levels/PrototypeEnemies.tscn index d53033f..f521a70 100644 --- a/godot/levels/PrototypeEnemies.tscn +++ b/godot/levels/PrototypeEnemies.tscn @@ -89,10 +89,3 @@ position = Vector2( 247, 439 ) [node name="SuperShelly" parent="Enemies" instance=ExtResource( 7 )] position = Vector2( 62, 546 ) - -[connection signal="player_touched" from="Enemies/Blightwing" to="Player" method="_on_player_touched"] -[connection signal="player_touched" from="Enemies/Blockface" to="Player" method="_on_player_touched"] -[connection signal="player_touched" from="Enemies/Dreadtooth" to="Player" method="_on_player_touched"] -[connection signal="player_touched" from="Enemies/Dreadtooth2" to="Player" method="_on_player_touched"] -[connection signal="player_touched" from="Enemies/Shelly" to="Player" method="_on_player_touched"] -[connection signal="player_touched" from="Enemies/SuperShelly" to="Player" method="_on_player_touched"] -- 2.30.2 From fa4cff9c57b97bb45647cd19db2f3f64285a22b2 Mon Sep 17 00:00:00 2001 From: Martin Araneda Date: Thu, 1 Sep 2022 22:33:43 -0400 Subject: [PATCH 30/36] Added some visual details to the PrototypeR map --- godot/levels/PrototypeR.tmx | 4 ++-- godot/levels/PrototypeR.tscn | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/godot/levels/PrototypeR.tmx b/godot/levels/PrototypeR.tmx index 57d9e74..6280b25 100644 --- a/godot/levels/PrototypeR.tmx +++ b/godot/levels/PrototypeR.tmx @@ -3,12 +3,12 @@ - KLUv/WAAO9UGAOQDABIAAAATFAAnEiYoEjo8YgAAADs6dQA6iwAAAIwAOnUAihIoADd/YwAAAGQAAAB4AAAAdiY3ADqLYwAAgAA8oBCVNdsBwAKTQCJcY8XxUYoarT8gQjyeu5O6nkqpOlT1gMJhyWO43xyk5jp+D3SGOxcoT52U4vScQx63fcb98i+k3jK5QUu8pNUR8O+i4l7VPW51R5d4k1T3FuabG4vErcrOI+U6fRflI6vfRsa41pUIv1HPe0OudqI1qDNHH2bcTSH3r27pd6Tac6lM+3bwXaj+q2cxvogB + KLUv/WAAO+UJAKKFEBmgKa0BQ/z5f96XBipzAacygijAnyB3inwKFSvNi9glMAjxxA9XlsgtTIpZPMt4Y5dngxsSKwGqJ/AAXtOPtCPdGGCgMLGl7aACk0ACwdEBxfEUiOZVzal6o7kqyNAeN3fIyH7S5qp2c6UrxlMzmjiIKgDhsHQId31OUO2QhjGOn1jH74PYuHOc8tYy/qlHqaNzDnLc/nFdEc9bdesdom5Z3PEgeGCq2jtS46axwFMfv3dxfKgNZ5HU/e4tjqcWSd0k/yrTDSmpq+CqHl/d0aVt0urewnTzsUiyVcsyprra58l1+g7NC/UOqt5CzniZswtOyWRvAHxDn0csowOGV42bUrLGiSrDqDOLOIxxbSotgVq8/NT2n/z80u/Jz1KVb98VKDofNZOm5Ndvltmp+0cuUIUgKiT5TQw= - KLUv/WAAOz0FAIQCADEAAAAyMwACAAAAAwQAAhYAAAAXGAB6AAAAe3wAF4ZfAHuIAIZeiCygMLF1UIIUiARiZAelj/9XjXZV/ipp0q1TfoI4FDJcav6xkgcm3cqld/XLYVzNgPGrRkX6pwiG831dQsKVhvGrM0E5nOTUdZpyl96SqGcYDzh1mVBuKT0+fmorpXmjgBlElduJp59uitTebrC/onYW//xER7myT2JL+hkD + KLUv/WAAO50FAMQCADEAAAAyMwACAAAAAwQAGwACFgAAABcYABt6AAAAe3wAGxeGXwB7iACGXogxoCCzdWCCFIgEYmQHpY//V412Vf4gGemWL/1AEQoZHqr8I5IHRLoFS671y2WYzYBxqqNa2qcCCqf7uoRE1YZxqzJNOVxJqesG5R7dJVCGcRyg1GVAvQU6Pu6UVhrTRgcqSPFJzkzZ78bTSSezM7YmircT9lep4Hgo+u2SHKWql8yW9EEH diff --git a/godot/levels/PrototypeR.tscn b/godot/levels/PrototypeR.tscn index ada3c23..e6ac0ce 100644 --- a/godot/levels/PrototypeR.tscn +++ b/godot/levels/PrototypeR.tscn @@ -18,6 +18,7 @@ [node name="PrototypeR" type="Node2D"] [node name="Player" parent="." instance=ExtResource( 2 )] +position = Vector2( 36, 444 ) collision_layer = 5 [node name="Camera2D" type="Camera2D" parent="Player"] -- 2.30.2 From 2c5d3d9afec8f0300fdd39941f5052f462a41542 Mon Sep 17 00:00:00 2001 From: Martin Araneda Date: Thu, 1 Sep 2022 23:20:53 -0400 Subject: [PATCH 31/36] validation over 100 coins --- src/coin/CoinCounter.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/coin/CoinCounter.cpp b/src/coin/CoinCounter.cpp index da39b39..e29280b 100644 --- a/src/coin/CoinCounter.cpp +++ b/src/coin/CoinCounter.cpp @@ -30,10 +30,14 @@ void alai::CoinCounter::_ready() event->connect("coin_collected", this, "_on_coin_collected"); } - void alai::CoinCounter::_on_coin_collected(int amount) { coins = coins + amount; + if (coins >= 100) + { + auto extra = coins - 100; + coins = extra; + } godot::String coin_string = godot::String(); if (coins <= 9) { -- 2.30.2 From a8e364415c4f681fbd29b36f35e710c23028c75d Mon Sep 17 00:00:00 2001 From: Martin Araneda Date: Thu, 1 Sep 2022 23:21:30 -0400 Subject: [PATCH 32/36] changed coin type format to avoid negatives --- src/coin/CoinCounter.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coin/CoinCounter.h b/src/coin/CoinCounter.h index 8702887..e04f5fa 100644 --- a/src/coin/CoinCounter.h +++ b/src/coin/CoinCounter.h @@ -15,7 +15,7 @@ namespace alai GODOT_CLASS(CoinCounter, godot::Label) private: - int coins; + uint8_t coins; public: /** -- 2.30.2 From e62acd3ab1932a769092b2796fe06d8500afd639 Mon Sep 17 00:00:00 2001 From: Martin Araneda Date: Thu, 1 Sep 2022 23:22:10 -0400 Subject: [PATCH 33/36] final changes to music --- godot/gui/GameOver.tscn | 4 ++-- src/gui/game_over/GameOverScreen.cpp | 13 +++++++++++-- src/gui/game_over/GameOverScreen.h | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/godot/gui/GameOver.tscn b/godot/gui/GameOver.tscn index 56c19a8..08d8f03 100644 --- a/godot/gui/GameOver.tscn +++ b/godot/gui/GameOver.tscn @@ -48,7 +48,7 @@ text = "REINICIAR" [node name="GameOverMusic" type="AudioStreamPlayer" parent="."] stream = ExtResource( 4 ) -volume_db = -23.524 +volume_db = -25.0 -[connection signal="visibility_changed" from="." to="." method="_play_music"] +[connection signal="visibility_changed" from="." to="." method="_on_visibility_changed"] [connection signal="pressed" from="Control/RestartButton" to="." method="_on_restart_button_pressed"] diff --git a/src/gui/game_over/GameOverScreen.cpp b/src/gui/game_over/GameOverScreen.cpp index 622a032..9dcdf47 100644 --- a/src/gui/game_over/GameOverScreen.cpp +++ b/src/gui/game_over/GameOverScreen.cpp @@ -16,7 +16,7 @@ void alai::GameOverScreen::_register_methods() godot::register_method("restart_game", &GameOverScreen::restart_game); godot::register_method("connect_signal", &GameOverScreen::connect_signal); godot::register_method("_on_player_died", &GameOverScreen::_on_player_died); - godot::register_method("_play_music", &GameOverScreen::_play_music); + godot::register_method("_on_visibility_changed", &GameOverScreen::_on_visibility_changed); } alai::GameOverScreen::GameOverScreen() @@ -96,6 +96,15 @@ void alai::GameOverScreen::connect_signal() event->connect("player_died", this, "_on_player_died"); } -void alai::GameOverScreen::_play_music() +void alai::GameOverScreen::_on_visibility_changed() { + auto gameoversound = get_node("GameOverMusic"); + if (is_visible()) + { + gameoversound->play(); + } + else + { + gameoversound->stop(); + } } diff --git a/src/gui/game_over/GameOverScreen.h b/src/gui/game_over/GameOverScreen.h index 3fb679c..0dc7226 100644 --- a/src/gui/game_over/GameOverScreen.h +++ b/src/gui/game_over/GameOverScreen.h @@ -55,7 +55,7 @@ namespace alai void _on_restart_button_pressed(); void restart_game(); void connect_signal(); - void _play_music(); + void _on_visibility_changed(); }; } -- 2.30.2 From e7a1b4f2f82a743ec85850d5d02393703016282f Mon Sep 17 00:00:00 2001 From: Martin Araneda Date: Thu, 1 Sep 2022 23:22:37 -0400 Subject: [PATCH 34/36] Added music to VictoryScreen --- godot/gui/GameWon.tscn | 8 +++++++- src/gui/game_won/GameWonScreen.cpp | 15 +++++++++++++++ src/gui/game_won/GameWonScreen.h | 1 + 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/godot/gui/GameWon.tscn b/godot/gui/GameWon.tscn index 49889fc..f91c385 100644 --- a/godot/gui/GameWon.tscn +++ b/godot/gui/GameWon.tscn @@ -1,8 +1,9 @@ -[gd_scene load_steps=7 format=2] +[gd_scene load_steps=8 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/GameWonScreen.gdns" type="Script" id=3] +[ext_resource path="res://assets/sounds/victory.wav" type="AudioStream" id=4] [sub_resource type="DynamicFont" id=1] size = 50 @@ -45,4 +46,9 @@ custom_fonts/font = SubResource( 2 ) custom_styles/hover = SubResource( 3 ) text = "SALIR" +[node name="VictorySound" type="AudioStreamPlayer" parent="."] +stream = ExtResource( 4 ) +volume_db = -18.0 + +[connection signal="visibility_changed" from="." to="." method="_on_visibility_changed"] [connection signal="pressed" from="Control/QuitButton" to="." method="_on_quit_button_pressed"] diff --git a/src/gui/game_won/GameWonScreen.cpp b/src/gui/game_won/GameWonScreen.cpp index f51822e..81ddc6d 100644 --- a/src/gui/game_won/GameWonScreen.cpp +++ b/src/gui/game_won/GameWonScreen.cpp @@ -2,6 +2,7 @@ #include "Event.h" +#include #include #include @@ -11,6 +12,7 @@ void alai::GameWonScreen::_register_methods() godot::register_method("connect_signal", &GameWonScreen::connect_signal); godot::register_method("_on_player_won", &GameWonScreen::_on_player_won); godot::register_method("_on_quit_button_pressed", &GameWonScreen::_on_quit_button_pressed); + godot::register_method("_on_visibility_changed", &GameWonScreen::_on_visibility_changed); } alai::GameWonScreen::GameWonScreen() @@ -64,3 +66,16 @@ void alai::GameWonScreen::connect_signal() auto event = get_node("/root/Event"); event->connect("player_won", this, "_on_player_won"); } + +void alai::GameWonScreen::_on_visibility_changed() +{ + auto victorysound = get_node("VictorySound"); + if (is_visible()) + { + victorysound->play(); + } + else + { + victorysound->stop(); + } +} diff --git a/src/gui/game_won/GameWonScreen.h b/src/gui/game_won/GameWonScreen.h index 987b7a1..683e554 100644 --- a/src/gui/game_won/GameWonScreen.h +++ b/src/gui/game_won/GameWonScreen.h @@ -45,6 +45,7 @@ namespace alai void _on_player_won(); void _on_quit_button_pressed(); void connect_signal(); + void _on_visibility_changed(); }; } -- 2.30.2 From 866944b784168ec74130fbbab8b8d6953a243944 Mon Sep 17 00:00:00 2001 From: Martin Araneda Date: Thu, 1 Sep 2022 23:22:56 -0400 Subject: [PATCH 35/36] Added victory sound to assets --- godot/assets/sounds/victory.wav | 3 +++ godot/assets/sounds/victory.wav.import | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 godot/assets/sounds/victory.wav create mode 100644 godot/assets/sounds/victory.wav.import diff --git a/godot/assets/sounds/victory.wav b/godot/assets/sounds/victory.wav new file mode 100644 index 0000000..4287414 --- /dev/null +++ b/godot/assets/sounds/victory.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a5c247f96d1a500806f31f8efd2d31a05c2422416afe3379b50b67cb04a7e810 +size 930948 diff --git a/godot/assets/sounds/victory.wav.import b/godot/assets/sounds/victory.wav.import new file mode 100644 index 0000000..557cd90 --- /dev/null +++ b/godot/assets/sounds/victory.wav.import @@ -0,0 +1,23 @@ +[remap] + +importer="wav" +type="AudioStreamSample" +path="res://.import/victory.wav-652e970b8418d2fc380cb882ddb39b3d.sample" + +[deps] + +source_file="res://assets/sounds/victory.wav" +dest_files=[ "res://.import/victory.wav-652e970b8418d2fc380cb882ddb39b3d.sample" ] + +[params] + +force/8_bit=false +force/mono=false +force/max_rate=false +force/max_rate_hz=44100 +edit/trim=false +edit/normalize=false +edit/loop_mode=0 +edit/loop_begin=0 +edit/loop_end=-1 +compress/mode=0 -- 2.30.2 From 729d8080867cbd9db646f5e0edd315c26f6861df Mon Sep 17 00:00:00 2001 From: Chris Cromer Date: Thu, 1 Sep 2022 23:31:23 -0400 Subject: [PATCH 36/36] ready for version 1.0.0 --- godot/Main.tscn | 1 + 1 file changed, 1 insertion(+) diff --git a/godot/Main.tscn b/godot/Main.tscn index 4257b35..049625d 100644 --- a/godot/Main.tscn +++ b/godot/Main.tscn @@ -8,6 +8,7 @@ [node name="Main" type="Node"] pause_mode = 2 script = ExtResource( 1 ) +game_version = "1.0.0" level = ExtResource( 2 ) [node name="Level" type="Node" parent="."] -- 2.30.2