From f177163dcfe0fea9ae3b5efeb4d7156ced66c384 Mon Sep 17 00:00:00 2001 From: David Wursteisen Date: Mon, 18 Mar 2024 23:49:34 +0100 Subject: [PATCH] Add Gfx example --- .../com/github/minigdx/tiny/lua/GfxLib.kt | 2 +- .../github/minigdx/tiny/lua/GfxLibExamples.kt | 33 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/tiny-engine/src/commonMain/kotlin/com/github/minigdx/tiny/lua/GfxLib.kt b/tiny-engine/src/commonMain/kotlin/com/github/minigdx/tiny/lua/GfxLib.kt index 6720bd99..82926083 100644 --- a/tiny-engine/src/commonMain/kotlin/com/github/minigdx/tiny/lua/GfxLib.kt +++ b/tiny-engine/src/commonMain/kotlin/com/github/minigdx/tiny/lua/GfxLib.kt @@ -129,7 +129,7 @@ class GfxLib(private val resourceAccess: GameResourceAccess) : TwoArgFunction() } } - @TinyFunction("Move the game camera.") + @TinyFunction("Move the game camera.", example = GFX_CAMERA_EXAMPLE) inner class camera : TwoArgFunction() { @TinyCall("Reset the game camera to it's default position (0,0).") diff --git a/tiny-engine/src/commonMain/kotlin/com/github/minigdx/tiny/lua/GfxLibExamples.kt b/tiny-engine/src/commonMain/kotlin/com/github/minigdx/tiny/lua/GfxLibExamples.kt index 26d33693..816fd061 100644 --- a/tiny-engine/src/commonMain/kotlin/com/github/minigdx/tiny/lua/GfxLibExamples.kt +++ b/tiny-engine/src/commonMain/kotlin/com/github/minigdx/tiny/lua/GfxLibExamples.kt @@ -111,3 +111,36 @@ function _draw() local pos = ctrl.touch() shape.circlef(pos.x, pos.y, 4, math.rnd()) end""" + +//language=Lua +const val GFX_CAMERA_EXAMPLE = """ +local x = 0 +local y = 0 + +function _update() + if ctrl.pressing(keys.left) then + x = x - 0.5 + elseif ctrl.pressing(keys.right) then + x = x + 0.5 + end + + if ctrl.pressing(keys.up) then + y = y - 0.5 + elseif ctrl.pressing(keys.down) then + y = y + 0.5 + end + gfx.camera(math.floor(x), math.floor(y)) +end + +function _draw() + gfx.cls(2) + for x = 0 - 64, 256 + 64, 16 do + for y = 0 - 64, 256 + 64, 16 do + shape.line(x - 2, y, x + 2, y, 9) + shape.line(x, y - 2, x, y + 2, 9) + end + end + print("camera: ("..x..", "..y..")", 6, 6) + + shape.rect(0, 0, 256, 256, 1) +end"""