~evantj/hare-raylib

b9e2efa5122ddeb4b93d20a5f9653591ea29d7c9 — Autumn! 7 months ago fe07653
Rewrite/fix demos

Signed-off-by: Autumn! <autumnull@posteo.net>
2 files changed, 38 insertions(+), 56 deletions(-)

M cmd/demo/main.ha
M cmd/heightmap/main.ha
M cmd/demo/main.ha => cmd/demo/main.ha +37 -53
@@ 1,62 1,46 @@
use raylib;
use rl = raylib;
use math;

export fn main() void = {
	let cam: raylib::Camera3D = raylib::Camera3D {
		position = raylib::Vector3 {
			x = 10.0,
			y = 10.0,
			z = 10.0,
		},
		target = raylib::Vector3 {
			x = 0.0,
			y = 0.0,
			z = 0.0,
		},
		up = raylib::Vector3 {
			x = 0.0,
			y = 1.0,
			z = 0.0,
		},
		fovy = 45.0,
		projection = raylib::CameraProjection::CAMERA_PERSPECTIVE,
	};
	let cam_angle: f64 = 0.0;
	const screenWidth = 800;
	const screenHeight = 450;
	rl::InitWindow(screenWidth, screenHeight, "hare-raylib demo");
	defer rl::CloseWindow();

	let cube_position = raylib::Vector3 {
		x = 0.0,
		y = 1.0,
		z = 0.0,
	};
	let harriet = rl::LoadTexture("resources/mascot.png");
	defer rl::UnloadTexture(harriet);

	let cube_size = raylib::Vector3 {
		x = 2.0,
		y = 2.0,
		z = 2.0,
	let frameWidth = harriet.width;
	let frameHeight = harriet.height;

	let source = rl::Rectangle {
		width = frameWidth: f32,
		height = frameHeight: f32,
		...
	};
	let dest = rl::Rectangle {
		x = screenWidth: f32 / 2.0,
		y = screenHeight: f32 / 2.0,
		width = frameWidth: f32 * 2.0,
		height = frameHeight: f32 * 2.0,
	};
	let origin = rl::Vector2 {
		x = frameWidth: f32,
		y = frameHeight: f32,
	};
	let rotation = 0;
	rl::SetTargetFPS(60);

	for (!rl::WindowShouldClose(); rotation += 1) {
		rl::BeginDrawing();

		rl::ClearBackground(rl::RAYWHITE);

		rl::DrawTexturePro(harriet, source, dest, origin, rotation: f32, rl::WHITE);
		rl::DrawLine(dest.x: int, 0, dest.x: int, screenHeight, rl::GRAY);
		rl::DrawLine(0, dest.y: int, screenWidth, dest.y: int, rl::GRAY);
		rl::DrawText("Hare raylib", screenWidth-70, screenHeight-20, 10, rl::GRAY);

	raylib::InitWindow(800, 450, "hare-raylib demo");
	defer raylib::CloseWindow();

	let harriet: raylib::Texture2D = raylib::LoadTexture("resources/mascot.png");
	defer raylib::UnloadTexture(harriet);

	raylib::SetTargetFPS(60);

	for (!raylib::WindowShouldClose()) {
		cam_angle += 0.01;
		cam.position.x = math::sinf64(cam_angle): f32 * 10.0;
		cam.position.z = math::cosf64(cam_angle): f32 * 10.0;

		raylib::BeginDrawing();
		raylib::ClearBackground(raylib::RAYWHITE);
		raylib::BeginMode3D(cam);
		raylib::DrawCubeTexture(harriet, cube_position, cube_size.x, cube_size.y, cube_size.z, raylib::WHITE);
		raylib::DrawCubeWires(cube_position, cube_size.x, cube_size.y, cube_size.z, raylib::BLACK);
		raylib::DrawGrid(10, 1.0);
		raylib::EndMode3D();
		raylib::DrawFPS(10, 10);
		raylib::DrawText("Hello, World!", 10, 40, 20, raylib::RED);
		raylib::EndDrawing();
		rl::EndDrawing();
	};
};

M cmd/heightmap/main.ha => cmd/heightmap/main.ha +1 -3
@@ 46,14 46,12 @@ export fn main() void = {
		z = -8.0,
	};

	raylib::SetCameraMode(camera, raylib::CameraMode::CAMERA_ORBITAL);

	raylib::SetTargetFPS(60);

	for (!raylib::WindowShouldClose()) {
		screen_width = raylib::GetScreenWidth();
		screen_height = raylib::GetScreenHeight();
		raylib::UpdateCamera(&camera);
		raylib::UpdateCamera(&camera, raylib::CameraMode::CAMERA_ORBITAL);
		raylib::BeginDrawing();
		raylib::ClearBackground(raylib::RAYWHITE);
		raylib::BeginMode3D(camera);