-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lua
67 lines (54 loc) · 1.74 KB
/
main.lua
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
require "debugger"
local simple_tree = require("examples.simple")
local advanced_tree = require("examples.advanced")
local tree_render = require("LOVElyTree.tree_render")
require "tests.tests"
local camera = require "examples.camera"
local tree
local tree_layour_data
function love.load()
math.randomseed(os.time())
tree = simple_tree()
tree_layour_data = tree_render.layout_tree(tree.root, 10, 10)
love.graphics.setFont(love.graphics.newFont(12))
end
function love.update(dt)
tree:update(dt)
camera.update(dt)
end
function love.draw()
camera.push()
tree_render.render_tree(tree_layour_data)
camera.pop()
love.graphics.setColor(0.5, 0.5, 0.5)
love.graphics.print("1: Simple Behavior Tree | 2: Complex Behavior tree", 10, 20)
love.graphics.print("Controls: AWSD or mouse drag to pan. QE or mouse wheel to zoom", 10,
love.graphics.getHeight() - 20)
local stats = love.graphics.getStats()
local fps = love.timer.getFPS()
love.graphics.print(string.format("FPS: %d\nDraw Calls: %d", fps, stats.drawcalls), 10,
love.graphics.getHeight() - 50)
end
function love.keypressed(key)
if key == "1" then
tree = simple_tree()
tree_layour_data = tree_render.layout_tree(tree.root, 10, 10)
camera.reset()
elseif key == "2" then
tree = advanced_tree()
tree_layour_data = tree_render.layout_tree(tree.root, 10, 10)
camera.reset()
end
end
function love.mousepressed(x, y, button)
camera.mousepressed(x, y, button)
end
function love.mousereleased(x, y, button)
camera.mousereleased(x, y, button)
end
function love.mousemoved(x, y, dx, dy)
camera.mousemoved(x, y, dx, dy)
end
function love.wheelmoved(x, y)
camera.wheel_moved(x, y)
end