mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-19 06:54:05 +09:00
Issue #6 resolved
Former-commit-id: 643ca0b3757f329107a7677fe3bf5f43ffac7639 Former-commit-id: caa5582abb797485e90b8c3e47a6307b177ff456
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
package net.torvald.terrarum.gameactors.ai.scripts
|
||||
|
||||
/**
|
||||
* Created by SKYHi14 on 2016-12-28.
|
||||
*/
|
||||
abstract class EncapsulatedString {
|
||||
abstract fun getString(): String
|
||||
override fun toString() = getString()
|
||||
}
|
||||
@@ -5,52 +5,63 @@ package net.torvald.terrarum.gameactors.ai.scripts
|
||||
*
|
||||
* Created by SKYHi14 on 2016-12-23.
|
||||
*/
|
||||
object PokemonNPCAI {
|
||||
operator fun invoke(): String = """
|
||||
|
||||
|
||||
object PokemonNPCAI : EncapsulatedString() {
|
||||
override fun getString() = """
|
||||
timeCounter = 0
|
||||
countMax = 0
|
||||
moveMode = math.random() >= 0.5 and "left" or "right"
|
||||
currentMode = "turn"
|
||||
|
||||
function generateTurn()
|
||||
return 4600 + 1250 * math.random()
|
||||
local function generateCountMax()
|
||||
function generateTurn()
|
||||
return 4600 + 1250 * math.random()
|
||||
end
|
||||
|
||||
function generateWalk()
|
||||
return 568 + 342 * math.random()
|
||||
end
|
||||
|
||||
return (currentMode == "move") and generateWalk() or generateTurn()
|
||||
end
|
||||
|
||||
function generateWalk()
|
||||
return 568 + 342 * math.random()
|
||||
local function moveToDirection()
|
||||
if moveMode == "left" then
|
||||
ai.moveLeft(0.5)
|
||||
elseif moveMode == "right" then
|
||||
ai.moveRight(0.5)
|
||||
end
|
||||
end
|
||||
|
||||
local function toggleCurrentMode()
|
||||
currentMode = (currentMode == "move") and "turn" or "move"
|
||||
end
|
||||
|
||||
local function toggleMoveMode()
|
||||
moveMode = (moveMode == "left") and "right" or "left"
|
||||
end
|
||||
|
||||
countMax = generateTurn()
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
countMax = generateCountMax()
|
||||
|
||||
function update(delta)
|
||||
timeCounter = timeCounter + delta
|
||||
|
||||
if currentMode == "turn" then
|
||||
-- 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(0.5)
|
||||
elseif moveMode == "right" then
|
||||
ai.moveRight(0.5)
|
||||
end
|
||||
-- reset counter
|
||||
if timeCounter >= countMax then
|
||||
timeCounter = 0
|
||||
currentMode = "turn"
|
||||
countMax = generateTurn()
|
||||
if currentMode == "move" then
|
||||
moveToDirection()
|
||||
end
|
||||
|
||||
if timeCounter >= countMax then
|
||||
timeCounter = 0
|
||||
toggleCurrentMode()
|
||||
countMax = generateCountMax()
|
||||
if currentMode == "turn" then
|
||||
toggleMoveMode()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user