Prevent overlapping buildings

This commit is contained in:
2025-04-30 11:21:34 +02:00
parent 7d79d3f60f
commit fee9cb99cf
8 changed files with 82 additions and 11 deletions

View File

@ -92,7 +92,7 @@ animations = [{
}], }],
"loop": false, "loop": false,
"name": &"play", "name": &"play",
"speed": 18.0 "speed": 32.0
}] }]
[node name="Coin" type="Node2D"] [node name="Coin" type="Node2D"]
@ -103,4 +103,17 @@ scale = Vector2(2, 2)
sprite_frames = SubResource("SpriteFrames_ibmyn") sprite_frames = SubResource("SpriteFrames_ibmyn")
animation = &"play" animation = &"play"
[node name="CPUParticles2D" type="CPUParticles2D" parent="."]
amount = 80
lifetime = 0.5
speed_scale = 1.3
explosiveness = 0.3
randomness = 1.0
lifetime_randomness = 0.1
emission_shape = 1
emission_sphere_radius = 20.0
spread = 0.0
gravity = Vector2(0, -200)
damping_max = 1.0
[connection signal="animation_finished" from="AnimatedSprite2D" to="." method="_on_animated_sprite_2d_animation_finished"] [connection signal="animation_finished" from="AnimatedSprite2D" to="." method="_on_animated_sprite_2d_animation_finished"]

View File

@ -14,6 +14,19 @@ func _input(event):
for i in list_of_entities: for i in list_of_entities:
for j in LIST_OF_ENTITIES: for j in LIST_OF_ENTITIES:
if i.get_parent().name.contains(j): if i.get_parent().name.contains(j):
match j:
"ArcherTower":
get_parent().get_node("SidePanel").Update_Coins(60)
"WizardTower":
get_parent().get_node("SidePanel").Update_Coins(30)
"MortarTower":
get_parent().get_node("SidePanel").Update_Coins(80)
"Mine":
get_parent().get_node("SidePanel").Update_Coins(10)
"StickTrap":
get_parent().get_node("SidePanel").Update_Coins(5)
"Wall":
get_parent().get_node("SidePanel").Update_Coins(0)
i.get_parent().queue_free() i.get_parent().queue_free()
queue_free() queue_free()
pass

View File

@ -11,7 +11,7 @@ const enemies = [FORKMAN, COBOLD, ORK]
func _ready() -> void: func _ready() -> void:
get_node("SidePanel").Update_Lifes(20) get_node("SidePanel").Update_Lifes(20)
get_node("SidePanel").Update_Coins(200) get_node("SidePanel").Update_Coins(2000)
func _on_timer_timeout() -> void: func _on_timer_timeout() -> void:

View File

@ -57,21 +57,21 @@ func set_character_data():
health = 100 health = 100
shield = 100 shield = 100
damage = 2 damage = 2
value = 20 value = 2
"Ork": "Ork":
self.name = "Ork-" + str(randi()) self.name = "Ork-" + str(randi())
speed = 80 speed = 80
health = 150 health = 150
shield = 200 shield = 200
damage = 5 damage = 5
value = 30 value = 3
"Cobold": "Cobold":
self.name = "Cobold-" + str(randi()) self.name = "Cobold-" + str(randi())
speed = 200 speed = 200
health = 50 health = 50
shield = 0 shield = 0
damage = 1 damage = 1
value = 10 value = 1
adjust_speed_of_animation() #adjust animation speed based on the character speed adjust_speed_of_animation() #adjust animation speed based on the character speed
current_health = health current_health = health

View File

