mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-12 03:24:06 +09:00
random roam around AI
Former-commit-id: 5edf7e848f519d440ecb915b7d6e27e9ead8dd6f Former-commit-id: e89bfcd8b443c77e88d5ec7090f836b77ae5f02b
This commit is contained in:
@@ -8,13 +8,49 @@ package net.torvald.terrarum.gameactors.ai.scripts
|
|||||||
object PokemonNPCAI {
|
object PokemonNPCAI {
|
||||||
operator fun invoke(): String = """
|
operator fun invoke(): String = """
|
||||||
|
|
||||||
counter = 1
|
timeCounter = 0
|
||||||
|
countMax = 0
|
||||||
|
moveMode = math.random() >= 0.5 and "left" or "right"
|
||||||
|
currentMode = "turn"
|
||||||
|
|
||||||
|
function generateTurn()
|
||||||
|
return 4600 + 1250 * math.random()
|
||||||
|
end
|
||||||
|
|
||||||
|
function generateWalk()
|
||||||
|
return 568 + 342 * math.random()
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
countMax = generateTurn()
|
||||||
|
|
||||||
function update(delta)
|
function update(delta)
|
||||||
ai.moveRight()
|
timeCounter = timeCounter + delta
|
||||||
print("delta", delta)
|
|
||||||
counter = counter + delta
|
if currentMode == "turn" then
|
||||||
print("testcounter", counter)
|
-- wait
|
||||||
|
-- reset counter
|
||||||
|
if timeCounter >= countMax then
|
||||||
|
timeCounter = 0
|
||||||
|
currentMode = "move"
|
||||||
|
countMax = generateWalk()
|
||||||
|
moveMode = (moveMode == "left") and "right" or "left"
|
||||||
|
end
|
||||||
|
elseif currentMode == "move" then
|
||||||
|
-- move
|
||||||
|
if moveMode == "left" then
|
||||||
|
ai.moveLeft()
|
||||||
|
elseif moveMode == "right" then
|
||||||
|
ai.moveRight()
|
||||||
|
end
|
||||||
|
-- reset counter
|
||||||
|
if timeCounter >= countMax then
|
||||||
|
timeCounter = 0
|
||||||
|
currentMode = "turn"
|
||||||
|
countMax = generateTurn()
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user