From e54e3b0687373c34922abb277108a5bba7439471 Mon Sep 17 00:00:00 2001 From: Martin Araneda Date: Mon, 1 Aug 2022 15:05:09 -0400 Subject: [PATCH] changes to coinHUD --- godot/goal/Goal.tscn | 2 +- godot/hud/CoinHUD.gd | 8 +++++ godot/hud/CoinHUD.tscn | 58 +++++++++++++++++++++++++++++++++++++ godot/levels/Prototype.tscn | 56 ++--------------------------------- src/goal/GoalNotReached.cpp | 8 ++++- 5 files changed, 77 insertions(+), 55 deletions(-) create mode 100644 godot/hud/CoinHUD.gd create mode 100644 godot/hud/CoinHUD.tscn diff --git a/godot/goal/Goal.tscn b/godot/goal/Goal.tscn index 3e6e22e..ee70903 100644 --- a/godot/goal/Goal.tscn +++ b/godot/goal/Goal.tscn @@ -36,11 +36,11 @@ shape = SubResource( 5 ) position = Vector2( 18, 18 ) frames = SubResource( 8 ) animation = "flagmove" -frame = 1 playing = true [node name="StateMachine" type="Node" parent="."] script = ExtResource( 4 ) +default_state = "GoalNotReached" [node name="GoalReached" type="Node" parent="StateMachine"] script = ExtResource( 3 ) diff --git a/godot/hud/CoinHUD.gd b/godot/hud/CoinHUD.gd new file mode 100644 index 0000000..efe294f --- /dev/null +++ b/godot/hud/CoinHUD.gd @@ -0,0 +1,8 @@ +extends CanvasLayer + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _physics_process(delta): + if get_tree().paused: + visible = false + else: + visible = true diff --git a/godot/hud/CoinHUD.tscn b/godot/hud/CoinHUD.tscn new file mode 100644 index 0000000..512a8cd --- /dev/null +++ b/godot/hud/CoinHUD.tscn @@ -0,0 +1,58 @@ +[gd_scene load_steps=8 format=2] + +[ext_resource path="res://assets/coin.png" type="Texture" id=1] +[ext_resource path="res://hud/coin/Counter.gdns" type="Script" id=2] +[ext_resource path="res://hud/CoinHUD.gd" type="Script" id=3] + +[sub_resource type="StyleBoxFlat" id=1] +bg_color = Color( 0, 0, 0, 0.541176 ) + +[sub_resource type="AtlasTexture" id=2] +atlas = ExtResource( 1 ) +region = Rect2( 0, 0, 18, 18 ) + +[sub_resource type="AtlasTexture" id=3] +atlas = ExtResource( 1 ) +region = Rect2( 18, 0, 18, 18 ) + +[sub_resource type="SpriteFrames" id=4] +animations = [ { +"frames": [ SubResource( 2 ), SubResource( 3 ) ], +"loop": true, +"name": "spin", +"speed": 5.0 +} ] + +[node name="CoinHUD" type="CanvasLayer"] +pause_mode = 2 +script = ExtResource( 3 ) + +[node name="Panel" type="Panel" parent="."] +margin_left = 144.0 +margin_top = 18.0 +margin_right = 288.0 +margin_bottom = 54.0 +custom_styles/panel = SubResource( 1 ) + +[node name="Label" type="Label" parent="."] +margin_left = 180.0 +margin_top = 18.0 +margin_right = 220.0 +margin_bottom = 36.0 +text = "X" + +[node name="Coins" type="Label" parent="."] +margin_left = 198.0 +margin_top = 18.0 +margin_right = 238.0 +margin_bottom = 32.0 +text = "##" +script = ExtResource( 2 ) + +[node name="AnimatedSprite" type="AnimatedSprite" parent="."] +position = Vector2( 162, 18 ) +frames = SubResource( 4 ) +animation = "spin" +frame = 1 +playing = true +centered = false diff --git a/godot/levels/Prototype.tscn b/godot/levels/Prototype.tscn index 036f781..b71e0c7 100644 --- a/godot/levels/Prototype.tscn +++ b/godot/levels/Prototype.tscn @@ -1,33 +1,13 @@ -[gd_scene load_steps=13 format=2] +[gd_scene load_steps=8 format=2] [ext_resource path="res://CameraLimit.gdns" type="Script" id=1] [ext_resource path="res://characters/player/Player.tscn" type="PackedScene" id=2] [ext_resource path="res://levels/Prototype.tmx" type="PackedScene" id=3] [ext_resource path="res://assets/backgrounds/mountains.png" type="Texture" id=4] [ext_resource path="res://collectables/coin/Coin.tscn" type="PackedScene" id=5] -[ext_resource path="res://assets/coin.png" type="Texture" id=6] -[ext_resource path="res://hud/coin/Counter.gdns" type="Script" id=7] +[ext_resource path="res://hud/CoinHUD.tscn" type="PackedScene" id=6] [ext_resource path="res://goal/Goal.tscn" type="PackedScene" id=8] -[sub_resource type="StyleBoxFlat" id=1] -bg_color = Color( 0, 0, 0, 0.541176 ) - -[sub_resource type="AtlasTexture" id=2] -atlas = ExtResource( 6 ) -region = Rect2( 0, 0, 18, 18 ) - -[sub_resource type="AtlasTexture" id=3] -atlas = ExtResource( 6 ) -region = Rect2( 18, 0, 18, 18 ) - -[sub_resource type="SpriteFrames" id=4] -animations = [ { -"frames": [ SubResource( 2 ), SubResource( 3 ) ], -"loop": true, -"name": "spin", -"speed": 5.0 -} ] - [node name="Prototype" type="Node2D"] [node name="Player" parent="." instance=ExtResource( 2 )] @@ -64,37 +44,7 @@ centered = false [node name="Prototype" parent="Map" instance=ExtResource( 3 )] script = ExtResource( 1 ) -[node name="CoinHUD" type="CanvasLayer" parent="."] - -[node name="Panel" type="Panel" parent="CoinHUD"] -margin_left = 144.0 -margin_top = 18.0 -margin_right = 288.0 -margin_bottom = 54.0 -custom_styles/panel = SubResource( 1 ) - -[node name="Label" type="Label" parent="CoinHUD"] -margin_left = 180.0 -margin_top = 18.0 -margin_right = 220.0 -margin_bottom = 36.0 -text = "X" - -[node name="Coins" type="Label" parent="CoinHUD"] -margin_left = 198.0 -margin_top = 18.0 -margin_right = 238.0 -margin_bottom = 32.0 -text = "##" -script = ExtResource( 7 ) - -[node name="AnimatedSprite" type="AnimatedSprite" parent="CoinHUD"] -position = Vector2( 162, 18 ) -frames = SubResource( 4 ) -animation = "spin" -frame = 1 -playing = true -centered = false +[node name="CoinHUD" parent="." instance=ExtResource( 6 )] [node name="Coins" type="Node" parent="."] diff --git a/src/goal/GoalNotReached.cpp b/src/goal/GoalNotReached.cpp index c4763f3..4248066 100644 --- a/src/goal/GoalNotReached.cpp +++ b/src/goal/GoalNotReached.cpp @@ -38,7 +38,13 @@ void GoalNotReached::_state_exit() void GoalNotReached::_on_Goal_body_entered(Node *node) { - + auto parent_node = get_parent(); + + if (parent_node != nullptr) + { + auto goal = Object::cast_to(parent_node); + goal->set_collision_mask_bit(0, false); + } get_state_machine()->change("GoalReached");