Skip to content

Commit

Permalink
Update Ctrl example.
Browse files Browse the repository at this point in the history
  • Loading branch information
dwursteisen committed Mar 19, 2024
1 parent dc72ea7 commit dece52e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class CtrlLib(
@TinyFunction(
"Return true if the key was pressed during the last frame. " +
"If you need to check that the key is still pressed, see `ctrl.pressing` instead.",
example = CTRL_PRESSING_EXAMPLE
)
inner class pressed : OneArgFunction() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,41 +12,33 @@ end

//language=Lua
const val CTRL_PRESSING_EXAMPLE = """
function _init()
circle = {
x = 256 * 0.5,
y = 256 * 0.5,
radius = 10
}
end
local percent_a = 1
local percent_b = 1
function _update()
-- check keys for horizontal move
if (ctrl.pressing(keys.left)) then
circle.x = math.max(circle.x - 1, 0)
elseif (ctrl.pressing(keys.right)) then
circle.x = math.min(circle.x + 1, 256)
end
percent_a = math.min(percent_a + 0.05, 1)
percent_b = math.min(percent_b + 0.05, 1)
-- check keys for vertical move
if (ctrl.pressing(keys.up)) then
circle.y = math.max(circle.y - 1, 0)
elseif (ctrl.pressing(keys.down)) then
circle.y = math.min(circle.y + 1, 256)
if ctrl.pressed(keys.space) then
percent_a = 0
end
-- check keys for update circle size
if (ctrl.pressing(keys.space)) then
circle.radius = math.min(circle.radius + 1, 256)
elseif (ctrl.pressing(keys.enter)) then
circle.radius = math.max(circle.radius - 1, 0)
if ctrl.pressing(keys.space) then
percent_b = 0
end
end
function _draw()
gfx.cls(1)
shape.circlef(circle.x, circle.y, circle.radius, 8)
shape.circle(circle.x, circle.y, 2, 9)
local offset_a = juice.powIn2(0, 8, percent_a)
local offset_b = juice.powIn2(0, 8, percent_b)
gfx.cls()
shape.rectf(64, 128 - 16, 32, 32, 7)
shape.rectf(64, 128 - 32 + offset_a, 32, 32, 8)
shape.rectf(32 + 128, 128 - 16, 32, 32, 7)
shape.rectf(32 + 128, 128 - 32 + offset_b, 32, 32, 8)
print("pressed", 64, 128 + 32)
print("pressing", 32 + 128, 128 + 32)
end
"""

Expand Down

0 comments on commit dece52e

Please sign in to comment.