world = require("world") sprites = require("world.sprites") ecs = require("ecs") win = require("window") colors = require("color") class BobberGraphicsComponent extends world.GraphicsComponent @loctbl = { {-1,-1} {-1,1} {1,1} {1,1} {1,-1} {-1,-1} } buf_size: () => 6 populate_buf: (geom_view, normal_view, offset) => @buf = geom_view h = 0.1 uv = sprites.bobber_normal utbl = { [-1]: {uv.s1, uv.t1} [1]: {uv.s2, uv.t2} } z = -0.1 print("Bobber created at", @properties.pos) for i = 1,6 loctbl = @@loctbl[i] geom_view[i] = vec3(@@loctbl[i][1] * h, @@loctbl[i][2] * h, z) + vec3(@properties.pos.x, @properties.pos.y, z) normal_view[i] = vec2(utbl[@@loctbl[i][1]][1], utbl[@@loctbl[i][2]][2]) join: (entity) => super(entity) aspect = win.width / win.height program = @.node("use_program") graphic = entity\get("bobber") @node\remove(program) @node\append(am.blend("alpha")\append(program)) bind = @.node("bind") [[ for name, color in pairs(colors.am_lake_color) bind[name] = color ]] bind.water = 1 @ent = entity @last_bubble = am.current_time! comp = @ class BobberPhysicsComponent extends world.PhysicsComponent new: (name, properties, shape, args) => super(name, properties) join: (entity) => super(entity) @gc = entity\get("graphics") class Bobber extends ecs.Entity new: (name, position) => c = { bobber: BobberGraphicsComponent("bobber",{pos: position}) pc: world.PhysicsComponent("pc",{},"circle", {position.x, position.y, 0.1}) } super(name, c) check: () => --print("Bobber is looking for fish") bp = @get("pc") for other, _ in pairs(bp\collisions!) --print("Found entity in collisions:", other) if other.component and other.component.entity --print("And it's component.entity is:", other.component.entity) @which = other.component.entity return true return false {:BobberGraphicsComponent, :BobberPhysicsComponent, :Bobber}