diff --git a/AlgebraicDataflowArchitectureModel/models/GameEngine.model b/AlgebraicDataflowArchitectureModel/models/GameEngine.model index 8d05235..1e23e9b 100644 --- a/AlgebraicDataflowArchitectureModel/models/GameEngine.model +++ b/AlgebraicDataflowArchitectureModel/models/GameEngine.model @@ -1,3 +1,10 @@ +init { + enemy := { + "position": {"x": 0.0, "y": 0.0, "z": 0.0}, + "id": "001" + } +} + native channel SceneUpdateEvent { out scene.time(time: Long, updateEvent(dt: Long)) = time + dt } @@ -42,6 +49,22 @@ in scene.entities.{eid}.mesh(curMesh: Json, updateSprite(spritePath: Str)) = {"type": "sprite", "sprite": spritePath} } +native channel TimersUpdated { + in timers(curTimers: Map, update(curTimers, nextTimers)) = nextTimers +} + +native channel TimerEvent(tid: Str) { + out timers.{tid}.count(count: Long, tick()) = count + 1 +} + +channel StartTimer { + out timers(timers: Map, startTimer(tid: Str, interval: Long)) = insert(timers, tid, {"interval": interval, "count": 0}) +} + +channel ClearTimer { + out timers(timers: Map, clearTimer(tid: Str)) = delete(timers, tid) +} + channel AddSprite { out scene.entities(entityDB: Map, addSprite(eid: Str, spritePath: Str)) = insert(entityDB, eid, { "transform": { @@ -60,3 +83,14 @@ channel RotateEntity(eid: Str) { out scene.entities.{eid}.transform.rotation(curRot: Json, rotate(x: Double, y: Double, z: Double)) = {"x": x, "y": y, "z": z} } + +channel UpdateEnemy(tid: Str) { + in timers.{tid}.count(curCount: Long, updateEnemy(nextCount)) = nextCount + out enemy.position(curPos: Json, updateEnemy(nextCount)) = {"x": curPos.x, "y": curPos.y + 1, "z": curPos.z} +} + +channel ViewEnemy { + in enemy.position(curPos: Json, viewEnemy(nextPos, nextId)) = nextPos + in enemy.id(curId: Str, viewEnemy(nextPos, nextId)) = nextId + out scene.entities.{nextId}.transform.position(curPos: Json, viewEnemy(nextPos, nextId)) = nextPos +}