Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@ func disconnect_timing_scheduler() -> void:
func play_audio() -> void:
# audio_stream.playing = true
if audio_stream_2d:
print("play aduio")
audio_stream_2d.playing = true
pass

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ func _request_persist_behavior_context() -> Array[ProjectileEngine.BehaviorConte
ProjectileEngine.BehaviorContext.ARRAY_VARIABLE
]

@export var piercing_count : int = 3
@export var pierce_area : bool = false
@export_flags_2d_physics var pierce_area_layer : int = 0
@export var pierce_body : bool = false
@export_flags_2d_physics var pierce_body_layer : int = 0
@export var piercing_count: int = 3
@export var pierce_area: bool = false
@export_flags_2d_physics var pierce_area_layer: int = 0
@export var pierce_body: bool = false
@export_flags_2d_physics var pierce_body_layer: int = 0


var _variable_array : Array
var _behavior_variable_piercing : BehaviorVariablePiercing
var _should_piercing : bool = false
var _variable_array: Array
var _behavior_variable_piercing: BehaviorVariablePiercing
var _should_piercing: bool = false

var _piercing_behavior_values : Dictionary
var _piercing_behavior_values: Dictionary

## Processes the piercing behavior and returns whether piercing should occur
## Returns bool: true if projectile should pierce, false if it should be stopped/destroyed
Expand Down Expand Up @@ -123,8 +123,9 @@ func process_behavior(_value, _context: Dictionary) -> Dictionary:
else:
_behavior_variable_piercing.is_overlap_piercing = false

elif _behavior_owner is ProjectileInstance2D:
var _projectile_updater : ProjectileUpdater2D = _behavior_owner.projectile_updater
if _behavior_owner is ProjectileInstance2D:
var _projectile_updater: ProjectileUpdater2D = _behavior_owner.projectile_updater
_behavior_variable_piercing.is_overlap_piercing = false
if pierce_area:
if _projectile_updater.has_overlapping_areas(_behavior_owner.area_index):
for _overlap_area in _projectile_updater.get_overlapping_areas(_behavior_owner.area_index):
Expand All @@ -141,23 +142,19 @@ func process_behavior(_value, _context: Dictionary) -> Dictionary:
_behavior_variable_piercing.is_overlap_piercing = true
_behavior_variable_piercing.pierced_targets.append(_overlap_area)

if piercing_count == 1:
_behavior_variable_piercing.is_piercing_just_done = true
elif _behavior_variable_piercing.current_piercing_count < piercing_count - 1:
if _behavior_variable_piercing.current_piercing_count <= piercing_count:
_behavior_variable_piercing.current_piercing_count += 1
else:

if _behavior_variable_piercing.current_piercing_count > piercing_count:
_behavior_variable_piercing.is_piercing_just_done = true
else:
_behavior_variable_piercing.is_overlap_piercing = false

if pierce_body:
if _projectile_updater.has_overlapping_bodies(_behavior_owner.area_index):
for _overlap_body in _projectile_updater.get_overlapping_bodies(_behavior_owner.area_index):
if not _overlap_body.collision_layer & _projectile_updater.projectile_collision_mask:
continue
if _behavior_variable_piercing.pierced_targets.has(_overlap_body):
continue
if not _overlap_body.collision_layer & pierce_area_layer:
if not _overlap_body.collision_layer & pierce_body_layer:
continue

_should_piercing = true
Expand All @@ -166,13 +163,8 @@ func process_behavior(_value, _context: Dictionary) -> Dictionary:
_behavior_variable_piercing.is_overlap_piercing = true
_behavior_variable_piercing.pierced_targets.append(_overlap_body)

if piercing_count == 1:
_behavior_variable_piercing.is_piercing_just_done = true
elif _behavior_variable_piercing.current_piercing_count < piercing_count - 1:
if _behavior_variable_piercing.current_piercing_count <= piercing_count:
_behavior_variable_piercing.current_piercing_count += 1
else:
if _behavior_variable_piercing.current_piercing_count > piercing_count:
_behavior_variable_piercing.is_piercing_just_done = true
else:
_behavior_variable_piercing.is_overlap_piercing = false

return _piercing_behavior_values
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,18 @@ class_name ProjectileDestroyCollision
@export var destroy_on_body_collide: bool = true

## Wait for Piercing is done before destroy
@export var wait_projectile_piercing : bool = false
@export var wait_projectile_piercing: bool = false
## Wait for Boucing is done before destroy
@export var wait_projectile_bouncing : bool = false
@export var wait_projectile_bouncing: bool = false

var _projectile_updater: ProjectileUpdater2D

var _behavior_variable_piercing: BehaviorVariablePiercing
var _behavior_variable_bouncing: BehaviorVariableBouncingReflect

