Events
app.subscribe(Event::Closed) { puts "window closed!"; exit(0) }class PlayerDeadEvent < Scar::Event::Event # Scar::Event is a module containing all builtin events!
property :pos
def initialize(@pos : Scar::Vec); end
end
class SomeSystem < Scar::System
include Scar
def init(app : App, space : Space)
app.subscribe(PlayerDeadEvent) { |e : PlayerDeadEvent | puts "Player died at #{e.pos.x} | #{e.pos.y}"}
end
end
class PlayerSystem < Scar::System
include Scar
def update(app : App, space : Space, dt)
pl = space["player"]
plc = pl[PlayerComponent]
app.broadcast(PlayerDeadEvent.new pl.position) if plc.health <= 0
end
endLast updated