commit bb363312a295acbd124d2d1163590040e9c37a1e Author: Nefrace Date: Sun Apr 14 00:11:16 2024 +0300 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c83aa98 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +src.bin +ols.json diff --git a/src/main.odin b/src/main.odin new file mode 100644 index 0000000..7f3b1dd --- /dev/null +++ b/src/main.odin @@ -0,0 +1,51 @@ +package main + +import "core:math" +import rl "vendor:raylib" + +Vec3 :: [3]f32 + +Entity :: struct { + position : Vec3, + velocity : Vec3, + size : Vec3, + update : proc(entity: ^Entity, delta: f32), +} + +PAL_INT :: [6]u32 { + 0x272744ff, + 0x494d7eff, + 0x8b6d9cff, + 0xc69fa5ff, + 0xf2d3abff, + 0xfbf5efff, +} + +PAL := [6]rl.Color{} + +main :: proc() { + for v, i in PAL_INT { + PAL[i] = rl.GetColor(v) + } + + rl.InitWindow(800, 400, "By The Fire") + rl.SetTargetFPS(60) + + player := player_create() + + rl.DisableCursor() + + for !rl.WindowShouldClose() { + using rl + player_update(&player, GetFrameTime()) + + BeginDrawing() + BeginMode3D(player.camera) + + ClearBackground(PAL[0]) + DrawPlane({0, 0, 0}, {32,32}, PAL[1]) + + EndMode3D() + EndDrawing() + } +} diff --git a/src/player.odin b/src/player.odin new file mode 100644 index 0000000..b7c0869 --- /dev/null +++ b/src/player.odin @@ -0,0 +1,57 @@ +package main + +import "core:math" +import rl "vendor:raylib" + +Player :: struct { + using entity: Entity, + cameraOffset: Vec3, + direction: f32, + yaw: f32, + camera: rl.Camera3D, +} + +player_create :: proc() -> Player { + return Player { + size = {0.5, 2, 0.5}, + cameraOffset = {0, 1.8, 0}, + camera = rl.Camera3D{ + up = {0, 1, 0}, + fovy = 80, + projection = rl.CameraProjection.PERSPECTIVE, + }, + } +} + +player_update :: proc(using player: ^Player, delta: f32) { + using rl + mouseDelta := GetMouseDelta() + + direction -= mouseDelta.x * 0.003 + yaw -= mouseDelta.y * 0.003 + + yaw = Clamp(yaw, -math.PI/2+0.001, math.PI/2-0.001) + + dir_right := direction + math.PI / 2 + forward := Vec3{math.sin(direction), 0, math.cos(direction)} + right := Vec3{math.sin(dir_right), 0, math.cos(dir_right)} + + motion := Vec3{} + + if IsKeyDown(KeyboardKey.W) {motion += forward * 0.1} + if IsKeyDown(KeyboardKey.S) {motion -= forward * 0.1} + if IsKeyDown(KeyboardKey.A) {motion += right * 0.1} + if IsKeyDown(KeyboardKey.D) {motion -= right * 0.1} + motion = rl.Vector3ClampValue(motion, 0, 0.2) + velocity.xz = motion.xz + position += velocity + + camera.position = position + cameraOffset + + target := Vec3{ + math.sin(direction) * math.cos(yaw), + math.sin(yaw), + math.cos(direction) * math.cos(yaw), + } + camera.target = position + cameraOffset + target +}