2024-10-13 17:41:17 -05:00
|
|
|
.{Vec2} := @use("../../../../libraries/stn/src/lib.hb").math
|
2024-10-13 17:38:43 -05:00
|
|
|
render := @use("../../../../libraries/render/src/lib.hb")
|
|
|
|
|
|
|
|
/* expected result:
|
|
|
|
a cute image bounces around the screen */
|
|
|
|
|
2024-10-14 19:24:29 -05:00
|
|
|
bmp_1 := @embed("./able.bmp")
|
|
|
|
bmp_2 := @embed("./mini.bmp")
|
2024-10-13 17:38:43 -05:00
|
|
|
|
|
|
|
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)),
|
|
|
|
)
|
2024-10-13 17:38:43 -05:00
|
|
|
vel := Vec2(int).(1, 1)
|
|
|
|
pos := Vec2(int).(100, 100)
|
2024-10-14 19:24:29 -05:00
|
|
|
n := -1
|
2024-10-13 17:38:43 -05:00
|
|
|
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-13 17:38:43 -05:00
|
|
|
|
2024-10-14 19:24:29 -05:00
|
|
|
if pos.x == 0 | pos.x == screen.width - image.width {
|
2024-10-13 17:38:43 -05:00
|
|
|
vel.x = -vel.x
|
2024-10-14 19:24:29 -05:00
|
|
|
n = -1 - n
|
2024-10-13 17:38:43 -05:00
|
|
|
}
|
2024-10-14 19:24:29 -05:00
|
|
|
if pos.y == 0 | pos.y == screen.height - image.height {
|
2024-10-13 17:38:43 -05:00
|
|
|
vel.y = -vel.y
|
2024-10-14 19:24:29 -05:00
|
|
|
n = -1 - n
|
2024-10-13 17:38:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
pos += vel
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|