local imgui = require("imgui") local Action = require("node.action") local Condition = require("node.condition") local Sprite = require("sprite") local player = Sprite("Face.png",64, 64) local player2 = Sprite("Face2.png",240, 64) local grid_tile = love.graphics.newImage("grid.png") grid_tile:setFilter("nearest") local function coro_test (action) for i=0,100 do action.progress = i/100 coroutine.yield( ) end end local function coro_test_longer (action) for i=0,400 do action.progress = i/400 coroutine.yield( ) end end local function sign(x) if x<0 then return -1 elseif x>0 then return 1 else return 0 end end function Move(player, dx, dy) local function move(action) local start_x = player.x local start_y = player.y local target_x = player.x + dx local target_y = player.y + dy local pdx = sign(target_x - start_x) local pdy = sign(target_y - start_y) repeat coroutine.yield() local walked_delta_x = math.abs(player.x - start_x) local walked_delta_y = math.abs(player.y - start_y) if walked_delta_x > math.abs(dx) then player.x = target_x walked_delta_x = dx end if walked_delta_y > math.abs(dy) then player.y = target_y walked_delta_y = dy end local px = dx ~= 0 and walked_delta_x/math.abs(dx) or 0 local py = dy ~= 0 and walked_delta_y/math.abs(dy) or 0 action.progress = math.max(px, py) local pdx = sign(target_x - player.x) local pdy = sign(target_y - player.y) player.dx = pdx * 60 player.dy = pdy * 60 until player.x == target_x and player.y == target_y player.dx = 0 player.dy = 0 end local action = Action(coroutine.create(move)) action.name = "Move ("..dx..";"..dy..") pixels" return action end function Wait(time) local function wait(action) local dt = 0 while dt <= time do coroutine.yield() dt = dt + love.timer.getDelta() action.progress = dt / time end end local action = Action(coroutine.create(wait)) action.name = "Wait "..time.." seconds" return action end local array = { Move(player, 0, 72), Wait(1), Move(player, 0, -72), Wait(1), Condition("and", {Move(player, 0, 72), Move(player2, 0, 72)}), Wait(1), Condition("and", {Move(player, 0, -72), Move(player2, 0, -72)}), Wait(1), Condition("and", {Move(player, 45, 0), Move(player2, -45, 0)}), Wait(0.5), Condition("and", {Move(player, 0, 72), Move(player2, 0, 72)}), Wait(0.5), Condition("and", {Move(player, 0, -72), Move(player2, 0, -72)}), Wait(0.5), Condition("and", {Move(player, -45, 0), Move(player2, 45, 0)}), --[[ Action(coroutine.create( coro_test )), Action(coroutine.create( coro_test )), Action(coroutine.create( coro_test )), Condition("and", {Action(coroutine.create( coro_test )), Action(coroutine.create( coro_test_longer ))}), Condition("and", {Action(), Action(coroutine.create(function() coroutine.yield() end))}), Condition("and", {Action(coroutine.create(function() coroutine.yield() end)), Action(coroutine.create(function() coroutine.yield() end))}), Condition("or", {Action(coroutine.create( coro_test )), Action(coroutine.create( coro_test_longer ))}), Condition("or", {Action(), Action(coroutine.create(function() coroutine.yield() end))}), Condition("or", {Action(coroutine.create(function() coroutine.yield() end)), Action(coroutine.create(function() coroutine.yield() end))}) ]] } for i,node in ipairs(array) do node.id = i end local selected_node = nil local started = false function not_in(v,t) for k,e in ipairs(t) do if v == e then return false end end return true end function draw_array() imgui.Begin("Array") if imgui.Button("START!") then started = true end for i,node in ipairs(array) do local current_selected_node = node:draw_debug() if current_selected_node then selected_node = current_selected_node end end if selected_node then imgui.Separator() imgui.Text(selected_node.name) imgui.Text(selected_node.id) imgui.Text("Is finished "..tostring(selected_node:is_finished())) end imgui.Separator() imgui.Text("--Player--") imgui.Text("X: "..player.x) imgui.Text("Y: "..player.y) imgui.End() end local iui_state = { array={cbk = draw_array, show=true} } function love.load() end function love.update(dt) imgui.NewFrame() if started then for _,node in ipairs(array) do node:update(dt) if not node:is_finished() then break end end end player:update(dt) player2:update(dt) end function love.draw() for x=0,love.graphics.getWidth(), grid_tile:getWidth() do for y=0,love.graphics.getHeight(), grid_tile:getHeight() do love.graphics.draw(grid_tile, x, y, 0, 1, 1) end end player:draw() player2:draw() if imgui.BeginMainMenuBar() then if imgui.BeginMenu("Test") then for k,v in pairs(iui_state) do if imgui.MenuItem(k, nil, v.show) then iui_state[k].show = not iui_state[k].show end end imgui.EndMenu() end end imgui.EndMainMenuBar() for k,v in pairs(iui_state) do if v.show then v.cbk() end end imgui.Render() end function love.quit() imgui.ShutDown() end -- -- User inputs -- function love.textinput(t) imgui.TextInput(t) if not imgui.GetWantCaptureKeyboard() then -- Pass event to the game end end function love.keypressed(key) imgui.KeyPressed(key) if not imgui.GetWantCaptureKeyboard() then -- Pass event to the game end end function love.keyreleased(key) imgui.KeyReleased(key) if not imgui.GetWantCaptureKeyboard() then -- Pass event to the game end end function love.mousemoved(x, y) imgui.MouseMoved(x, y) if not imgui.GetWantCaptureMouse() then -- Pass event to the game end end function love.mousepressed(x, y, button) imgui.MousePressed(button) if not imgui.GetWantCaptureMouse() then -- Pass event to the game end end function love.mousereleased(x, y, button) imgui.MouseReleased(button) if not imgui.GetWantCaptureMouse() then -- Pass event to the game end end function love.wheelmoved(x, y) imgui.WheelMoved(y) if not imgui.GetWantCaptureMouse() then -- Pass event to the game end end