aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Bullet.gd7
-rw-r--r--Coin.gd21
-rw-r--r--Coin.tscn17
-rw-r--r--HUD.tscn12
-rw-r--r--KinematicBody2D.gd8
-rw-r--r--Main.gd3
-rw-r--r--Money.gd19
-rw-r--r--Player.tscn1
-rw-r--r--project.godot4
9 files changed, 82 insertions, 10 deletions
diff --git a/Bullet.gd b/Bullet.gd
index 96e69c2..b3f0b6a 100644
--- a/Bullet.gd
+++ b/Bullet.gd
@@ -3,7 +3,7 @@ export (int) var speed = 2000
var velocity = Vector2()
var target = Vector2.ZERO
-#var player = load("")
+var spawn_object = load("res://Coin.tscn")
var shot = false;
var screen_size
@@ -17,7 +17,10 @@ func _physics_process(delta):
velocity = move_and_slide(velocity)
for i in get_slide_count():
var collision = get_slide_collision(i)
- if collision.collider and "Enemy" in collision.collider.get_name():
+ if collision.collider:
+ var obj = spawn_object.instance()
+ obj.position = collision.collider.position
+ get_parent().add_child(obj)
collision.collider.free()
if velocity == Vector2(0.0, 0.0):
queue_free()
diff --git a/Coin.gd b/Coin.gd
new file mode 100644
index 0000000..fa5610e
--- /dev/null
+++ b/Coin.gd
@@ -0,0 +1,21 @@
+extends StaticBody2D
+
+
+# Declare member variables here. Examples:
+# var a = 2
+# var b = "text"
+var timer
+
+# Called when the node enters the scene tree for the first time.
+func _ready():
+ timer = Timer.new()
+ get_parent().add_child(timer)
+ timer.one_shot = true
+ timer.connect("timeout", self, "_on_timer_timeout")
+ timer.start(5.0)
+
+func _on_timer_timeout() -> void:
+ queue_free()
+# Called every frame. 'delta' is the elapsed time since the previous frame.
+#func _process(delta):
+# if timer.stopp
diff --git a/Coin.tscn b/Coin.tscn
new file mode 100644
index 0000000..64c8060
--- /dev/null
+++ b/Coin.tscn
@@ -0,0 +1,17 @@
+[gd_scene load_steps=3 format=2]
+
+[ext_resource path="res://assets/super_duper_meage_super_duper_coin.png" type="Texture" id=1]
+[ext_resource path="res://Coin.gd" type="Script" id=2]
+
+[node name="Coin" type="StaticBody2D"]
+collision_layer = 2
+collision_mask = 0
+script = ExtResource( 2 )
+
+[node name="Sprite" type="Sprite" parent="."]
+scale = Vector2( 0.1, 0.1 )
+texture = ExtResource( 1 )
+
+[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="."]
+scale = Vector2( 0.1, 0.1 )
+polygon = PoolVector2Array( 39.5, -114.6, 42.5, -101, 79.5, -101, 79.5, -95.6, 81.1, -82.3, 100.5, -78, 100.5, -62, 115.6, -62, 120.5, -57.1, 120.5, -23.2, 139.5, -19, 139.5, 41, 134.2, 41, 120.5, 44, 120.5, 79.1, 100.5, 83.1, 100.5, 97.1, 95.6, 102, 80.4, 102, 79.2, 121, 41.4, 121, 39.1, 125, -41.5, 125, -41.5, 123.6, -43.2, 121, -80.5, 121, -80.5, 115.7, -83.5, 102, -96.6, 102, -101.5, 97.1, -101.5, 82, -115.6, 82, -120.5, 77.1, -120.5, 44.3, -141.5, 40.1, -141.5, -20, -136, -20, -121.5, -23.1, -121.5, -59.5, -102.8, -61.6, -98.5, -81, -82.5, -81, -82.5, -96.1, -77.6, -101, -44.5, -101, -41.5, -114.6, -41.5, -120, 39.5, -120 )
diff --git a/HUD.tscn b/HUD.tscn
index 640ba79..5be4d5c 100644
--- a/HUD.tscn
+++ b/HUD.tscn
@@ -1,9 +1,10 @@
-[gd_scene load_steps=7 format=2]
+[gd_scene load_steps=8 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://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]
[sub_resource type="StyleBoxFlat" id=1]
bg_color = Color( 0, 1, 0, 1 )
@@ -29,7 +30,7 @@ align = 2
[node name="HealthBar" type="ProgressBar" parent="HBoxContainer"]
margin_left = 56.0
-margin_right = 1205.0
+margin_right = 1213.0
margin_bottom = 14.0
size_flags_horizontal = 3
size_flags_vertical = 3
@@ -39,16 +40,17 @@ value = 100.0
script = ExtResource( 1 )
[node name="Label2" type="Label" parent="HBoxContainer"]
-margin_left = 1215.0
+margin_left = 1223.0
margin_right = 1262.0
margin_bottom = 14.0
-text = "Money:"
+text = "Coins:"
-[node name="Label3" type="Label" parent="HBoxContainer"]
+[node name="Money" 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="."]
position = Vector2( 626, 372 )
diff --git a/KinematicBody2D.gd b/KinematicBody2D.gd
index 3bbb3a9..22f7db1 100644
--- a/KinematicBody2D.gd
+++ b/KinematicBody2D.gd
@@ -1,6 +1,7 @@
extends Area2D
signal hit
+signal coin
var screen_size
export (int) var speed = 500
var spawn_object = load("res://Bullet.tscn")
@@ -31,8 +32,11 @@ func _physics_process(delta):
if Input.is_action_just_pressed("click"):
var obj = spawn_object.instance()
obj.position = get_position()
- get_owner().add_child(obj)
+ get_parent().add_child(obj)
var bodies = get_overlapping_bodies()
for body in bodies:
- if not "Bullet" in body.get_name():
+ if "Coin" in body.get_name():
+ emit_signal("coin")
+ body.free()
+ elif "Enemy" in body.get_name():
emit_signal("hit", delta)
diff --git a/Main.gd b/Main.gd
index a80905e..f93ecbc 100644
--- a/Main.gd
+++ b/Main.gd
@@ -9,7 +9,8 @@ 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("hit", get_node("HUD/HBoxContainer/HealthBar"), "_on_player_hit")
+ get_node("KinematicBody2D").connect("coin", get_node("HUD/HBoxContainer/Money"), "_on_coin_hit")
$EnemySpawnTimer.start()
diff --git a/Money.gd b/Money.gd
new file mode 100644
index 0000000..fadd9ba
--- /dev/null
+++ b/Money.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/Player.tscn b/Player.tscn
index 915a26e..4dcae32 100644
--- a/Player.tscn
+++ b/Player.tscn
@@ -4,6 +4,7 @@
[ext_resource path="res://assets/htm_tex.png" type="Texture" id=2]
[node name="Area2D" type="Area2D"]
+collision_mask = 3
script = ExtResource( 1 )
[node name="Sprite" type="Sprite" parent="."]
diff --git a/project.godot b/project.godot
index 70d7ff1..c209dd1 100644
--- a/project.godot
+++ b/project.godot
@@ -14,6 +14,10 @@ config/name="TowerDefence"
run/main_scene="res://Node2D.tscn"
config/icon="res://icon.png"
+[audio]
+
+default_bus_layout=""
+
[autoload]
Global="*res://Global.gd"