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',
diff --git a/godot/Main.tscn b/godot/Main.tscn
index 5babece..049625d 100644
--- a/godot/Main.tscn
+++ b/godot/Main.tscn
@@ -1,12 +1,14 @@
-[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://levels/PrototypeR.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
script = ExtResource( 1 )
+game_version = "1.0.0"
level = ExtResource( 2 )
[node name="Level" type="Node" parent="."]
@@ -14,3 +16,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/assets/music/prototype_r.ogg b/godot/assets/music/prototype_r.ogg
new file mode 100644
index 0000000..a9c0020
--- /dev/null
+++ b/godot/assets/music/prototype_r.ogg
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:212b33aef7ed3befca6912a1fcd86e7166a9bbbe55a3422a7d10bbf1afbf5020
+size 2189889
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/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
diff --git a/godot/characters/enemies/WalkingEnemy.gd b/godot/characters/enemies/WalkingEnemy.gd
index c1c54b5..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
@@ -16,6 +13,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:
@@ -31,8 +29,15 @@ 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)
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..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
@@ -22,6 +19,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 +28,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 +60,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)
@@ -77,6 +79,10 @@ 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
+
+
+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..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
@@ -11,17 +8,27 @@ 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:
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:
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))
diff --git a/godot/characters/player/Player.tscn b/godot/characters/player/Player.tscn
index bbd2fc2..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 = -45.0
+volume_db = -20.0
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/GUI/GameOver.tscn b/godot/gui/GameOver.tscn
similarity index 77%
rename from godot/GUI/GameOver.tscn
rename to godot/gui/GameOver.tscn
index ba0990d..08d8f03 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://gui/GameOverScreen.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 = -25.0
+
+[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/godot/GUI/botonreiniciar.gdns b/godot/gui/GameOverScreen.gdns
similarity index 100%
rename from godot/GUI/botonreiniciar.gdns
rename to godot/gui/GameOverScreen.gdns
diff --git a/godot/gui/GameWon.tscn b/godot/gui/GameWon.tscn
new file mode 100644
index 0000000..f91c385
--- /dev/null
+++ b/godot/gui/GameWon.tscn
@@ -0,0 +1,54 @@
+[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
+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"
+
+[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/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/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..b585f63 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/prototype_r.ogg" type="AudioStream" id=7]
[ext_resource path="res://goal/Goal.tscn" type="PackedScene" id=8]
[node name="Prototype" type="Node2D"]
@@ -56,4 +57,9 @@ 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/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"]
diff --git a/godot/levels/PrototypeR.tmx b/godot/levels/PrototypeR.tmx
new file mode 100644
index 0000000..6280b25
--- /dev/null
+++ b/godot/levels/PrototypeR.tmx
@@ -0,0 +1,19 @@
+
+
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..e6ac0ce
--- /dev/null
+++ b/godot/levels/PrototypeR.tscn
@@ -0,0 +1,154 @@
+[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]
+[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]
+[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]
+[ext_resource path="res://characters/enemies/blightwing/Blightwing.tscn" type="PackedScene" id=14]
+
+[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"]
+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="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 )
+
+[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 )
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/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/Event.cpp b/src/Event.cpp
index 6561979..9605468 100644
--- a/src/Event.cpp
+++ b/src/Event.cpp
@@ -2,11 +2,16 @@
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);
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);
}
diff --git a/src/Main.cpp b/src/Main.cpp
index 4f895bd..353882b 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");
}
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/coin/CoinCollected.cpp b/src/coin/CoinCollected.cpp
index 5c30b82..0e9921f 100644
--- a/src/coin/CoinCollected.cpp
+++ b/src/coin/CoinCollected.cpp
@@ -2,13 +2,14 @@
#include "Event.h"
+#include
#include
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()
@@ -32,12 +33,12 @@ 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()
{
-
}
void alai::CoinCollected::_on_animation_finished(godot::String anim_name)
diff --git a/src/coin/CoinCounter.cpp b/src/coin/CoinCounter.cpp
index 667ea9e..e29280b 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()
@@ -23,15 +23,28 @@ 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;
+ if (coins >= 100)
+ {
+ auto extra = coins - 100;
+ coins = extra;
+ }
+ 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);
+}
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:
/**
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..6afb5f0 100644
--- a/src/goal/GoalReached.cpp
+++ b/src/goal/GoalReached.cpp
@@ -1,11 +1,13 @@
#include "goal/GoalReached.h"
+#include "Event.h"
+
#include
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()
@@ -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_over/GameOverScreen.cpp b/src/gui/game_over/GameOverScreen.cpp
index fc35153..9dcdf47 100644
--- a/src/gui/game_over/GameOverScreen.cpp
+++ b/src/gui/game_over/GameOverScreen.cpp
@@ -1,7 +1,8 @@
#include "gui/game_over/GameOverScreen.h"
+
#include "Event.h"
-#include
+#include
#include
#include
#include
@@ -9,11 +10,13 @@
#include
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("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("_on_visibility_changed", &GameOverScreen::_on_visibility_changed);
}
alai::GameOverScreen::GameOverScreen()
@@ -36,9 +39,9 @@ void alai::GameOverScreen::_ready()
void alai::GameOverScreen::_on_restart_button_pressed()
{
- if (_resource_loader->exists("res://levels/Prototype.tscn"))
+ 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");
@@ -46,7 +49,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
{
@@ -80,8 +83,28 @@ 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");
event->connect("player_died", this, "_on_player_died");
}
+
+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 892a316..0dc7226 100644
--- a/src/gui/game_over/GameOverScreen.h
+++ b/src/gui/game_over/GameOverScreen.h
@@ -1,10 +1,11 @@
-#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
#include
+
namespace alai
{
/**
@@ -52,7 +53,9 @@ namespace alai
void _ready();
void _on_player_died();
void _on_restart_button_pressed();
+ void restart_game();
void connect_signal();
+ void _on_visibility_changed();
};
}
diff --git a/src/gui/game_won/GameWonScreen.cpp b/src/gui/game_won/GameWonScreen.cpp
new file mode 100644
index 0000000..81ddc6d
--- /dev/null
+++ b/src/gui/game_won/GameWonScreen.cpp
@@ -0,0 +1,81 @@
+#include "gui/game_won/GameWonScreen.h"
+
+#include "Event.h"
+
+#include
+#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);
+ godot::register_method("_on_visibility_changed", &GameWonScreen::_on_visibility_changed);
+}
+
+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");
+}
+
+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
new file mode 100644
index 0000000..683e554
--- /dev/null
+++ b/src/gui/game_won/GameWonScreen.h
@@ -0,0 +1,52 @@
+#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();
+ void _on_visibility_changed();
+ };
+}
+
+#endif
diff --git a/src/player/Player.cpp b/src/player/Player.cpp
index 68df74f..43dce2e 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);
@@ -51,11 +51,17 @@ void alai::player::Player::_init()
coins = 0;
+ notifier_initialized = false;
+
velocity = godot::Vector2();
}
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)
{
@@ -77,7 +83,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)
{
@@ -151,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);
}
}
@@ -186,10 +192,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
@@ -289,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 cedcfb5..9510e09 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:
/**
@@ -278,13 +283,13 @@ 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.
*
*/
- void _on_monitor_loaded();
+ void _on_level_loaded();
};
}
}
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()