Skip to content

Commit

Permalink
Add Gfx example
Browse files Browse the repository at this point in the history
  • Loading branch information
dwursteisen committed Mar 18, 2024
1 parent 25a5fff commit f177163
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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).")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"""

0 comments on commit f177163

Please sign in to comment.