Common Attacks examples

Here is a collection of regularly requested Attacks and their implementation in All Projectiles.

The list will be continuously updated as requested.


Single Charge on Start

extends  Node2D

@export var separation: int = 30

@onready var projectile_manager: ProjectileManager2D = $ProjectileManager2D

@onready var bow: Sprite2D = $Bow
@onready var animation_player: AnimationPlayer = $AnimationPlayer


func _ready() -> void:
	animation_player.play("idle")
	projectile_manager.get_attack(0).set_on_charge_enter(on_charge_enter).set_on_charge_exit(on_charge_exit).set_on_main_exit(on_main_exit)


func _process(_delta: float) -> void:
	var direction: Vector2 = (get_global_mouse_position() - position).normalized()
	bow.position = direction * separation
	bow.rotation = direction.angle()

	projectile_manager.position = bow.position
	projectile_manager.rotation = bow.rotation

	if (Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT)):
		projectile_manager.request_execution(0, 0, position + (direction * separation), get_global_mouse_position())


func on_main_exit(attack: Attack2D) -> void:
	if (attack.is_under_uninterrupted_request):
		attack.change_state(attack.AttackState.ATTACK_MAIN)
	else:
		attack.main_exit()


func on_charge_enter(attack: Attack2D) -> void:
	animation_player.play("charge")
	attack.charge_enter()

func on_charge_exit(attack: Attack2D) -> void:
	animation_player.play("idle")
	attack.charge_exit()