Made buildings EnemyList more robust

This commit is contained in:
Florian 2025-09-16 16:24:53 +02:00
parent 85c16a2d69
commit b3b8ba3304
3 changed files with 31 additions and 11 deletions

View file

@ -1,7 +1,7 @@
class_name Building extends Node2D class_name Building extends Node2D
var location : Vector2i # x is the angle, y is the height in the grid var location : Vector2i # x is the angle, y is the height in the grid
var dimension : Vector2i = Vector2(2, 1) # same as above @export var dimension : Vector2i = Vector2(2, 1) # same as above
@onready var grid : Grid = get_parent() @onready var grid : Grid = get_parent()
# make sure location is set before adding a building to the scene tree # make sure location is set before adding a building to the scene tree
@ -11,8 +11,10 @@ func _ready() -> void:
var angle = location.x * TAU / grid.num_collumns; # currently assumes anchor is bottom left var angle = location.x * TAU / grid.num_collumns; # currently assumes anchor is bottom left
var height = grid.ground_radius + location.y * grid.cell_height; var height = grid.ground_radius + location.y * grid.cell_height;
position = height * Vector2.from_angle(angle) position = height * Vector2.from_angle(angle)
grid.buildings.append(self) grid.buildings.append(self)
if get_node_or_null("EnemyList") != null:
for enemy in $EnemyList.get_children(): for enemy in $EnemyList.get_children():
enemy.reparent(get_parent()) enemy.reparent(get_parent())

View file

@ -1,10 +1,9 @@
[gd_scene load_steps=7 format=3 uid="uid://djawvtdwp423v"] [gd_scene load_steps=6 format=3 uid="uid://djawvtdwp423v"]
[ext_resource type="Script" uid="uid://b2ji03ekijjnn" path="res://buildings/building.gd" id="1_5j34s"] [ext_resource type="Script" uid="uid://b2ji03ekijjnn" path="res://buildings/building.gd" id="1_5j34s"]
[ext_resource type="Texture2D" uid="uid://cy70quh6k3s1j" path="res://icon.svg" id="2_2yopf"] [ext_resource type="Texture2D" uid="uid://cy70quh6k3s1j" path="res://icon.svg" id="2_2yopf"]
[ext_resource type="Shader" uid="uid://c7gb1nqwvkr37" path="res://buildings/building.gdshader" id="2_f1gjg"] [ext_resource type="Shader" uid="uid://c7gb1nqwvkr37" path="res://buildings/building.gdshader" id="2_f1gjg"]
[ext_resource type="Script" uid="uid://dj7d4d2xs3nci" path="res://buildings/building_mesh.gd" id="4_qnfc1"] [ext_resource type="Script" uid="uid://dj7d4d2xs3nci" path="res://buildings/building_mesh.gd" id="4_qnfc1"]
[ext_resource type="PackedScene" uid="uid://chu67ci7sl488" path="res://enemies/ghost.tscn" id="5_xr4t5"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_qnfc1"] [sub_resource type="ShaderMaterial" id="ShaderMaterial_qnfc1"]
resource_local_to_scene = true resource_local_to_scene = true
@ -22,7 +21,3 @@ material = SubResource("ShaderMaterial_qnfc1")
scale = Vector2(25, 25) scale = Vector2(25, 25)
texture = ExtResource("2_2yopf") texture = ExtResource("2_2yopf")
script = ExtResource("4_qnfc1") script = ExtResource("4_qnfc1")
[node name="EnemyList" type="Node2D" parent="."]
[node name="Ghost" parent="EnemyList" instance=ExtResource("5_xr4t5")]

View file

@ -1,6 +1,29 @@
[gd_scene load_steps=2 format=3 uid="uid://bno6flekdwx88"] [gd_scene load_steps=7 format=3 uid="uid://bno6flekdwx88"]
[ext_resource type="Script" uid="uid://b2ji03ekijjnn" path="res://buildings/building.gd" id="1_q3nfb"] [ext_resource type="Script" uid="uid://b2ji03ekijjnn" path="res://buildings/building.gd" id="1_q3nfb"]
[ext_resource type="Shader" uid="uid://c7gb1nqwvkr37" path="res://buildings/building.gdshader" id="2_uv7v8"]
[ext_resource type="Texture2D" uid="uid://cy70quh6k3s1j" path="res://icon.svg" id="3_e6j05"]
[ext_resource type="Script" uid="uid://dj7d4d2xs3nci" path="res://buildings/building_mesh.gd" id="4_bl5jt"]
[ext_resource type="PackedScene" uid="uid://chu67ci7sl488" path="res://enemies/ghost.tscn" id="5_23fi7"]
[node name="HauntedHouse" type="Node2D"] [sub_resource type="ShaderMaterial" id="ShaderMaterial_qnfc1"]
resource_local_to_scene = true
shader = ExtResource("2_uv7v8")
shader_parameter/ground_height = 3000.0
shader_parameter/cell_height = 300.0
shader_parameter/num_cells = 60
[node name="Building" type="Node2D"]
script = ExtResource("1_q3nfb") script = ExtResource("1_q3nfb")
dimension = Vector2i(1, 2)
[node name="Sprite2D" type="Sprite2D" parent="."]
self_modulate = Color(0.1764706, 0, 0.003921569, 0.003921569)
material = SubResource("ShaderMaterial_qnfc1")
scale = Vector2(25, 25)
texture = ExtResource("3_e6j05")
script = ExtResource("4_bl5jt")
[node name="EnemyList" type="Node2D" parent="."]
[node name="Ghost" parent="EnemyList" instance=ExtResource("5_23fi7")]