Skip to content

Commit

Permalink
Playground fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Marek Maškarinec <[email protected]>
  • Loading branch information
marekmaskarinec committed Apr 17, 2024
1 parent cb2fed0 commit 1a88148
Showing 1 changed file with 31 additions and 31 deletions.
62 changes: 31 additions & 31 deletions etc/playground.html
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,10 @@ <h1>Tophat playground</h1>
)
fn init*() {
window.setup("Hello world", 200, 200)
window::setup("Hello world", 200, 200)
window.onFrame.register({
canvas.drawText("Hello world", { 1, 1 }, th.green, 1)
window::onFrame.register({
canvas::drawText("Hello world", { 1, 1 }, th::green, 1)
})
}`);
break;
Expand All @@ -176,67 +176,67 @@ <h1>Tophat playground</h1>
"std.um"
)
var ft: font.Font
var ft: font::Font
fn init*() {
window.setup("Hello world", 200, 200)
window::setup("Hello world", 200, 200)
var err: std.Err
ft, err = font.load("etc/roboto.ttf", 32)
std.exitif(err)
var err: std::Err
ft, err = font::load("etc/roboto.ttf", 32)
std::exitif(err)
window.onFrame.register({
ft.draw("Hello world", { 1, 1 }, th.green, 1)
window::onFrame.register({
ft.draw("Hello world", { 1, 1 }, th::green, 1)
})
}`);
break;
case "Moving rectangle":
window.jar.updateCode(
`import ("th.um"; "rect.um"; "input.um"; "canvas.um"; "window.um"; "signal.um")
pos := th.Vf2{100, 100}
pos := th::Vf2{100, 100}
fn init*() {
const speed = 100
window.setup("my game", 400, 400)
window.setViewport(th.Vf2{200, 200})
window::setup("my game", 400, 400)
window::setViewport(th::Vf2{200, 200})
window.onFrame.register(signal.Callback{
var change: th.Vf2
window::onFrame.register({
var change: th::Vf2
// Handle input
if input.isPressedc('A') { change.x -= 1 }
if input.isPressedc('D') { change.x += 1 }
if input.isPressedc('W') { change.y -= 1 }
if input.isPressedc('S') { change.y += 1 }
if input::isPressedc('A') { change.x -= 1 }
if input::isPressedc('D') { change.x += 1 }
if input::isPressedc('W') { change.y -= 1 }
if input::isPressedc('S') { change.y += 1 }
// Apply movement
pos = pos.add(change.norm().mulf(speed * th.delta / 1000.0))
pos = pos.add(change.norm().mulf(speed * th::delta / 1000.0))
// Draw!
canvas.drawRect(th.green, rect.mk(pos.x, pos.y, 10, 10))
canvas::drawRect(th::green, rect::mk(pos.x, pos.y, 10, 10))
})
}`);
break;
case "Draw an image":
window.jar.updateCode(
`import ("window.um"; "image.um"; "th.um"; "signal.um"; "std.um")
var img: image.Image
var img: image::Image
const scale = 4
fn init*() {
window.setup("image drawing", 400, 400)
var err: std.Err
img, err = image.load("etc/logo/logo-hatonly.png")
std.exitif(err)
window.onFrame.register(signal.Callback{
img.draw(th.mkTransform(
window.wp.sub(img.getDims().mulf(scale)).divf(2),
th.vf2f(scale) ))
window::setup("image drawing", 400, 400)
var err: std::Err
img, err = image::load("etc/logo/logo-hatonly.png")
std::exitif(err)
window::onFrame.register({
img.draw(th::mkTransform(
window::wp.sub(img.getDims().mulf(scale)).divf(2),
th::vf2f(scale) ))
})
}`);
break;
Expand Down

0 comments on commit 1a88148

Please sign in to comment.