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
78
79
80
81
82
83
84
85
86
87
88
|
shader = require("shaders.world")
win = require("window")
hc = require("party.hc.init")
ecs = require("ecs")
world = require("world")
ss = require("shader_shim")
ui = require("ui")
peer = require("router")
server = ui.button(-200,0,100,100, "Server")
co = nil
server.on = () =>
if @co == nil
print("Setting co...")
@co = coroutine.create(() ->
router = peer.Router!
router\initalize!
router
)
button = @
@node\action(() =>
if button.co and coroutine.status(button.co) ~= "dead"
succ, val = coroutine.resume(button.co)
if not succ
error(debug.traceback(button.co,val))
if type(val) == "string"
button.text.text = val
else
router = val
world.router = router
)
client.on = () =>
textbox = ui.textbox(200,100,100,32, "Serverid")
client = ui.button(200,0,100,100, "Client")
test_sprite = am.translate(0,0) ^ am.scale(20) ^ am.sprite("BRY\nYYY\nBBB")
ui.node\prepend(test_sprite)
world_cache = {
}
print("Before setting world level:", world)
world.level = {
graphics:{}
entities:{}
graphic_world: hc.new(5)
physics_world: hc.new(1)
}
world.level.entities[0] = ecs.Entity("World",{
ecs.NetworkedComponent("net",{seed: "1234567"}),
ecs.GraphicsComponent("graphics",{
node: ss.world\append(
am.depth_test("less")\append(
am.cull_face("front")\append(
am.bind({})\append(
am.draw("triangles")
))))
}),
ecs.PhysicsComponent("physics",{
shape: world.level.physics_world\rectangle(0,0,100,100)
}),
ecs.ScriptComponent("script",{script: "prefab.worldgen"})
})
world.level.entities[1] = ecs.Entity("LocalPlayer",{
ecs.NetworkedComponent({
name: ""
position: {0,0}
velocity: {0,0}
acceleration: {0,0}
lasttime: 0
}),
ecs.GraphicsComponent("graphics",{
node: ss.world\append(
am.depth_test("less")\append(
am.cull_face("front")\append(
am.bind({})\append(
am.draw("triangles")
))))
}),
ecs.PhysicsComponent("physics",{shape: world.level.physics_world\circle(0,0,0.5)}),
ecs.ScriptComponent("script",{script: "player"})
})
|