forked from AbleOS/ableos
32 lines
875 B
Plaintext
32 lines
875 B
Plaintext
.{Vec2} := @use("../../../../libraries/stn/src/lib.hb").math;
|
|
.{random} := @use("../../../../libraries/stn/src/lib.hb")
|
|
render := @use("../../../../libraries/render/src/lib.hb")
|
|
|
|
/* expected result:
|
|
a square that changes colour bounces around the screen */
|
|
|
|
example := fn(): void {
|
|
render.init()
|
|
vel := Vec2(int).(1, 1)
|
|
pos := Vec2(int).(100, 100)
|
|
width := render.width()
|
|
height := render.height()
|
|
color := @as(render.Color, @intcast(random.range(int, 0, 0xFFFFFF)))
|
|
loop {
|
|
render.put_filled_rect(pos, .(100, 100), color)
|
|
render.sync()
|
|
render.clear(render.black)
|
|
|
|
if pos.x == 0 | pos.x == width - 100 {
|
|
vel.x = -vel.x
|
|
color = @as(render.Color, @intcast(random.range(int, 0, 0xFFFFFF)))
|
|
}
|
|
if pos.y == 0 | pos.y == height - 100 {
|
|
vel.y = -vel.y
|
|
color = @as(render.Color, @intcast(random.range(int, 0, 0xFFFFFF)))
|
|
}
|
|
|
|
pos += vel
|
|
}
|
|
return
|
|
} |