Systems

Systems are where all game logic should happen. Systems move entities, react to input, draw text and so on.

The Scar::System class is, just like Scar::Component, an abstract class but it declares three overridable methods: init, update and render. init should contain initialization logic, update should contain game logic while render should contain drawing logic. The last two get the current app, the current space and the delta time as parameters, init does not get a delta time.

There are many builtin systems available, you can find them in the 'Builtin Systems' chapter of this book.

Example

class PlayerSystem < Scar::System
    include Scar
    
    def update(app : App, space: Space, dt)
        space.each_with Components::PlayerComponent do |ent, player|
            ent.position.x += player.health * dt            
        end
    end
end

Last updated