First Growing Vine
This commit is contained in:
parent
f790694373
commit
8d642f694d
13 changed files with 243 additions and 15 deletions
22
main.tscn
22
main.tscn
|
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=17 format=3 uid="uid://cxo6bq26huau7"]
|
||||
[gd_scene load_steps=18 format=3 uid="uid://cxo6bq26huau7"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://cmaovvr15b3qk" path="res://player/player.tscn" id="2_1bvp3"]
|
||||
[ext_resource type="Texture2D" uid="uid://d3fpq76anm4t7" path="res://world/Background Prototype/Background prototype.png" id="3_kek77"]
|
||||
|
|
@ -16,6 +16,7 @@
|
|||
[ext_resource type="PackedScene" uid="uid://cpe4s6vsn0ujd" path="res://enemies/boss/boss.tscn" id="11_efxa6"]
|
||||
[ext_resource type="Script" uid="uid://gul4u5tw1vxk" path="res://bg_image.gd" id="13_vivmo"]
|
||||
[ext_resource type="PackedScene" uid="uid://dhxnae8wbhp3u" path="res://vines_petals/bud.tscn" id="16_2cqfq"]
|
||||
[ext_resource type="PackedScene" uid="uid://b7o82cdfwuqd1" path="res://vines_petals/vine.tscn" id="17_yaehf"]
|
||||
|
||||
[node name="main" type="Node2D"]
|
||||
|
||||
|
|
@ -85,6 +86,7 @@ visible = false
|
|||
[node name="Water" parent="." instance=ExtResource("10_4c57u")]
|
||||
unique_name_in_owner = true
|
||||
z_index = 15
|
||||
position = Vector2(102, 0)
|
||||
|
||||
[node name="Background" type="CanvasLayer" parent="."]
|
||||
layer = -1
|
||||
|
|
@ -104,8 +106,22 @@ colors = Array[Color]([Color(0, 0.6441987, 0.6693053, 1), Color(0.90588236, 0.15
|
|||
script = ExtResource("10_efxa6")
|
||||
boss = ExtResource("11_efxa6")
|
||||
|
||||
[node name="Bud" parent="." instance=ExtResource("16_2cqfq")]
|
||||
position = Vector2(897, -3027)
|
||||
[node name="Vine" parent="." instance=ExtResource("17_yaehf")]
|
||||
|
||||
[node name="Bud" parent="Vine" node_paths=PackedStringArray("vine") instance=ExtResource("16_2cqfq")]
|
||||
position = Vector2(1320, -3484)
|
||||
vine = NodePath("..")
|
||||
location = Vector2(46, 1)
|
||||
offset = Vector2(150, 150)
|
||||
|
||||
[node name="Node2D2" type="Node2D" parent="Vine"]
|
||||
position = Vector2(963, -3171)
|
||||
|
||||
[node name="Node2D4" type="Node2D" parent="Vine"]
|
||||
position = Vector2(1035, -3518)
|
||||
|
||||
[node name="Node2D5" type="Node2D" parent="Vine"]
|
||||
position = Vector2(1551, -2955)
|
||||
|
||||
[connection signal="active_item_changed" from="Player" to="UIOverlay/ItemUI" method="_on_player_active_item_changed"]
|
||||
[connection signal="health_changed" from="Player" to="UIOverlay/Healthbar" method="_on_player_health_changed"]
|
||||
|
|
|
|||
129
main.tscn13002292799.tmp
Normal file
129
main.tscn13002292799.tmp
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
[gd_scene load_steps=18 format=3 uid="uid://cxo6bq26huau7"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://cmaovvr15b3qk" path="res://player/player.tscn" id="2_1bvp3"]
|
||||
[ext_resource type="Texture2D" uid="uid://d3fpq76anm4t7" path="res://world/Background Prototype/Background prototype.png" id="3_kek77"]
|
||||
[ext_resource type="PackedScene" uid="uid://jjoyj1ldafkf" path="res://world/earth.tscn" id="3_lquwl"]
|
||||
[ext_resource type="Script" uid="uid://colvx6wq0e8n7" path="res://world/building_generator.gd" id="4_1bvp3"]
|
||||
[ext_resource type="PackedScene" uid="uid://snvs7fty1l5a" path="res://ui/initial_text/initial_text.tscn" id="4_dg77c"]
|
||||
[ext_resource type="Texture2D" uid="uid://c6bd4kakb1tr3" path="res://utils/empty.png" id="4_ycdy4"]
|
||||
[ext_resource type="PackedScene" uid="uid://73g8y37skebh" path="res://ui/item_ui/item_ui.tscn" id="6_4c57u"]
|
||||
[ext_resource type="PackedScene" uid="uid://cjsrtswk4vgf2" path="res://ui/healthbar/healthbar.tscn" id="6_7mycd"]
|
||||
[ext_resource type="PackedScene" uid="uid://dpdn2php3ydsv" path="res://ui/death_screen/death_screen.tscn" id="7_5vw27"]
|
||||
[ext_resource type="Script" uid="uid://3k6r3jnko4hg" path="res://utils/show_fps.gd" id="8_5vw27"]
|
||||
[ext_resource type="PackedScene" uid="uid://ca5ndobertnp4" path="res://water/water.tscn" id="10_4c57u"]
|
||||
[ext_resource type="Script" uid="uid://cpaskpj67pnaj" path="res://enemies/boss/boss_spawner.gd" id="10_efxa6"]
|
||||
[ext_resource type="PackedScene" uid="uid://cqn67nwyrtq3k" path="res://ui/journal/journal.tscn" id="10_w48qg"]
|
||||
[ext_resource type="PackedScene" uid="uid://cpe4s6vsn0ujd" path="res://enemies/boss/boss.tscn" id="11_efxa6"]
|
||||
[ext_resource type="Script" uid="uid://gul4u5tw1vxk" path="res://bg_image.gd" id="13_vivmo"]
|
||||
[ext_resource type="PackedScene" uid="uid://dhxnae8wbhp3u" path="res://vines_petals/bud.tscn" id="16_2cqfq"]
|
||||
[ext_resource type="PackedScene" uid="uid://b7o82cdfwuqd1" path="res://vines_petals/vine.tscn" id="17_yaehf"]
|
||||
|
||||
[node name="main" type="Node2D"]
|
||||
|
||||
[node name="Earth" parent="." instance=ExtResource("3_lquwl")]
|
||||
unique_name_in_owner = true
|
||||
|
||||
[node name="Player" parent="." instance=ExtResource("2_1bvp3")]
|
||||
unique_name_in_owner = true
|
||||
position = Vector2(578, -3017)
|
||||
scale = Vector2(3, 3)
|
||||
|
||||
[node name="Camera2D" type="Camera2D" parent="Player"]
|
||||
position = Vector2(0, -50)
|
||||
ignore_rotation = false
|
||||
|
||||
[node name="Debug_Camera" type="Camera2D" parent="."]
|
||||
scale = Vector2(41.02, 41.02)
|
||||
zoom = Vector2(0.12, 0.12)
|
||||
|
||||
[node name="Building Generator" type="Node" parent="."]
|
||||
script = ExtResource("4_1bvp3")
|
||||
initial_buildings = 10
|
||||
|
||||
[node name="Timer" type="Timer" parent="Building Generator"]
|
||||
wait_time = 3.0
|
||||
autostart = true
|
||||
|
||||
[node name="UIOverlay" type="CanvasLayer" parent="."]
|
||||
|
||||
[node name="TextureRect" type="TextureRect" parent="UIOverlay"]
|
||||
offset_right = 40.0
|
||||
offset_bottom = 40.0
|
||||
texture = ExtResource("4_ycdy4")
|
||||
|
||||
[node name="InitialText" parent="UIOverlay" instance=ExtResource("4_dg77c")]
|
||||
|
||||
[node name="Healthbar" parent="UIOverlay" instance=ExtResource("6_7mycd")]
|
||||
offset_right = 96.0
|
||||
offset_bottom = 96.0
|
||||
|
||||
[node name="ActiveItemUses" type="VBoxContainer" parent="UIOverlay"]
|
||||
unique_name_in_owner = true
|
||||
offset_left = 1863.0
|
||||
offset_top = 25.0
|
||||
offset_right = 1895.0
|
||||
offset_bottom = 120.0
|
||||
alignment = 2
|
||||
|
||||
[node name="ItemUI" parent="UIOverlay" node_paths=PackedStringArray("player") instance=ExtResource("6_4c57u")]
|
||||
player = NodePath("../../Player")
|
||||
|
||||
[node name="DeathScreen" parent="UIOverlay" instance=ExtResource("7_5vw27")]
|
||||
visible = false
|
||||
|
||||
[node name="FPS" type="Label" parent="UIOverlay"]
|
||||
anchors_preset = 1
|
||||
anchor_left = 1.0
|
||||
anchor_right = 1.0
|
||||
offset_left = -40.0
|
||||
offset_bottom = 23.0
|
||||
grow_horizontal = 0
|
||||
script = ExtResource("8_5vw27")
|
||||
|
||||
[node name="Journal" parent="UIOverlay" instance=ExtResource("10_w48qg")]
|
||||
visible = false
|
||||
|
||||
[node name="Water" parent="." instance=ExtResource("10_4c57u")]
|
||||
unique_name_in_owner = true
|
||||
z_index = 15
|
||||
position = Vector2(102, 0)
|
||||
|
||||
[node name="Background" type="CanvasLayer" parent="."]
|
||||
layer = -1
|
||||
|
||||
[node name="ColorRect" type="TextureRect" parent="Background"]
|
||||
modulate = Color(0.544974, 0.544974, 0.544974, 1)
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
texture = ExtResource("3_kek77")
|
||||
script = ExtResource("13_vivmo")
|
||||
colors = Array[Color]([Color(0, 0.6441987, 0.6693053, 1), Color(0.90588236, 0.15686275, 0.21176471, 0.60784316), Color(0.69803923, 0.69803923, 0.69803923, 1)])
|
||||
|
||||
[node name="BossSpawner" type="Node" parent="."]
|
||||
script = ExtResource("10_efxa6")
|
||||
boss = ExtResource("11_efxa6")
|
||||
|
||||
[node name="Vine" parent="." instance=ExtResource("17_yaehf")]
|
||||
|
||||
[node name="Bud" parent="Vine" instance=ExtResource("16_2cqfq")]
|
||||
position = Vector2(271, -3293)
|
||||
|
||||
[node name="Node2D2" type="Node2D" parent="Vine"]
|
||||
position = Vector2(963, -3171)
|
||||
|
||||
[node name="Node2D4" type="Node2D" parent="Vine"]
|
||||
position = Vector2(1035, -3518)
|
||||
|
||||
[node name="Node2D5" type="Node2D" parent="Vine"]
|
||||
position = Vector2(1551, -2955)
|
||||
|
||||
[connection signal="active_item_changed" from="Player" to="UIOverlay/ItemUI" method="_on_player_active_item_changed"]
|
||||
[connection signal="health_changed" from="Player" to="UIOverlay/Healthbar" method="_on_player_health_changed"]
|
||||
[connection signal="max_hp_changed" from="Player" to="UIOverlay/Healthbar" method="_on_player_max_hp_changed"]
|
||||
[connection signal="player_died" from="Player" to="UIOverlay/DeathScreen" method="_on_player_player_died"]
|
||||
[connection signal="timeout" from="Building Generator/Timer" to="Building Generator" method="_on_timer_timeout"]
|
||||
[connection signal="visibility_changed" from="UIOverlay/DeathScreen" to="Player" method="_on_death_screen_visibility_changed"]
|
||||
[connection signal="water_reached_max_height" from="Water" to="BossSpawner" method="_on_water_water_reached_max_height"]
|
||||
3
vine.gd
3
vine.gd
|
|
@ -1,3 +0,0 @@
|
|||
extends Node2D
|
||||
|
||||
var vine_nodes : Array[Vector2]
|
||||
|
|
@ -1,6 +1,23 @@
|
|||
class_name Bud extends Node2D
|
||||
class_name Bud extends VineNode
|
||||
signal opened
|
||||
|
||||
func _on_opened():
|
||||
$AnimatedSprite2D.play("open")
|
||||
opened.emit()
|
||||
spread()
|
||||
await $AnimatedSprite2D.animation_finished
|
||||
queue_free()
|
||||
|
||||
func spread():
|
||||
for dir in [Vector2.UP, Vector2.DOWN, Vector2.RIGHT, Vector2.LEFT]:
|
||||
if not vine.vine_locations.has(location + dir):
|
||||
vine.vine_locations.append(location + dir)
|
||||
grow_to_next_bud(dir)
|
||||
|
||||
func grow_to_next_bud(dir):
|
||||
var target_offset = Vector2(randf_range(60, 240), randf_range(60, 240))
|
||||
var pos1 = grid.get_world_position(location, offset)
|
||||
var pos2 = grid.get_world_position(location + dir, target_offset)
|
||||
var num_seg = floor((pos1-pos2).length() / 96)
|
||||
var path = "res://vines_petals/vine_active_green.png"
|
||||
await vine.grow_vine_sequence(location, offset, location + dir, target_offset, num_seg, path, true)
|
||||
|
|
|
|||
|
|
@ -34,14 +34,17 @@ radius = 12.0
|
|||
[sub_resource type="CircleShape2D" id="CircleShape2D_rupnl"]
|
||||
|
||||
[node name="Bud" type="Node2D"]
|
||||
z_index = 1
|
||||
script = ExtResource("1_543bc")
|
||||
|
||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
||||
position = Vector2(0, -46)
|
||||
scale = Vector2(3, 3)
|
||||
sprite_frames = SubResource("SpriteFrames_rnmbv")
|
||||
animation = &"open"
|
||||
|
||||
[node name="EnemyHurtbox" type="Area2D" parent="."]
|
||||
position = Vector2(0, -46)
|
||||
scale = Vector2(3, 3)
|
||||
collision_layer = 16
|
||||
collision_mask = 0
|
||||
|
|
@ -61,5 +64,6 @@ scale = Vector2(0.5, 1)
|
|||
shape = SubResource("CircleShape2D_rupnl")
|
||||
|
||||
[node name="EarthAligner" parent="." instance=ExtResource("7_tg157")]
|
||||
position = Vector2(0, -46)
|
||||
|
||||
[connection signal="died" from="EnemyHurtbox" to="." method="_on_opened"]
|
||||
|
|
|
|||
61
vines_petals/vine.gd
Normal file
61
vines_petals/vine.gd
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
class_name Vine extends Node2D
|
||||
var petal_location : Vector2
|
||||
@export var vine_locations : Array[Vector2]
|
||||
@export var bud_resource : PackedScene
|
||||
@onready var grid : Grid = get_tree().get_root().get_node("main/Earth/Grid")
|
||||
|
||||
func draw_vine(pos1 : Vector2, pos2 : Vector2, img_path):
|
||||
var sprite = Sprite2D.new()
|
||||
get_tree().get_root().get_node("main").add_child(sprite)
|
||||
sprite.texture = ResourceLoader.load(img_path)
|
||||
sprite.position = (pos1 + pos2)/2.0
|
||||
sprite.rotation = (pos1 - pos2).angle() + PI/2
|
||||
sprite.scale *= (pos1 - pos2).length() * 1 / sprite.texture.get_width()
|
||||
sprite.scale.x = 3
|
||||
|
||||
func grow_vine_sequence(location1 : Vector2, offset1 : Vector2, location2: Vector2, offset2 : Vector2, num_segments: int, img_path, grow_bud = false):
|
||||
var pos1 = grid.get_world_position(location1, offset1)
|
||||
var pos2 = grid.get_world_position(location2, offset2)
|
||||
var positions = []
|
||||
positions.append(pos1)
|
||||
|
||||
var segment_length = (pos1 - pos2).length() / num_segments
|
||||
var offsets = generate_random_offsets(num_segments, 0.6 * segment_length)
|
||||
for i in range(num_segments - 1):
|
||||
var t = (i + 1) * 1.0/num_segments
|
||||
var center = t * pos2 + (1 - t) * pos1
|
||||
var offset = offsets[i + 1] * (pos2 - pos1).normalized().rotated(PI/2)
|
||||
positions.append(center + offset)
|
||||
positions.append(pos2)
|
||||
for i in range(num_segments):
|
||||
draw_vine(positions[i], positions[i+1], img_path)
|
||||
await get_tree().create_timer(0.2).timeout
|
||||
if grow_bud and location2.y > 0:
|
||||
spawn_bud(location2, offset2)
|
||||
|
||||
func generate_random_offsets(segment_count, max_second_derivative):
|
||||
var differences = []
|
||||
var last_diff = 0
|
||||
for i in range(segment_count):
|
||||
var new_diff = last_diff + randf_range(-max_second_derivative, max_second_derivative)
|
||||
differences.append(new_diff)
|
||||
last_diff = new_diff
|
||||
var sum = 0.0
|
||||
for i in range(segment_count):
|
||||
sum += differences[i]
|
||||
var correction = - sum / segment_count
|
||||
for i in range(segment_count):
|
||||
differences[i] += correction
|
||||
var ret = []
|
||||
var next_val = 0
|
||||
for i in range(segment_count):
|
||||
ret.append(next_val)
|
||||
next_val += differences[i]
|
||||
return ret
|
||||
|
||||
func spawn_bud(location, offset):
|
||||
var bud = bud_resource.instantiate()
|
||||
bud.location = location
|
||||
bud.offset = offset
|
||||
bud.vine = self
|
||||
get_tree().get_root().get_node("main").add_child(bud)
|
||||
Binary file not shown.
|
|
@ -1,6 +1,9 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://b7o82cdfwuqd1"]
|
||||
[gd_scene load_steps=3 format=3 uid="uid://b7o82cdfwuqd1"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://dnxttryo3t3sx" path="res://vine.gd" id="1_3bbo6"]
|
||||
[ext_resource type="Script" uid="uid://dnxttryo3t3sx" path="res://vines_petals/vine.gd" id="1_3bbo6"]
|
||||
[ext_resource type="PackedScene" uid="uid://dhxnae8wbhp3u" path="res://vines_petals/bud.tscn" id="2_r0bsc"]
|
||||
|
||||
[node name="Vine" type="Node2D"]
|
||||
script = ExtResource("1_3bbo6")
|
||||
vine_locations = Array[Vector2]([Vector2(46, 1)])
|
||||
bud_resource = ExtResource("2_r0bsc")
|
||||
|
|
|
|||
Binary file not shown.
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.9 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.9 KiB |
|
|
@ -1,9 +1,9 @@
|
|||
class_name VineNode extends Node2D
|
||||
@onready var grid : Grid = %Grid
|
||||
var grid_position : Vector2
|
||||
var angular_offset : float
|
||||
var height_offset : float
|
||||
var bud : Bud
|
||||
|
||||
@export var vine : Vine
|
||||
@onready var grid : Grid = get_tree().get_root().get_node("main/Earth/Grid")
|
||||
@export var location : Vector2
|
||||
@export var offset : Vector2
|
||||
|
||||
func _ready() -> void:
|
||||
position = grid.
|
||||
position = grid.get_world_position(location, offset)
|
||||
|
|
|
|||
|
|
@ -43,5 +43,6 @@ script = ExtResource("3_2bhor")
|
|||
ground_radius = 3000.0
|
||||
cell_height = 300.0
|
||||
num_collumns = 60
|
||||
debug = true
|
||||
packed_buildings = Array[PackedScene]([ExtResource("4_r4pw8"), ExtResource("4_ml5no"), ExtResource("6_640fc"), ExtResource("7_abvrx"), ExtResource("3_nihcy"), ExtResource("9_ej0af"), ExtResource("10_640fc")])
|
||||
metadata/_custom_type_script = "uid://m3vyyfk8gnma"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue