Fixed vines spawning inactively at some point
This commit is contained in:
parent
1ea01c30d6
commit
248b1915b6
4 changed files with 17 additions and 20 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
class_name GridNode extends Node2D
|
class_name GridNode extends Node2D
|
||||||
|
|
||||||
@export var vine : Vine
|
# Setting location and offset automatically adjusts position
|
||||||
@export var location : Vector2 :
|
@export var location : Vector2 :
|
||||||
set(new_loc):
|
set(new_loc):
|
||||||
location = Global.vec_mod(new_loc, Grid.num_collumns, true)
|
location = Global.vec_mod(new_loc, Grid.num_collumns, true)
|
||||||
|
|
@ -11,32 +11,23 @@ class_name GridNode extends Node2D
|
||||||
update_position()
|
update_position()
|
||||||
@export var depth : int
|
@export var depth : int
|
||||||
|
|
||||||
func _get(property: StringName) -> Variant:
|
# Setting the global position automatically adjusts location and offset
|
||||||
if property == "position":
|
|
||||||
return position
|
|
||||||
if property == "global_position":
|
|
||||||
return global_position
|
|
||||||
return null
|
|
||||||
|
|
||||||
func _set(property: StringName, value: Variant) -> bool:
|
func _set(property: StringName, value: Variant) -> bool:
|
||||||
if property == "global_position":
|
if property == "global_position":
|
||||||
location = Grid.get_location_from_world_pos(value)
|
location = Grid.get_location_from_world_pos(value)
|
||||||
offset = Grid.get_offset_from_world_pos(value)
|
offset = Grid.get_offset_from_world_pos(value)
|
||||||
update_position()
|
update_position()
|
||||||
return true
|
return true
|
||||||
if property == "position":
|
|
||||||
update_position()
|
|
||||||
return false
|
|
||||||
return false
|
return false
|
||||||
|
|
||||||
|
# Generates position from location and offset
|
||||||
func update_position():
|
func update_position():
|
||||||
global_position = Grid.get_world_position(location, offset)
|
global_position = Grid.get_world_position(location, offset)
|
||||||
|
|
||||||
func _enter_grid() -> void:
|
func _enter_grid() -> void:
|
||||||
update_position()
|
update_position()
|
||||||
|
|
||||||
func _init(_vine = null, _location = Vector2.ZERO, _offset = Vector2.ZERO, _depth = 0):
|
# Constructor for Grid Nodes
|
||||||
vine = _vine
|
func _init(_location = Vector2.ZERO, _offset = Vector2.ZERO):
|
||||||
location = _location
|
location = _location
|
||||||
offset = _offset
|
offset = _offset
|
||||||
depth = _depth
|
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,18 @@
|
||||||
class_name Bud extends GridNode
|
class_name Bud extends GridNode
|
||||||
signal opened
|
signal opened
|
||||||
var img_path
|
var img_path
|
||||||
|
@export var vine : Vine
|
||||||
|
|
||||||
# Triggers when a bud is hit. Spreads the vine, then removes the bud
|
# Triggers when a bud is hit. Spreads the vine, then removes the bud
|
||||||
func _on_opened():
|
func _on_opened():
|
||||||
|
$EnemyHurtbox.monitorable = false
|
||||||
|
$EnemyHurtbox.monitoring = false
|
||||||
$AnimatedSprite2D.play("open")
|
$AnimatedSprite2D.play("open")
|
||||||
opened.emit()
|
opened.emit()
|
||||||
spread()
|
spread()
|
||||||
await $AnimatedSprite2D.animation_finished
|
await $AnimatedSprite2D.animation_finished
|
||||||
queue_free()
|
for child in get_children():
|
||||||
|
queue_free()
|
||||||
|
|
||||||
# Spread in all directions where the given vine is not yet present
|
# Spread in all directions where the given vine is not yet present
|
||||||
func spread():
|
func spread():
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
class_name Petal extends GridNode
|
class_name Petal extends GridNode
|
||||||
|
@export var vine : Vine
|
||||||
@export var vine_resource : PackedScene
|
@export var vine_resource : PackedScene
|
||||||
var activated = false
|
var activated = false
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ var status_params : Dictionary = {}
|
||||||
# When max depth is reached, everything is active from then on.
|
# When max depth is reached, everything is active from then on.
|
||||||
var active_depth = -1
|
var active_depth = -1
|
||||||
var fully_active = false
|
var fully_active = false
|
||||||
var max_depth = 50
|
var max_depth = 10
|
||||||
|
|
||||||
# Array containings lists of sprites, using their depths as index
|
# Array containings lists of sprites, using their depths as index
|
||||||
var vine_data = []
|
var vine_data = []
|
||||||
|
|
@ -44,7 +44,7 @@ var vine_end_data = []
|
||||||
func draw_vine(pos1 : Vector2, pos2 : Vector2, depth : int):
|
func draw_vine(pos1 : Vector2, pos2 : Vector2, depth : int):
|
||||||
var sprite = Sprite2D.new()
|
var sprite = Sprite2D.new()
|
||||||
get_tree().get_root().get_node("main").add_child(sprite)
|
get_tree().get_root().get_node("main").add_child(sprite)
|
||||||
if active_depth >= depth:
|
if active_depth >= depth or fully_active:
|
||||||
sprite.texture = ResourceLoader.load(img_path_active)
|
sprite.texture = ResourceLoader.load(img_path_active)
|
||||||
else:
|
else:
|
||||||
sprite.texture = ResourceLoader.load(img_path_inactive)
|
sprite.texture = ResourceLoader.load(img_path_inactive)
|
||||||
|
|
@ -86,7 +86,7 @@ func grow_vine_sequence(start : GridNode, target: GridNode, grow_bud = false, qu
|
||||||
if not quick_spawn:
|
if not quick_spawn:
|
||||||
await get_tree().create_timer(0.2).timeout
|
await get_tree().create_timer(0.2).timeout
|
||||||
|
|
||||||
if active_depth >= depth + num_segments:
|
if active_depth >= depth + num_segments or fully_active:
|
||||||
if grow_bud and target.location.y > 0 and target.location.y <= Grid.max_bud_height:
|
if grow_bud and target.location.y > 0 and target.location.y <= Grid.max_bud_height:
|
||||||
spawn_bud(target.location, target.offset, depth + num_segments)
|
spawn_bud(target.location, target.offset, depth + num_segments)
|
||||||
else:
|
else:
|
||||||
|
|
@ -142,6 +142,7 @@ func update_active_depth():
|
||||||
if data.depth == active_depth:
|
if data.depth == active_depth:
|
||||||
spawn_bud(data.location, data.offset, data.depth)
|
spawn_bud(data.location, data.offset, data.depth)
|
||||||
update_active_depth()
|
update_active_depth()
|
||||||
|
else: fully_active = true
|
||||||
|
|
||||||
func _enter_tree() -> void:
|
func _enter_tree() -> void:
|
||||||
var data : Dictionary = status_data.pick_random()
|
var data : Dictionary = status_data.pick_random()
|
||||||
|
|
@ -152,7 +153,7 @@ func _enter_tree() -> void:
|
||||||
|
|
||||||
func random_vine_node_at(location):
|
func random_vine_node_at(location):
|
||||||
var offset = random_offset()
|
var offset = random_offset()
|
||||||
return GridNode.new(self, location, offset)
|
return GridNode.new(location, offset)
|
||||||
|
|
||||||
func init_random():
|
func init_random():
|
||||||
Grid.add_vine_to(self, petal.location)
|
Grid.add_vine_to(self, petal.location)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue