mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +09:00
AI script is now persistent (you can keep variables)
Former-commit-id: 20ca0a8e80f0712c4a3d6a21ee9ae5f15c46c406 Former-commit-id: 2f1cfc2c9b60981053e928a3e7b07117d3b18919
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="Lua" name="Lua">
|
||||
<configuration SdkName="Kahlua" />
|
||||
</facet>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
|
||||
@@ -1,60 +1,8 @@
|
||||
싸구려 커피를 마신다
|
||||
미지근해 적잖이 속이 쓰려온다
|
||||
눅눅한 비닐장판에 발바닥이
|
||||
쩍 달라 붙었다 떨어진다
|
||||
이제는 아무렇지 않어
|
||||
바퀴벌레 한마리쯤 쓱 지나가도
|
||||
무거운 매일 아침엔
|
||||
다만 그저 약간의 기침이 멈출 생각을 않는다
|
||||
축축한 이불을 갠다
|
||||
삐걱대는 문을 열고 밖에 나가본다
|
||||
아직 덜갠 하늘이 너무 가까워 숨쉬기가
|
||||
쉽지를 않다 수만번 본 것만 같다
|
||||
어지러워 쓰러질 정도로 익숙하기만 하다
|
||||
남은 것도 없이 텅빈 나를 잠근다
|
||||
객체 지향 프로그래밍(영어: Object-Oriented Programming, OOP)은 컴퓨터 프로그래밍의 패러다임의 하나
|
||||
이다. 객체 지향 프로그래밍은 컴퓨터 프로그램을 명령어의 목록으로 보는 시각에서 벗어나 여러 개의 독립된 단위, 즉
|
||||
“객체” 들의 모임으로 파악하고자 하는 것이다. 각각의 객체는 메시지를 주고받고, 데이터를 처리할 수 있다.
|
||||
|
||||
싸구려 커피를 마신다
|
||||
미지근해 적잖이 속이 쓰려온다
|
||||
눅눅한 비닐장판에 발바닥이
|
||||
쩍하고 달라 붙었다가 떨어진다
|
||||
|
||||
뭐 한 몇년간 세숫대야에
|
||||
고여있는 물 마냥 그냥 완전히 썩어가지고
|
||||
이거는 뭐 감각이 없어
|
||||
비가 내리면 처마 밑에서 쭈그리고 앉아서
|
||||
멍하니 그냥 가만히 보다보면은
|
||||
이거는 뭔가 아니다 싶어
|
||||
비가 그쳐도 희끄므레죽죽한
|
||||
저게 하늘이라고 머리위를 뒤덮고 있는건지
|
||||
저건 뭔가 하늘이라고 하기에는 뭔가 너무 낮게
|
||||
머리카락에 거의 닿게 조금만 뛰어도 정수리를
|
||||
쿵!하고 찧을거 같은데
|
||||
벽장속 제습제는 벌써 꽉차 있으나마나
|
||||
모기 때려잡다 번진 피가 묻은 거울을 볼때마다
|
||||
어우! 약간 놀라
|
||||
제 멋대로 구부러진 칫솔 갖다 이빨을 닦다 보면은
|
||||
잇몸에 피가 나게 닦아도 당췌 치석은 빠져 나올줄을 몰라
|
||||
언제 땄는지도 모르는 미지근한 콜라가 담긴
|
||||
캔을 입에 가져다 한모금 아뿔싸 담배 꽁초가
|
||||
이제는 장판이 난지 내가 장판인지도 몰라
|
||||
해가 뜨기도 전에 지는 이런 상황은 뭔가
|
||||
|
||||
싸구려 커피를 마신다
|
||||
미지근해 적잖이 속이 쓰려온다
|
||||
눅눅한 비닐장판에 발바닥이
|
||||
쩍 달라 붙었다 떨어진다
|
||||
이제는 아무렇지 않어
|
||||
바퀴벌레 한마리쯤 쓱 지나가도
|
||||
무거운 매일 아침엔
|
||||
다만 그저 약간의 기침이 멈출 생각을 않는다
|
||||
축축한 이불을 갠다
|
||||
삐걱대는 문을 열고 밖에 나가본다
|
||||
아직 덜갠 하늘이 너무 가까워 숨쉬기가
|
||||
쉽지를 않다 수만번 본 것만 같다
|
||||
어지러워 쓰러질 정도로 익숙하기만 하다
|
||||
남은 것도 없이 텅빈 나를 잠근다
|
||||
|
||||
싸구려 커피를 마신다
|
||||
미지근해 적잖이 속이 쓰려온다
|
||||
눅눅한 비닐장판에 발바닥이
|
||||
쩍하고 달라 붙었다가 떨어진다
|
||||
객체 지향 프로그래밍은 프로그램을 유연하고 변경이 용이하게 만들기 때문에 대규모 소프트웨어 개발에 많이 사용된다.
|
||||
또한 프로그래밍을 더 배우기 쉽게 하고 소프트웨어 개발과 보수를 간편하게 하며, 보다 직관적인 코드 분석을 가능하게
|
||||
하는 장점을 갖고 있다. 그러나 지나친 프로그램의 객체화 경향은 실제 세계의 모습을 그대로 반영하지 못한다는 비판을
|
||||
받기도 한다.
|
||||
|
||||
@@ -4,10 +4,7 @@ import net.torvald.terrarum.gameactors.ActorHumanoid
|
||||
import net.torvald.terrarum.gameactors.ai.AILuaAPI
|
||||
import net.torvald.terrarum.gameitem.EquipPosition
|
||||
import net.torvald.terrarum.gameitem.InventoryItem
|
||||
import org.luaj.vm2.Globals
|
||||
import org.luaj.vm2.LoadState
|
||||
import org.luaj.vm2.LuaError
|
||||
import org.luaj.vm2.LuaValue
|
||||
import org.luaj.vm2.*
|
||||
import org.luaj.vm2.compiler.LuaC
|
||||
import org.luaj.vm2.lib.*
|
||||
import org.luaj.vm2.lib.jse.JseBaseLib
|
||||
@@ -27,8 +24,18 @@ open class HumanoidNPC(val luaScript: String, born: GameDate) : ActorHumanoid(bo
|
||||
|
||||
protected val luag: Globals = JsePlatform.standardGlobals()
|
||||
|
||||
/**
|
||||
* Initialised in init block.
|
||||
* Use function "function update(delta)" to step the AI.
|
||||
*/
|
||||
protected val luaInstance: LuaValue
|
||||
|
||||
private val aiLuaAPI: AILuaAPI
|
||||
|
||||
init {
|
||||
AILuaAPI(luag, this)
|
||||
aiLuaAPI = AILuaAPI(luag, this)
|
||||
luaInstance = luag.load(luaScript)
|
||||
luaInstance.call()
|
||||
}
|
||||
|
||||
// we're having InventoryItem data so that this class could be somewhat universal
|
||||
@@ -67,17 +74,12 @@ open class HumanoidNPC(val luaScript: String, born: GameDate) : ActorHumanoid(bo
|
||||
isVisible = true
|
||||
}
|
||||
|
||||
|
||||
init {
|
||||
//val inputStream = javaClass.getResourceAsStream(scriptPath)
|
||||
//runCommand(InputStreamReader(inputStream), scriptPath)
|
||||
}
|
||||
|
||||
|
||||
override fun update(gc: GameContainer, delta: Int) {
|
||||
super.update(gc, delta)
|
||||
aiLuaAPI.update(delta)
|
||||
|
||||
//runCommand(luaScript)
|
||||
luag.load(luaScript).call()
|
||||
luag.get("update").call(delta.toLuaValue())
|
||||
|
||||
//moveRight()
|
||||
}
|
||||
@@ -172,4 +174,6 @@ open class HumanoidNPC(val luaScript: String, born: GameDate) : ActorHumanoid(bo
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun Int.toLuaValue(): LuaValue = LuaInteger.valueOf(this)
|
||||
}
|
||||
@@ -28,6 +28,13 @@ object PlayerBuilderCynthia {
|
||||
|
||||
p.setPosition(4096.0 * MapDrawer.TILE_SIZE, 300.0 * MapDrawer.TILE_SIZE)
|
||||
|
||||
|
||||
|
||||
|
||||
p.referenceID = 12345678
|
||||
|
||||
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.torvald.terrarum.gameactors.ai
|
||||
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.gameactors.AIControlled
|
||||
import net.torvald.terrarum.gameactors.AVKey
|
||||
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||
@@ -13,13 +14,13 @@ import org.luaj.vm2.lib.ZeroArgFunction
|
||||
/**
|
||||
* Created by minjaesong on 16-10-24.
|
||||
*/
|
||||
internal class AILuaAPI(g: Globals, actor: ActorWithBody) {
|
||||
internal class AILuaAPI(val g: Globals, actor: ActorWithBody) {
|
||||
|
||||
init {
|
||||
if (actor !is AIControlled)
|
||||
throw IllegalArgumentException("The actor is not AIControlled! $actor")
|
||||
|
||||
// load things. WARNING: THIS IS MANUAL!
|
||||
// load functions and set up constants
|
||||
g["ai"] = LuaValue.tableOf()
|
||||
|
||||
g["ai"]["getSelfActorInfo"] = GetSelfActorInfo(actor)
|
||||
@@ -35,7 +36,10 @@ internal class AILuaAPI(g: Globals, actor: ActorWithBody) {
|
||||
g["ai"]["moveRight"] = MoveRight(actor)
|
||||
g["ai"]["moveTo"] = MoveTo(actor)
|
||||
g["ai"]["jump"] = Jump(actor)
|
||||
}
|
||||
|
||||
fun update(delta: Int) {
|
||||
// set up variables
|
||||
}
|
||||
|
||||
companion object {
|
||||
@@ -59,7 +63,7 @@ internal class AILuaAPI(g: Globals, actor: ActorWithBody) {
|
||||
|
||||
t["collisionType"] = actor.collisionType
|
||||
|
||||
t["strength"] = actor.actorValue.getAsInt(AVKey.STRENGTH) ?: 0
|
||||
t["strength"] = actor.avStrength
|
||||
|
||||
val lumrgb: Int = actor.actorValue.getAsInt(AVKey.LUMINOSITY) ?: 0
|
||||
val MUL_2 = LightmapRenderer.MUL_2
|
||||
|
||||
@@ -7,10 +7,14 @@ package net.torvald.terrarum.gameactors.ai.scripts
|
||||
*/
|
||||
object PokemonNPCAI {
|
||||
operator fun invoke(): String = """
|
||||
ai.jump()
|
||||
ai.moveRight()
|
||||
|
||||
thisActorInfo = ai.getSelfActorInfo()
|
||||
print(thisActorInfo.strength)
|
||||
counter = 1
|
||||
|
||||
function update(delta)
|
||||
ai.moveRight()
|
||||
print("delta", delta)
|
||||
counter = counter + delta
|
||||
print("testcounter", counter)
|
||||
end
|
||||
"""
|
||||
}
|
||||
Reference in New Issue
Block a user