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

37 lines
857 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-14 19:24:29 -05:00
screen := render.init(true)
images := [render.Surface; 2].(
render.image.surface_from_bmp(@bitcast(&bmp_1)),
render.image.surface_from_bmp(@bitcast(&bmp_2)),
)
vel := Vec2(int).(1, 1)
pos := Vec2(int).(100, 100)
2024-10-14 19:24:29 -05:00
n := -1
loop {
2024-10-14 19:24:29 -05:00
image := images[n]
render.put_surface(screen, image, pos)
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
2024-10-14 19:24:29 -05:00
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
2024-10-14 19:24:29 -05:00
n = -1 - n
}
pos += vel
}
return
}