@ -83,3 +83,10 @@ shape = SubResource("CircleShape2D_be2t6")
[node name="Timer" type="Timer" parent="."] [node name="Timer" type="Timer" parent="."]
autostart = true autostart = true
[node name="Area2D" type="Area2D" parent="."]
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
position = Vector2(0, 17)
shape = SubResource("CapsuleShape2D_ssiuv")
debug_color = Color(0.862152, 0.144907, 0.800391, 0.42)

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=7 format=3 uid="uid://uqxd2lii1xba"] [gd_scene load_steps=8 format=3 uid="uid://uqxd2lii1xba"]
[ext_resource type="Script" uid="uid://dil41a1ymo0ua" path="res://Game/Towers/towers.gd" id="1_bhlym"] [ext_resource type="Script" uid="uid://dil41a1ymo0ua" path="res://Game/Towers/towers.gd" id="1_bhlym"]
[ext_resource type="Texture2D" uid="uid://dkgih7tl654v1" path="res://Assets/Towers/Mortar part (3).png" id="1_sq58r"] [ext_resource type="Texture2D" uid="uid://dkgih7tl654v1" path="res://Assets/Towers/Mortar part (3).png" id="1_sq58r"]
@ -12,6 +12,10 @@ height = 88.0
[sub_resource type="RectangleShape2D" id="RectangleShape2D_bhlym"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_bhlym"]
size = Vector2(367.125, 172.25) size = Vector2(367.125, 172.25)
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_bhlym"]
radius = 29.0
height = 88.0
[node name="MortarTower" type="Node2D"] [node name="MortarTower" type="Node2D"]
script = ExtResource("1_bhlym") script = ExtResource("1_bhlym")
@ -46,3 +50,10 @@ texture = ExtResource("3_82ftk")
[node name="Timer" type="Timer" parent="."] [node name="Timer" type="Timer" parent="."]
autostart = true autostart = true
[node name="Area2D" type="Area2D" parent="."]
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
position = Vector2(0, 17)
shape = SubResource("CapsuleShape2D_bhlym")
debug_color = Color(0.862152, 0.144907, 0.800391, 0.42)

View File

@ -24,10 +24,25 @@ func _ready() -> void:
func _process(delta: float) -> void: func _process(delta: float) -> void:
if follower: if follower:
position = get_viewport().get_mouse_position() position = get_viewport().get_mouse_position()
if not target: if not name.contains("MortarTower"):
if get_node("Area2D").get_overlapping_bodies().size() > 1:
get_node("CharacterBody2D/AnimatedSprite2D").modulate = Color(255, 0, 0, 0.3)
else:
get_node("CharacterBody2D/AnimatedSprite2D").modulate = Color(1, 1, 1, 1)
else:
if get_node("Area2D").get_overlapping_bodies().size() > 1:
get_node("CharacterBody2D/lifter - 1").modulate = Color(255, 0, 0, 0.3)
get_node("CharacterBody2D/lifter - 2").modulate = Color(255, 0, 0, 0.3)
get_node("CharacterBody2D/MortarPart(2)").modulate = Color(255, 0, 0, 0.3)
else:
get_node("CharacterBody2D/lifter - 1").modulate = Color(1, 1, 1, 1)
get_node("CharacterBody2D/lifter - 2").modulate = Color(1, 1, 1, 1)
get_node("CharacterBody2D/MortarPart(2)").modulate = Color(1, 1, 1, 1)
elif not target:
if get_node("CharacterBody2D/Area2D").get_overlapping_bodies(): if get_node("CharacterBody2D/Area2D").get_overlapping_bodies():
choose_target(null) choose_target(null)
if lifter: elif lifter:
lifteramount += 4 lifteramount += 4
if lifteramount <= 40: if lifteramount <= 40:
get_node("CharacterBody2D/lifter - 1").position.y -= 4 get_node("CharacterBody2D/lifter - 1").position.y -= 4
@ -59,6 +74,7 @@ func get_if_moving_state():
func _input(event): func _input(event):
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and event.pressed: if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and event.pressed:
if abs(position) <= get_viewport().get_mouse_position(): if abs(position) <= get_viewport().get_mouse_position():
if get_node("Area2D").get_overlapping_bodies().size() <= 1:
follower = false follower = false
func choose_target(body : Node2D) -> void: func choose_target(body : Node2D) -> void:

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=12 format=3 uid="uid://b4e605q60lde4"] [gd_scene load_steps=13 format=3 uid="uid://b4e605q60lde4"]
[ext_resource type="Script" uid="uid://dil41a1ymo0ua" path="res://Game/Towers/towers.gd" id="1_grwc8"] [ext_resource type="Script" uid="uid://dil41a1ymo0ua" path="res://Game/Towers/towers.gd" id="1_grwc8"]
[ext_resource type="Texture2D" uid="uid://dngrpwmj4oedg" path="res://Assets/Towers/S_Fly.png" id="2_grwc8"] [ext_resource type="Texture2D" uid="uid://dngrpwmj4oedg" path="res://Assets/Towers/S_Fly.png" id="2_grwc8"]
@ -60,6 +60,10 @@ height = 88.0
[sub_resource type="CircleShape2D" id="CircleShape2D_c5q70"] [sub_resource type="CircleShape2D" id="CircleShape2D_c5q70"]
radius = 183.044 radius = 183.044
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_grwc8"]
radius = 29.0
height = 88.0
[node name="WizardTower" type="Node2D"] [node name="WizardTower" type="Node2D"]
script = ExtResource("1_grwc8") script = ExtResource("1_grwc8")
@ -87,3 +91,10 @@ shape = SubResource("CircleShape2D_c5q70")
[node name="Timer" type="Timer" parent="."] [node name="Timer" type="Timer" parent="."]
wait_time = 2.0 wait_time = 2.0
autostart = true autostart = true
[node name="Area2D" type="Area2D" parent="."]
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
position = Vector2(0, 17)
shape = SubResource("CapsuleShape2D_grwc8")
debug_color = Color(0.862152, 0.144907, 0.800391, 0.42)