1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
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}
|