ai won't jump if it sees tall ledge that can't jump over

Former-commit-id: c74b12206547838c72301d3d2223a98c9098687d
Former-commit-id: a1f7c29cc42758f92c202d20d28e47820546c900
This commit is contained in:
Song Minjae
2017-01-20 01:56:29 +09:00
parent 02f38eab3c
commit 5db3aadaf4

View File

@@ -5,8 +5,9 @@ timeCounter = 0
countMax = 0 countMax = 0
moveMode = math.random() >= 0.5 and "left" or "right" moveMode = math.random() >= 0.5 and "left" or "right"
currentMode = "move" currentMode = "move"
jumpheight = 6 -- lol
local function generateCountMax() function generateCountMax()
local function generateTurn() local function generateTurn()
return 4600 + 1250 * math.random() return 4600 + 1250 * math.random()
end end
@@ -18,33 +19,38 @@ local function generateCountMax()
return (currentMode == "move") and generateWalk() or generateTurn() return (currentMode == "move") and generateWalk() or generateTurn()
end end
local function moveToDirection(delta) function moveToDirection(delta)
local tiles = ai.getNearbyTiles(1) local tiles = ai.getNearbyTiles(1)
local ledges = ai.getLedgesHeight(1)
if moveMode == "left" then if moveMode == "left" then
if bit32.band(bit32.bor(tiles[0][-1], tiles[-1][-1]), 1) == 1 then if bit32.band(bit32.bor(tiles[0][-1], tiles[-1][-1]), 1) == 1 then
ai.moveLeft(0.75) ai.moveLeft(0.8)
ai.jump() if ledges[-1] <= jumpheight then -- no futile jumps
ai.jump()
end
else else
timeCounter = timeCounter + delta -- no countup when jumping
ai.moveLeft(0.5) ai.moveLeft(0.5)
end end
elseif moveMode == "right" then elseif moveMode == "right" then
if bit32.band(bit32.bor(tiles[0][1], tiles[-1][1]), 1) == 1 then if bit32.band(bit32.bor(tiles[0][1], tiles[-1][1]), 1) == 1 then
ai.moveRight(0.75) ai.moveRight(0.8)
ai.jump() if ledges[1] <= jumpheight then -- no futile jumps
ai.jump()
end
else else
timeCounter = timeCounter + delta -- no countup when jumping
ai.moveRight(0.5) ai.moveRight(0.5)
end end
end end
timeCounter = timeCounter + delta
end end
local function toggleCurrentMode() function toggleCurrentMode()
currentMode = (currentMode == "move") and "turn" or "move" currentMode = (currentMode == "move") and "turn" or "move"
end end
local function toggleMoveMode() function toggleMoveMode()
moveMode = (moveMode == "left") and "right" or "left" moveMode = (moveMode == "left") and "right" or "left"
end end
@@ -52,6 +58,13 @@ end
countMax = generateCountMax() countMax = generateCountMax()
function toggleCondition()
local floorsheight = ai.getFloorsHeight(1)
return timeCounter >= countMax or
-- avoid great falls
(timeCounter > 150 and (floorsheight[-1] > jumpheight or floorsheight[1] > jumpheight))
end
function update(delta) function update(delta)
if currentMode == "move" then if currentMode == "move" then
moveToDirection(delta) moveToDirection(delta)
@@ -59,7 +72,7 @@ function update(delta)
timeCounter = timeCounter + delta -- no countup when jumping timeCounter = timeCounter + delta -- no countup when jumping
end end
if timeCounter >= countMax then if toggleCondition() then
timeCounter = 0 timeCounter = 0
toggleCurrentMode() toggleCurrentMode()
countMax = generateCountMax() countMax = generateCountMax()