class_name MovementSystem
extends System

func query():
	# Find all entities that have both transform and velocity
	return q.with_all([C_Velocity])

func process(entities: Array[Entity], _components: Array, delta: float):
	for entity in entities:
		var c_velocity = entity.get_component(C_Velocity) as C_Velocity
		
		if entity.velocity.length() == 0:
			entity.velocity = c_velocity.velocity
			
		# Add the gravity.
		if not entity.is_on_floor():
			entity.velocity += entity.get_gravity() * delta
			
		# Bounce off screen edges (simple example)
		if entity.global_position.x > 10 && entity.velocity.x > 0:
			entity.velocity = -c_velocity.velocity
		if  entity.global_position.x < -10 && entity.velocity.x < 0:
			entity.velocity = c_velocity.velocity
			
		entity.move_and_slide()
