diff --git a/buildings/building.gd b/buildings/building.gd index 9bad536..09d6dd2 100644 --- a/buildings/building.gd +++ b/buildings/building.gd @@ -14,9 +14,17 @@ func _ready() -> void: grid.buildings.append(self) + await get_tree().create_timer(0).timeout if get_node_or_null("EnemyList") != null: for enemy in $EnemyList.get_children(): - enemy.reparent(get_parent()) + var oldpos = enemy.position; + enemy.reparent(get_tree().get_root()) + enemy.position = get_world_position(oldpos) + +func get_world_position (local_position: Vector2) -> Vector2: + var height = grid.ground_radius + location.y * grid.cell_height - local_position.y + var angle = (location.x + local_position.x / grid.cell_height) * TAU / grid.num_collumns + return height * Vector2.from_angle(angle) func overlaps(other : Building): # heights don't overlap diff --git a/buildings/building.gdshader b/buildings/building.gdshader index 4176c28..4463040 100644 --- a/buildings/building.gdshader +++ b/buildings/building.gdshader @@ -13,7 +13,7 @@ void vertex() { location = ivec2(128. * COLOR.xy); dimension = ivec2(128. * COLOR.zw); - + vec2 myloc = vec2(location) + UV * (vec2(dimension) + vec2(0., .5)); float angle = float(myloc.x) * TAU / 60.; float height = float(myloc.y) * cell_height + ground_height; diff --git a/buildings/building.tscn b/buildings/building.tscn index 359abc8..bbbdf5a 100644 --- a/buildings/building.tscn +++ b/buildings/building.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=8 format=3 uid="uid://djawvtdwp423v"] +[gd_scene load_steps=9 format=3 uid="uid://djawvtdwp423v"] [ext_resource type="Script" uid="uid://b2ji03ekijjnn" path="res://buildings/building.gd" id="1_5j34s"] [ext_resource type="Shader" uid="uid://c7gb1nqwvkr37" path="res://buildings/building.gdshader" id="2_xx8ra"] @@ -6,6 +6,7 @@ [ext_resource type="Script" uid="uid://dj7d4d2xs3nci" path="res://buildings/building_mesh.gd" id="4_xr4t5"] [ext_resource type="Texture2D" uid="uid://3weywjfsapax" path="res://buildings/Building 2x1 downside.png" id="5_pfkkr"] [ext_resource type="PackedScene" uid="uid://dpv1w56yr1xue" path="res://traps/morning_star.tscn" id="5_xr4t5"] +[ext_resource type="PackedScene" uid="uid://chu67ci7sl488" path="res://enemies/ghost.tscn" id="7_35wcg"] [sub_resource type="ShaderMaterial" id="ShaderMaterial_pfkkr"] shader = ExtResource("2_xx8ra") @@ -32,3 +33,13 @@ grid_offset = Vector2i(0, -1) [node name="EnemyList" type="Node2D" parent="."] [node name="MorningStar" parent="EnemyList" instance=ExtResource("5_xr4t5")] +position = Vector2(397, -3) + +[node name="Ghost" parent="EnemyList" instance=ExtResource("7_35wcg")] +position = Vector2(118, -125) + +[node name="DebugSprite" type="Sprite2D" parent="."] +visible = false +position = Vector2(300, -150) +scale = Vector2(1.172, 1.172) +texture = ExtResource("3_xr4t5") diff --git a/buildings/haunted_house.tscn b/buildings/haunted_house.tscn index 0e0aa2f..bec7e3a 100644 --- a/buildings/haunted_house.tscn +++ b/buildings/haunted_house.tscn @@ -27,4 +27,4 @@ script = ExtResource("4_bl5jt") [node name="EnemyList" type="Node2D" parent="."] [node name="Ghost" parent="EnemyList" instance=ExtResource("5_23fi7")] -position = Vector2(115, -75) +position = Vector2(150, 300) diff --git a/enemies/ghost.gd b/enemies/ghost.gd index 6ae5899..56edb5c 100644 --- a/enemies/ghost.gd +++ b/enemies/ghost.gd @@ -23,6 +23,7 @@ func _physics_process(delta: float) -> void: var motion = -(position - target.position).normalized() * speed self.position += motion * delta * min(1, dist/(motion.length()*delta)) + self.position += earth_aligner.global_from_local(current_knockback) * delta current_knockback = current_knockback/pow(1.3, 60*delta) diff --git a/main.tscn b/main.tscn index 1fb61bd..ab01c3e 100644 --- a/main.tscn +++ b/main.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=9 format=3 uid="uid://cxo6bq26huau7"] +[gd_scene load_steps=10 format=3 uid="uid://cxo6bq26huau7"] [ext_resource type="PackedScene" uid="uid://cmaovvr15b3qk" path="res://player/player.tscn" id="2_1bvp3"] [ext_resource type="Script" uid="uid://vgxh2xdevat7" path="res://world/earth.gd" id="2_lquwl"] @@ -22,6 +22,10 @@ position = Vector2(0, -3200) [node name="Platform" parent="." instance=ExtResource("4_5vw27")] position = Vector2(934, -2965) +[node name="Debug_Camera" type="Camera2D" parent="."] +scale = Vector2(41.02, 41.02) +zoom = Vector2(0.15, 0.15) + [node name="Player" parent="." instance=ExtResource("2_1bvp3")] unique_name_in_owner = true position = Vector2(500, -3100) @@ -31,15 +35,11 @@ scale = Vector2(3, 3) position = Vector2(0, -50) ignore_rotation = false -[node name="Debug_Camera" type="Camera2D" parent="."] -scale = Vector2(41.020004, 41.020004) -zoom = Vector2(0.15, 0.15) - [node name="Building Generator" type="Node" parent="."] script = ExtResource("4_1bvp3") [node name="Timer" type="Timer" parent="Building Generator"] -wait_time = 0.5 +wait_time = 5.0 autostart = true [node name="CanvasLayer" type="CanvasLayer" parent="."] @@ -54,11 +54,6 @@ visible = false [node name="MorningStar" parent="." instance=ExtResource("7_272bh")] position = Vector2(989, -2939) -[node name="Debug_Camera" type="Camera2D" parent="."] -position = Vector2(0.999969, 0) -scale = Vector2(41.02, 41.02) -zoom = Vector2(0.12, 0.12) - [connection signal="health_changed" from="Player" to="CanvasLayer/Healthbar" method="_on_player_health_changed"] [connection signal="player_died" from="Player" to="CanvasLayer/DeathScreen" method="_on_player_player_died"] [connection signal="timeout" from="Building Generator/Timer" to="Building Generator" method="_on_timer_timeout"] diff --git a/world/earth.tscn b/world/earth.tscn index 1814f18..2269158 100644 --- a/world/earth.tscn +++ b/world/earth.tscn @@ -21,7 +21,6 @@ radius = 3000.0 [node name="Grid" type="Node2D" parent="."] unique_name_in_owner = true -position = Vector2(1, 0) script = ExtResource("3_2bhor") ground_radius = 3000.0 cell_height = 300.0 @@ -30,4 +29,4 @@ packed_buildings = Array[PackedScene]([ExtResource("3_nihcy"), ExtResource("4_ml metadata/_custom_type_script = "uid://m3vyyfk8gnma" [node name="Building" parent="Grid" instance=ExtResource("3_nihcy")] -location = Vector2i(45, 1) +location = Vector2i(45, 0)