This commit is contained in:
Nefrace 2024-04-14 00:11:16 +03:00
commit bb363312a2
3 changed files with 110 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
src.bin
ols.json

51
src/main.odin Normal file
View File

@ -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()
}
}

57
src/player.odin Normal file
View File

@ -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
}