import "luxe: io" for IO import "luxe: world" for World, Entity, Modifiers, ModifierSystem, Transform, Sprite import "math/vector" for Vector import "math/util" for Util //User facing API //This is what the user of your modifier will interact with class Human { static create(entity) { Modifiers.create(This, entity) } static destroy(entity) { Modifiers.destroy(This, entity) } static has(entity) { Modifiers.has(This, entity) } static set_color(entity, color){ var data = Modifiers.get(This, entity) data.color = color if(Sprite.has(entity)){ Sprite.set_color(entity, color.r, color.g, color.b, color.a) } } } //Human //Your modifier system implementation. //This speaks to the engine and your user facing API //to do the actual work. You'll get notified when things change //in the world and respond to them here. class HumanSystem is ModifierSystem { player_start{[26, 90]} player_size{[10, 12]} construct new() { //called when your system is first created. } init(world) { _world = world //called when your modifier is created in a world _material = Util.material_from_image_path("assets/wip/Human") } destroy() { //called when your modifier is removed from a world } attach(entity, data) { //called when attached to an entity update() } detach(entity, data) { //called when detached from an entity, like on destroy update() } tick(delta) { //called usually once every frame. //called when the world that this modifier lives in, is ticked each {|entity, data| System.print("%(Transform.get_pos(entity))") } } //tick update(){ var i = 0 var size = Vector.new(player_size) var start = Vector.new(player_start) + size / 2 each {|entity, data| if(!data.active){ Transform.destroy(entity) Sprite.destroy(entity) return } var pos = start pos.x = pos.x + size.x * i if(!Transform.has(entity)){ Transform.create(entity) } if(!Sprite.has(entity)){ Sprite.create(entity, _material, 10, 12) Sprite.set_color(entity, data.color.r, data.color.g, data.color.b, 1) } Transform.set_pos(entity, pos.x, pos.y) i = i + 1 } } } //HumanSystem var Modifier = HumanSystem //required