var _overlap_area_collision_layer: int
var _overlap_body_collision_layer: int

var _behavior_variable_piercing : BehaviorVariablePiercing
var _behavior_variable_bouncing : BehaviorVariableBouncingReflect

func _request_behavior_context() -> Array[ProjectileEngine.BehaviorContext]:
return [
Expand All @@ -30,7 +36,6 @@ func _request_persist_behavior_context() -> Array[ProjectileEngine.BehaviorConte

## Processes collision-based destroy behavior
func process_behavior(_value, _context: Dictionary) -> bool:

if !destroy_on_area_collide and !destroy_on_body_collide:
return false

Expand All @@ -43,6 +48,8 @@ func process_behavior(_value, _context: Dictionary) -> bool:
var _behavior_owner = _context.get(ProjectileEngine.BehaviorContext.BEHAVIOR_OWNER)
if !_behavior_owner:
return false
if !_projectile_updater:
_projectile_updater = _behavior_owner.projectile_updater

if _behavior_owner is Projectile2D:
if !_behavior_owner.monitorable or !_behavior_owner.monitoring:
Expand Down Expand Up @@ -125,19 +132,14 @@ func process_behavior(_value, _context: Dictionary) -> bool:
return false
return true

elif _behavior_owner is ProjectileInstance2D:
var _projectile_updater : ProjectileUpdater2D = _behavior_owner.projectile_updater
if _behavior_owner is ProjectileInstance2D:
if destroy_on_area_collide:
if _projectile_updater.has_overlapping_areas(_behavior_owner.area_index):
# print("ProjectileEngine ProjectileEngine: ", ProjectileEngine)
for _overlap_area in _projectile_updater.get_overlapping_areas(_behavior_owner.area_index):
if !_overlap_area:
_projectile_updater.get_overlapping_areas(_behavior_owner.area_index).erase(_overlap_area)
return true
# print("ProjectileEngine ProjectileEngine: ", ProjectileEngine)

var _overlap_area_collision_layer : int = ProjectileEngine.get_collider_collision_layer(_overlap_area)

continue
_overlap_area_collision_layer = ProjectileEngine.get_collider_collision_layer(_overlap_area)
if not _overlap_area_collision_layer & _projectile_updater.projectile_collision_mask:
continue

Expand Down Expand Up @@ -177,11 +179,15 @@ func process_behavior(_value, _context: Dictionary) -> bool:
if destroy_on_body_collide:
if _projectile_updater.has_overlapping_bodies(_behavior_owner.area_index):
for _overlap_body in _projectile_updater.get_overlapping_bodies(_behavior_owner.area_index):
var _overlap_body_collision_layer : int = ProjectileEngine.get_collider_collision_layer(_overlap_body)
if !_overlap_body:
_projectile_updater.get_overlapping_bodies(_behavior_owner.body_index).erase(_overlap_body)
continue
_overlap_body_collision_layer = ProjectileEngine.get_collider_collision_layer(_overlap_body)
if not _overlap_body_collision_layer & _projectile_updater.projectile_collision_mask:
continue

if wait_projectile_piercing:

var _variable_array := _context.get(ProjectileEngine.BehaviorContext.ARRAY_VARIABLE)
if _variable_array.size() <= 0:
_behavior_variable_piercing = null
Expand All @@ -196,23 +202,24 @@ func process_behavior(_value, _context: Dictionary) -> bool:
if _behavior_variable_piercing.is_overlap_piercing == false and _behavior_variable_piercing.is_piercing_done:
return true
return false

if wait_projectile_bouncing:
var _variable_array := _context.get(ProjectileEngine.BehaviorContext.ARRAY_VARIABLE)
if _variable_array.size() <= 0:
_behavior_variable_bouncing = null
return false
for _variable in _variable_array:
if _variable is BehaviorVariableBouncingReflect:
_behavior_variable_bouncing = _variable
break
_behavior_variable_bouncing = null
if !_behavior_variable_bouncing:
return false
if _behavior_variable_bouncing.is_bouncing == false and _behavior_variable_bouncing.is_bouncing_done:
return true
return false


return true


# if wait_projectile_bouncing:
# var _variable_array := _context.get(ProjectileEngine.BehaviorContext.ARRAY_VARIABLE)
# if _variable_array.size() <= 0:
# _behavior_variable_bouncing = null
# return false
# for _variable in _variable_array:
# if _variable is BehaviorVariableBouncingReflect:
# _behavior_variable_bouncing = _variable
# break
# _behavior_variable_bouncing = null
# if !_behavior_variable_bouncing:
# return false
# if _behavior_variable_bouncing.is_bouncing == false and _behavior_variable_bouncing.is_bouncing_done:
# return true
# return false

return false
Loading
Loading