ableos/sysdata/programs/render_example/src/examples/image.hb

37 lines
869 B
Plaintext
Raw Normal View History

2024-10-13 17:41:17 -05:00
.{Vec2} := @use("../../../../libraries/stn/src/lib.hb").math
render := @use("../../../../libraries/render/src/lib.hb")
/* expected result:
a cute image bounces around the screen */
2024-10-15 15:43:23 -05:00
bmp_1 := @embed("./assets/able.bmp")
bmp_2 := @embed("./assets/mini.bmp")
example := fn(): void {
2024-10-25 10:37:38 -05:00
images := [render.Surface].(
2024-10-14 19:24:29 -05:00
render.image.surface_from_bmp(@bitcast(&bmp_1)),
render.image.surface_from_bmp(@bitcast(&bmp_2)),
)
screen := render.init(true)
vel := Vec2(int).(1, 1)
2024-10-25 10:37:38 -05:00
pos := Vec2(uint).(100, 100)
n := 0
loop {
2024-10-14 19:24:29 -05:00
image := images[n]
render.put_surface(screen, image, pos, false)
2024-10-14 19:24:29 -05:00
render.sync(screen)
render.clear(screen, render.black)
2024-10-14 19:24:29 -05:00
if pos.x == 0 | pos.x == screen.width - image.width {
vel.x = -vel.x
n = 1 - n
}
2024-10-14 19:24:29 -05:00
if pos.y == 0 | pos.y == screen.height - image.height {
vel.y = -vel.y
n = 1 - n
}
2024-10-25 10:37:38 -05:00
pos += @bitcast(vel)
}
return
}