From bb87759291786cba9378334ed88218e3bb155dbd Mon Sep 17 00:00:00 2001 From: freddie-a <57713959+freddie-a@users.noreply.github.com> Date: Sun, 30 Oct 2022 09:24:11 +0000 Subject: Code cleanup and project refactoring --- CoinCount.gd | 19 +++++++++++++++++++ Enemy.gd | 17 +++++++++++++++++ Enemy.tscn | 17 +++++++++++++++++ Enemy0.gd | 17 ----------------- Enemy0.tscn | 17 ----------------- GameOver.gd | 9 +++++++++ HUD.tscn | 19 +++++++++---------- HealthBar.gd | 2 +- Label2.gd | 20 -------------------- Main.gd | 6 +++--- Main.tscn | 36 ++++++++++++++++++++++++++++++++++++ Money.gd | 19 ------------------- Node2D.tscn | 38 -------------------------------------- Wordart.gd | 9 --------- project.godot | 2 +- 15 files changed, 112 insertions(+), 135 deletions(-) create mode 100644 CoinCount.gd create mode 100644 Enemy.gd create mode 100644 Enemy.tscn delete mode 100644 Enemy0.gd delete mode 100644 Enemy0.tscn create mode 100644 GameOver.gd delete mode 100644 Label2.gd create mode 100644 Main.tscn delete mode 100644 Money.gd delete mode 100644 Node2D.tscn delete mode 100644 Wordart.gd diff --git a/CoinCount.gd b/CoinCount.gd new file mode 100644 index 0000000..fadd9ba --- /dev/null +++ b/CoinCount.gd @@ -0,0 +1,19 @@ +extends Label + + +# Declare member variables here. Examples: +# var a = 2 +# var b = "text" +var score = 0 + + +# Called when the node enters the scene tree for the first time. +func _ready(): + pass # Replace with function body. + +func _on_coin_hit(): + score += 1 + self.text = str(score) +# Called every frame. 'delta' is the elapsed time since the previous frame. +#func _process(delta): +# pass diff --git a/Enemy.gd b/Enemy.gd new file mode 100644 index 0000000..46cb750 --- /dev/null +++ b/Enemy.gd @@ -0,0 +1,17 @@ +extends KinematicBody2D + + +# Declare member variables here. Examples: +# var a = 2 +# var b = "text" +# var player = get_node("") +onready var globals = get_node("/root/Global") + +# Called when the node enters the scene tree for the first time. +func _ready(): + pass # Replace with function body. + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + move_and_collide(global_position.direction_to(globals.playerPos).normalized() * 300 * delta) diff --git a/Enemy.tscn b/Enemy.tscn new file mode 100644 index 0000000..5e69f79 --- /dev/null +++ b/Enemy.tscn @@ -0,0 +1,17 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://assets/Likkan-boss.png" type="Texture" id=1] +[ext_resource path="res://Enemy.gd" type="Script" id=2] + +[node name="Enemy" type="KinematicBody2D"] +script = ExtResource( 2 ) + +[node name="Sprite" type="Sprite" parent="."] +position = Vector2( 7.62939e-06, 3.8147e-06 ) +scale = Vector2( 0.1, 0.1 ) +texture = ExtResource( 1 ) + +[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="."] +position = Vector2( 1.52588e-05, -9.53674e-07 ) +scale = Vector2( 0.1, 0.1 ) +polygon = PoolVector2Array( 78, -247, 78, -244.6, 91, -223.6, 91, -219.4, 96.6, -190.4, 139, -208.3, 139, -209.2, 169.5, -225, 173.7, -225, 186.7, -229, 201.9, -229, 218, -230.1, 218, -228.7, 233, -225.6, 233, -224.3, 242, -220.3, 242, -218.8, 250, -210, 250, -182.2, 239.1, -165, 237.7, -165, 209.7, -142, 207.5, -142, 146.5, -111, 143.3, -111, 116, -102.5, 116, -99.9, 109.8, -48, 108.2, -48, 102, -34.6, 102, -33.3, 106, -24, 103.7, -24, 97.3, 15.4, 102, 21.3, 102, 30, 100, 30, 96, 35, 92.1, 35, 90, 35.5, 90, 38.4, 82.3, 57, 81.1, 57, 74.2, 67.3, 91, 85.2, 91, 100.8, 80, 112.8, 81.3, 123, 79.4, 123, 78.6, 125.6, 91, 132.2, 91, 131.6, 88.7, 128.1, 89.8, 126, 91.5, 126, 105, 117.9, 105, 112.7, 108.6, 102, 110, 102, 118, 92, 120.5, 92, 139, 80.9, 139, 80, 227.8, 13.1, 224.8, 7, 227.9, 7, 229.9, 4, 233.4, 4, 236.7, 5.3, 245, 2, 245, 5.10001, 250, 9.39999, 250, 22.5, 230, 37, 235, 43.3, 235, 52, 233, 52, 229, 57, 226.6, 57, 183, 88, 183, 90.4, 190.3, 101.9, 189.2, 104, 187.7, 104, 168, 119, 168, 128, 166, 128, 163, 131.7, 171, 140.2, 171, 149.6, 167.1, 156, 165.7, 156, 152.7, 167, 146.7, 167, 139.5, 164.6, 147, 174.3, 147, 177.6, 155, 195.6, 155, 200, 161, 225.8, 161, 234, 162, 250, -250, 250, -250, 137, -228.5, 125, -225.4, 125, -162, 102.6, -162, 101.7, -132, 88.7, -132, 85.3, -119, 69, -116.6, 69, -112, 65.9, -112, 65.3, -114.8, 57, -112.4, 57, -110.4, 52, -108.8, 52, -102.8, 46, -100.4, 46, -94, 43.6, -94, 42.4, -86, 30.4, -86, 26, -91.8, 26, -102, 16.9, -102, 10.5, -100.7, 8, -105, -4.7, -105, -27.1, -102.8, -45, -100.8, -45, -96, -49.8, -96, -51, -102, -74.8, -102, -76, -101.1, -97.2, -180, -112.3, -180, -113.6, -232, -130.5, -232, -131.7, -239, -134.7, -239, -136.3, -250, -149, -250, -175, -235.9, -190, -233.4, -190, -210.3, -198, -186.8, -198, -139, -190.7, -139, -189.5, -85.7, -176.4, -75.6, -224, -74.3, -224, -69.3, -235, -67.8, -235, -58.8, -244, -56.5, -244, -51.6, -247, -38, -247, -38, -245.5, -30, -243.6, -30, -241.8, -8.2, -219, -6.8, -219, 7.10001, -215.5, 21, -219.5, 40, -246, 41.3, -246, 46, -249.9, 74, -250 ) diff --git a/Enemy0.gd b/Enemy0.gd deleted file mode 100644 index 46cb750..0000000 --- a/Enemy0.gd +++ /dev/null @@ -1,17 +0,0 @@ -extends KinematicBody2D - - -# Declare member variables here. Examples: -# var a = 2 -# var b = "text" -# var player = get_node("") -onready var globals = get_node("/root/Global") - -# Called when the node enters the scene tree for the first time. -func _ready(): - pass # Replace with function body. - - -# Called every frame. 'delta' is the elapsed time since the previous frame. -func _process(delta): - move_and_collide(global_position.direction_to(globals.playerPos).normalized() * 300 * delta) diff --git a/Enemy0.tscn b/Enemy0.tscn deleted file mode 100644 index d888b8f..0000000 --- a/Enemy0.tscn +++ /dev/null @@ -1,17 +0,0 @@ -[gd_scene load_steps=3 format=2] - -[ext_resource path="res://assets/Likkan-boss.png" type="Texture" id=1] -[ext_resource path="res://Enemy0.gd" type="Script" id=2] - -[node name="Enemy" type="KinematicBody2D"] -script = ExtResource( 2 ) - -[node name="Sprite" type="Sprite" parent="."] -position = Vector2( 7.62939e-06, 3.8147e-06 ) -scale = Vector2( 0.1, 0.1 ) -texture = ExtResource( 1 ) - -[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="."] -position = Vector2( 1.52588e-05, -9.53674e-07 ) -scale = Vector2( 0.1, 0.1 ) -polygon = PoolVector2Array( 78, -247, 78, -244.6, 91, -223.6, 91, -219.4, 96.6, -190.4, 139, -208.3, 139, -209.2, 169.5, -225, 173.7, -225, 186.7, -229, 201.9, -229, 218, -230.1, 218, -228.7, 233, -225.6, 233, -224.3, 242, -220.3, 242, -218.8, 250, -210, 250, -182.2, 239.1, -165, 237.7, -165, 209.7, -142, 207.5, -142, 146.5, -111, 143.3, -111, 116, -102.5, 116, -99.9, 109.8, -48, 108.2, -48, 102, -34.6, 102, -33.3, 106, -24, 103.7, -24, 97.3, 15.4, 102, 21.3, 102, 30, 100, 30, 96, 35, 92.1, 35, 90, 35.5, 90, 38.4, 82.3, 57, 81.1, 57, 74.2, 67.3, 91, 85.2, 91, 100.8, 80, 112.8, 81.3, 123, 79.4, 123, 78.6, 125.6, 91, 132.2, 91, 131.6, 88.7, 128.1, 89.8, 126, 91.5, 126, 105, 117.9, 105, 112.7, 108.6, 102, 110, 102, 118, 92, 120.5, 92, 139, 80.9, 139, 80, 227.8, 13.1, 224.8, 7, 227.9, 7, 229.9, 4, 233.4, 4, 236.7, 5.3, 245, 2, 245, 5.10001, 250, 9.39999, 250, 22.5, 230, 37, 235, 43.3, 235, 52, 233, 52, 229, 57, 226.6, 57, 183, 88, 183, 90.4, 190.3, 101.9, 189.2, 104, 187.7, 104, 168, 119, 168, 128, 166, 128, 163, 131.7, 171, 140.2, 171, 149.6, 167.1, 156, 165.7, 156, 152.7, 167, 146.7, 167, 139.5, 164.6, 147, 174.3, 147, 177.6, 155, 195.6, 155, 200, 161, 225.8, 161, 234, 162, 250, -250, 250, -250, 137, -228.5, 125, -225.4, 125, -162, 102.6, -162, 101.7, -132, 88.7, -132, 85.3, -119, 69, -116.6, 69, -112, 65.9, -112, 65.3, -114.8, 57, -112.4, 57, -110.4, 52, -108.8, 52, -102.8, 46, -100.4, 46, -94, 43.6, -94, 42.4, -86, 30.4, -86, 26, -91.8, 26, -102, 16.9, -102, 10.5, -100.7, 8, -105, -4.7, -105, -27.1, -102.8, -45, -100.8, -45, -96, -49.8, -96, -51, -102, -74.8, -102, -76, -101.1, -97.2, -180, -112.3, -180, -113.6, -232, -130.5, -232, -131.7, -239, -134.7, -239, -136.3, -250, -149, -250, -175, -235.9, -190, -233.4, -190, -210.3, -198, -186.8, -198, -139, -190.7, -139, -189.5, -85.7, -176.4, -75.6, -224, -74.3, -224, -69.3, -235, -67.8, -235, -58.8, -244, -56.5, -244, -51.6, -247, -38, -247, -38, -245.5, -30, -243.6, -30, -241.8, -8.2, -219, -6.8, -219, 7.10001, -215.5, 21, -219.5, 40, -246, 41.3, -246, 46, -249.9, 74, -250 ) diff --git a/GameOver.gd b/GameOver.gd new file mode 100644 index 0000000..ccde8b3 --- /dev/null +++ b/GameOver.gd @@ -0,0 +1,9 @@ +extends Sprite + +func _ready(): + visible = false + +func _on_player_dead(): + visible = true + $AudioStreamPlayer.play() + get_tree().paused = true diff --git a/HUD.tscn b/HUD.tscn index 2400419..aa6e77c 100644 --- a/HUD.tscn +++ b/HUD.tscn @@ -1,11 +1,10 @@ -[gd_scene load_steps=12 format=2] +[gd_scene load_steps=11 format=2] [ext_resource path="res://HealthBar.gd" type="Script" id=1] -[ext_resource path="res://Wordart.gd" type="Script" id=2] +[ext_resource path="res://GameOver.gd" type="Script" id=2] [ext_resource path="res://assets/wordart.png" type="Texture" id=3] [ext_resource path="res://assets/preview_4.tres" type="AudioStream" id=4] -[ext_resource path="res://Money.gd" type="Script" id=5] -[ext_resource path="res://Label2.gd" type="Script" id=6] +[ext_resource path="res://CoinCount.gd" type="Script" id=5] [ext_resource path="res://assets/MinecraftRegular-Bmg3.otf" type="DynamicFontData" id=7] [ext_resource path="res://assets/wordart(1).png" type="Texture" id=8] @@ -54,25 +53,25 @@ margin_right = 1262.0 margin_bottom = 14.0 text = "Coins:" -[node name="Money" type="Label" parent="HBoxContainer"] +[node name="CoinCount" type="Label" parent="HBoxContainer"] margin_left = 1272.0 margin_right = 1280.0 margin_bottom = 14.0 text = "0" script = ExtResource( 5 ) -[node name="Wordart" type="Sprite" parent="."] +[node name="GameOver" type="Sprite" parent="."] position = Vector2( 626, 246 ) scale = Vector2( 0.171967, 0.186029 ) texture = ExtResource( 3 ) script = ExtResource( 2 ) -[node name="Wordart(1)" type="Sprite" parent="Wordart"] +[node name="GameOverCoinMessage" type="Sprite" parent="GameOver"] position = Vector2( -488.465, 1451.39 ) scale = Vector2( 0.639108, 0.832261 ) texture = ExtResource( 8 ) -[node name="Label" type="Label" parent="Wordart/Wordart(1)"] +[node name="GameOverCoinCount" type="Label" parent="GameOver/GameOverCoinMessage"] margin_left = 3885.16 margin_top = -219.604 margin_right = 5987.16 @@ -80,8 +79,8 @@ margin_bottom = 983.396 custom_fonts/font = SubResource( 3 ) text = "0 " -script = ExtResource( 6 ) +script = ExtResource( 5 ) -[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="Wordart"] +[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="GameOver"] pause_mode = 2 stream = ExtResource( 4 ) diff --git a/HealthBar.gd b/HealthBar.gd index 57e9283..e064039 100644 --- a/HealthBar.gd +++ b/HealthBar.gd @@ -8,7 +8,7 @@ signal player_dead # Called when the node enters the scene tree for the first time. func _ready(): - connect("player_dead", get_node("/root/Main/HUD/Wordart"), "_on_player_dead") + connect("player_dead", get_node("/root/Main/HUD/GameOver"), "_on_player_dead") # Called every frame. 'delta' is the elapsed time since the previous frame. diff --git a/Label2.gd b/Label2.gd deleted file mode 100644 index b35e3a3..0000000 --- a/Label2.gd +++ /dev/null @@ -1,20 +0,0 @@ -extends Label - - -# Declare member variables here. Examples: -# var a = 2 -# var b = "text" - -var score = 0 - - -# Called when the node enters the scene tree for the first time. -func _ready(): - pass # Replace with function body. - -func _on_coin_hit(): - score += 1 - self.text = str(score) -# Called every frame. 'delta' is the elapsed time since the previous frame. -#func _process(delta): -# pass diff --git a/Main.gd b/Main.gd index 182de50..813d22b 100644 --- a/Main.gd +++ b/Main.gd @@ -6,9 +6,9 @@ onready var globals = get_node("/root/Global") # Called when the node enters the scene tree for the first time. func _ready(): randomize() - get_node("KinematicBody2D").connect("hit", get_node("HUD/HBoxContainer/HealthBar"), "_on_player_hit") - get_node("KinematicBody2D").connect("coin", get_node("HUD/HBoxContainer/Money"), "_on_coin_hit") - get_node("KinematicBody2D").connect("coin", get_node("HUD/Wordart/Wordart(1)/Label"), "_on_coin_hit") + get_node("Player").connect("hit", get_node("HUD/HBoxContainer/HealthBar"), "_on_player_hit") + get_node("Player").connect("coin", get_node("HUD/HBoxContainer/CoinCount"), "_on_coin_hit") + get_node("Player").connect("coin", get_node("HUD/GameOver/GameOverCoinMessage/GameOverCoinCount"), "_on_coin_hit") $EnemySpawnTimer.start() diff --git a/Main.tscn b/Main.tscn new file mode 100644 index 0000000..b665c9f --- /dev/null +++ b/Main.tscn @@ -0,0 +1,36 @@ +[gd_scene load_steps=7 format=2] + +[ext_resource path="res://Main.gd" type="Script" id=1] +[ext_resource path="res://HUD.tscn" type="PackedScene" id=2] +[ext_resource path="res://Player.tscn" type="PackedScene" id=3] +[ext_resource path="res://Enemy.tscn" type="PackedScene" id=4] +[ext_resource path="res://assets/maps/map2.jpg" type="Texture" id=5] + +[sub_resource type="Curve2D" id=1] +_data = { +"points": PoolVector2Array( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1280, 0, 0, 0, 0, 0, 1280, 720, 0, 0, 0, 0, 0, 720, 0, 0, 0, 0, 0, 0 ) +} + +[node name="Main" type="Node2D"] +script = ExtResource( 1 ) +enemy_scene = ExtResource( 4 ) + +[node name="Sprite" type="Sprite" parent="."] +scale = Vector2( 0.64, 0.64 ) +texture = ExtResource( 5 ) +centered = false + +[node name="Player" parent="." instance=ExtResource( 3 )] +position = Vector2( 544, 216 ) + +[node name="HUD" parent="." instance=ExtResource( 2 )] + +[node name="EnemySpawn" type="Path2D" parent="."] +curve = SubResource( 1 ) + +[node name="EnemySpawnLocation" type="PathFollow2D" parent="EnemySpawn"] + +[node name="EnemySpawnTimer" type="Timer" parent="."] +wait_time = 0.476 + +[connection signal="timeout" from="EnemySpawnTimer" to="." method="_on_EnemySpawnTimer_timeout"] diff --git a/Money.gd b/Money.gd deleted file mode 100644 index fadd9ba..0000000 --- a/Money.gd +++ /dev/null @@ -1,19 +0,0 @@ -extends Label - - -# Declare member variables here. Examples: -# var a = 2 -# var b = "text" -var score = 0 - - -# Called when the node enters the scene tree for the first time. -func _ready(): - pass # Replace with function body. - -func _on_coin_hit(): - score += 1 - self.text = str(score) -# Called every frame. 'delta' is the elapsed time since the previous frame. -#func _process(delta): -# pass diff --git a/Node2D.tscn b/Node2D.tscn deleted file mode 100644 index 0a39396..0000000 --- a/Node2D.tscn +++ /dev/null @@ -1,38 +0,0 @@ -[gd_scene load_steps=7 format=2] - -[ext_resource path="res://HUD.tscn" type="PackedScene" id=1] -[ext_resource path="res://Player.tscn" type="PackedScene" id=2] -[ext_resource path="res://Main.gd" type="Script" id=3] -[ext_resource path="res://assets/maps/map2.jpg" type="Texture" id=4] -[ext_resource path="res://Enemy0.tscn" type="PackedScene" id=5] - -[sub_resource type="Curve2D" id=1] -_data = { -"points": PoolVector2Array( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1280, 0, 0, 0, 0, 0, 1280, 720, 0, 0, 0, 0, 0, 720, 0, 0, 0, 0, 0, 0 ) -} - -[node name="Main" type="Node2D"] -script = ExtResource( 3 ) -enemy_scene = ExtResource( 5 ) - -[node name="Sprite" type="Sprite" parent="."] -scale = Vector2( 0.64, 0.64 ) -texture = ExtResource( 4 ) -centered = false - -[node name="KinematicBody2D" parent="." instance=ExtResource( 2 )] -position = Vector2( 544, 216 ) - -[node name="Node" type="Node" parent="."] - -[node name="HUD" parent="." instance=ExtResource( 1 )] - -[node name="EnemySpawn" type="Path2D" parent="."] -curve = SubResource( 1 ) - -[node name="EnemySpawnLocation" type="PathFollow2D" parent="EnemySpawn"] - -[node name="EnemySpawnTimer" type="Timer" parent="."] -wait_time = 0.476 - -[connection signal="timeout" from="EnemySpawnTimer" to="." method="_on_EnemySpawnTimer_timeout"] diff --git a/Wordart.gd b/Wordart.gd deleted file mode 100644 index ccde8b3..0000000 --- a/Wordart.gd +++ /dev/null @@ -1,9 +0,0 @@ -extends Sprite - -func _ready(): - visible = false - -func _on_player_dead(): - visible = true - $AudioStreamPlayer.play() - get_tree().paused = true diff --git a/project.godot b/project.godot index c209dd1..579b7f0 100644 --- a/project.godot +++ b/project.godot @@ -11,7 +11,7 @@ config_version=4 [application] config/name="TowerDefence" -run/main_scene="res://Node2D.tscn" +run/main_scene="res://Main.tscn" config/icon="res://icon.png" [audio] -- cgit v1.2.3-70-g09d2