class_name PlatformerActorController extends ActorController ## Controls an actor's movement in the game world ## @remarks ## Actors are players, enemies and items in the game world. Each actor can perform ## moves (see the Move class) which are either atomic tasks ("walk", "jump") combined ## into complex behaviors by AI or infinites task that respond to state changes, ## used by items and user-controller actors. # ----------------------------------------------------------------------------------------------- # ## Path to the ability definition component export(NodePath) var actor_abilities_path : NodePath = "../Abilities" # Path to the repository providing the actor's moves #export(NodePath) var move_repository_path : NodePath = "../Moves" # ----------------------------------------------------------------------------------------------- # ## Ability definition component that specified the speed and possible actions of the actor ## @remarks ## The ability definition is optional but a default instance will be created if ## none is provided at design time. var actor_abilities : PlatformerActorAbilities \ setget _set_actor_abilities, _get_actor_abilities ## Number of jumps the actor has performed without touching the ground var consecutive_jump_count : int = 0 # ----------------------------------------------------------------------------------------------- # ## Whether the lookup for the ability definition component has taken place already ## @remarks ## Used to avoid looking it up over and over in move-derived classes var _actor_abilities_searched : bool # ---------------------------------------------------------------------------------------------- # ## Called every physics frame to move objects and the state of the game ## @param delta_seconds Elapsed time since the previous frame func _physics_process(delta_seconds) -> void: if _actor_physics_searched: if actor_physics != null: actor_physics.velocity.z = 0.0 if _rigid_body_searched: if rigid_body != null: rigid_body.linear_velocity.z = 0.0 # Good/bad? Velocity may have been present and cause minimal drift # setting position requires us to know the actor's root node and # prevents 2.5D platformers that move the actor on different Z lanes #position.z = 0.0 # ---------------------------------------------------------------------------------------------- # ## Retrieves the actor physics component when the property is read from ## @returns The actor physics component used by the actor, if any func _get_actor_abilities() -> PlatformerActorAbilities: if not _actor_abilities_searched: actor_abilities = get_node(actor_abilities_path) as PlatformerActorAbilities _actor_abilities_searched = true return actor_abilities # ----------------------------------------------------------------------------------------------- # ## Complains if the user tries to directly assign the actor physics component ## @param new_actor_physics_component New component that will not be assigned func _set_actor_abilities( new_actor_abilities : PlatformerActorAbilities ) -> void: if new_actor_abilities != actor_abilities: printerr("ERROR: The ability definition component cannot be assigned to")