2024-10-12 15:39:09 -05:00
|
|
|
.{Vec2} := @use("../../../../libraries/stn/src/lib.hb").math;
|
2024-09-30 15:45:57 -05:00
|
|
|
.{random} := @use("../../../../libraries/stn/src/lib.hb")
|
2024-09-13 16:41:31 -05:00
|
|
|
render := @use("../../../../libraries/render/src/lib.hb")
|
|
|
|
|
|
|
|
/* expected result:
|
2024-09-30 15:45:57 -05:00
|
|
|
a square that changes colour bounces around the screen */
|
2024-09-13 16:41:31 -05:00
|
|
|
|
|
|
|
example := fn(): void {
|
2024-10-14 19:24:29 -05:00
|
|
|
screen := render.init(true)
|
2024-10-12 15:39:09 -05:00
|
|
|
vel := Vec2(int).(1, 1)
|
2024-10-15 15:43:23 -05:00
|
|
|
side := screen.width / 8
|
|
|
|
pos := Vec2(int).((screen.width - side) / 2, (screen.height - side) / 2)
|
|
|
|
color := random.range(render.Color, render.black, render.white)
|
2024-09-13 16:41:31 -05:00
|
|
|
loop {
|
2024-10-15 15:43:23 -05:00
|
|
|
render.put_filled_rect(screen, pos, .(side, side), color)
|
2024-10-14 19:24:29 -05:00
|
|
|
render.sync(screen)
|
|
|
|
render.clear(screen, render.black)
|
2024-09-13 16:41:31 -05:00
|
|
|
|
2024-10-15 15:43:23 -05:00
|
|
|
if pos.x == 0 | pos.x == screen.width - side {
|
2024-09-14 05:26:32 -05:00
|
|
|
vel.x = -vel.x
|
2024-10-15 15:43:23 -05:00
|
|
|
color = random.range(render.Color, render.black, render.white)
|
2024-09-13 16:41:31 -05:00
|
|
|
}
|
2024-10-15 15:43:23 -05:00
|
|
|
if pos.y == 0 | pos.y == screen.height - side {
|
2024-09-14 05:26:32 -05:00
|
|
|
vel.y = -vel.y
|
2024-10-15 15:43:23 -05:00
|
|
|
color = random.range(render.Color, render.black, render.white)
|
2024-09-13 16:41:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
pos += vel
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|