.{rect_line} := @use("../draw.hb");
.{clear, create_buffer, present, Point, FB_HEIGHT, FB_WIDTH} := @use("../lib.hb")

/* expected result:
   the white outline of a square bounces around the screen */

example := fn(): void {
	// creates a back buffer, which we write to, to avoid screen flickering
	buffer := create_buffer()
	vel := Point.{x: 1, y: 1}
	pos := Point.{x: 100, y: 100}
	loop {
		// draw the square at our current position
		rect_line(buffer, pos, .(100, 100), .(255, 255, 255, 255), 3)
		/* push the back buffer to the front buffer
		   this displays our image to the screen */
		present(buffer)
		// erase our old image
		clear(buffer, .(0, 0, 0, 0))

		// bounce the square if it touches the screen edges
		if pos.x == 0 | pos.x == FB_WIDTH - 100 {
			vel.x = 0 - vel.x
		}
		if pos.y == 0 | pos.y == FB_HEIGHT - 100 {
			vel.y = 0 - vel.y
		}

		pos += vel
	}
	return
}