Shooter

Node creating a level of abstraction in order to fire projectiles.

Inherits : Node2D

Signals

start_attack

Signal emitted when the entity can start attacking (after stop moving for example).

Emitted by : set_can_shoot() Received by : _on_start_attack_timeout()

stop_attack

Signal emitted when the entity should stop attacking (when running for example).

Emitted by : set_can_shoot() Received by : _on_stop_attack_timeout()

Description

This Node acts as a layer. It’s a layer above the player, and his job is to instance the projectiles.

Such a trick is needed, because if we simply instancied the projectile in the player Node, projectiles would be childrens of the player, and whenever the player move, the projectiles would move also. We need the position of the player and the projectiles to be independant.

This Node also handle the timer for the attack speed.

Properties description

entity

Type WeakRef
Default null

Reference to shooting Entity.

projectile

Type Projectile
Default null

Non-Instancied Projectile to shoot. The Shooter will instanciate a new one every time it fires.

can_shoot

Type bool
Default true

State of the Shooter : if it can shoot (not running for example), it is true, else false.

attack_speed

Type float

Attack speed to use to fire projectiles.

hit_n_run

Type bool
Default false
If true, allow the Entity to attack while moving.
This is false for the player for example.

Methods description

init(shooting_entity, projectile_to_shoot, attck_spd=1, hit_run=false)

Arguments

shooting_entity
Set the shooting entity.
projectile_to_shoot
Non-instancied projectile to use when shooting.
attck_spd
Set the attack_speed.
hit_run
Set the hit_n_run.

Method to initialize the object with the value needed.

_ready()

This function simply call the set_can_shoot() function at startup time, in order to send the signal.

set_can_shoot(cs)

Arguments

cs
Bool indicating if the player can shoot or not.
This method change the can_shoot property.
If the can_shoot is set to true, start_attack signal is emitted. Otherwise, stop_attack is emitted.

Emitted signals

start_attack
This signal is emitted if can_shoot is set to true through this method.
stop_attack
This signal is emitted if can_shoot is set to false through this method.

_on_start_attack_timeout(collider)

Method called when start_attack signal is emitted.
It will call the method _on_Recharging_timeout() and start the timer according to attack_speed for the next projectile.

Receives signals

start_attack
This signal is emitted when it’s time to shoot.

_on_stop_attack_timeout()

Method called when stop_attack signal is emitted.
It will interrupt the timer of attack_speed and call the Entity method to potentially interrupt other things such as animations.

Receives signals

stop_attack
This signal is emitted when shooting is interrupted.

_on_Recharging_timeout()

Main timer, used for timing every time a projectile is fired, based on attack_speed.

If entity exist, it instanciate a new projectile and fire it.
If entity does not exist anymore (may be killed), it does nothing until the last fired projectile is freed (because if we free before, the child projectile will also be freed).

Receives signals

timeout
This signal is emitted when the timer (that waited for some time based on attack_speed) ends.

_on_immobile_timeout()

Method called when signal immobile is emitted.
It simply set can_shoot to true if it was false.

Receives signals

immobile
This signal is emitted when the entity stopped moving.

_on_running_timeout()

Method called when signal running is emitted.
It simply set can_shoot to false if it was true.

Receives signals

running
This signal is emitted when the entity started moving.