basic ECS spawner
This commit is contained in:
25
GECS/systems/s_movement.gd
Normal file
25
GECS/systems/s_movement.gd
Normal file
@@ -0,0 +1,25 @@
|
||||
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()
|
||||
Reference in New Issue
Block a user