118 lines
2.5 KiB
Odin
118 lines
2.5 KiB
Odin
package terrain
|
|
|
|
import rl "vendor:raylib"
|
|
import rlgl "vendor:raylib/rlgl"
|
|
import "core:math"
|
|
import "core:math/rand"
|
|
import "core:fmt"
|
|
|
|
Vec2 :: [2]f32
|
|
Vec3 :: [3]f32
|
|
Rect :: rl.Rectangle
|
|
Img :: rl.Image
|
|
Tex :: rl.Texture
|
|
Key :: rl.KeyboardKey
|
|
Color :: rl.Color
|
|
|
|
SCREEN_WIDTH : i32 = 1600
|
|
SCREEN_HEIGHT : i32 = 1000
|
|
BW := f32(SCREEN_WIDTH)
|
|
BH := f32(SCREEN_HEIGHT)
|
|
|
|
points :[]Vec3
|
|
|
|
GameState :: struct {
|
|
dt: f32,
|
|
keymap: map[string]Key,
|
|
cam: rl.Camera3D,
|
|
}
|
|
|
|
init_state :: proc() -> ^GameState {
|
|
keymap := make(map[string]Key)
|
|
keymap["Left"] = .A
|
|
keymap["Right"] = .D
|
|
keymap["Up"] = .W
|
|
keymap["Down"] = .S
|
|
|
|
state := GameState {
|
|
keymap = keymap,
|
|
cam = {
|
|
position = { 35.0, 35.0, 35.0 },
|
|
target = { 0.0, -5.0, 0.0 },
|
|
up = { 0.0, 1.0, 0.0 },
|
|
fovy = 15.0,
|
|
projection = rl.CameraProjection.PERSPECTIVE,
|
|
},
|
|
}
|
|
rlgl.EnableWireMode()
|
|
// rows := 1
|
|
// cols := 50
|
|
// for r in 0..<rows {
|
|
// for c in 0..<cols {
|
|
// row := c % 2 == 0 ? c : c + 1
|
|
// points[c + r * cols] = {}
|
|
// }
|
|
// }
|
|
points = {
|
|
{0,0,0},{0,0,1},
|
|
{1,0,0},{1,0,0},{1,0,1},
|
|
{2,0,0},{2,0,1},
|
|
{3,0,0},{3,0,1},
|
|
{4,0,0},{4,0,1},
|
|
{5,0,0},{5,0,1},
|
|
}
|
|
cloned := new_clone(state)
|
|
return cloned
|
|
}
|
|
|
|
get_rand_angle :: proc(min: i32, max: i32) -> f32 { return f32(rl.GetRandomValue(min, max)) * rl.DEG2RAD }
|
|
|
|
player_input :: proc(using s: ^GameState) {
|
|
horizontal: f32
|
|
vertical: f32
|
|
if rl.IsKeyDown(s.keymap["Right"]) { horizontal = 1 }
|
|
if rl.IsKeyDown(s.keymap["Left"]) { horizontal = -1 }
|
|
if rl.IsKeyDown(s.keymap["Up"]) { vertical = -1 }
|
|
if rl.IsKeyDown(s.keymap["Down"]) { vertical = 1 }
|
|
if rl.IsMouseButtonPressed(rl.MouseButton.LEFT) {
|
|
}
|
|
}
|
|
|
|
update :: proc(using s: ^GameState) {
|
|
}
|
|
|
|
draw :: proc(using s: ^GameState) {
|
|
|
|
rl.DrawTriangleStrip3D(raw_data(points), 6, rl.BLACK)
|
|
}
|
|
|
|
main :: proc() {
|
|
rl.SetTraceLogLevel(.ERROR)
|
|
rl.InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "Boids")
|
|
rl.SetTargetFPS(60)
|
|
|
|
state := init_state()
|
|
defer {
|
|
free(state)
|
|
}
|
|
|
|
for !rl.WindowShouldClose() {
|
|
state.dt = rl.GetFrameTime()
|
|
|
|
player_input(state)
|
|
|
|
update(state)
|
|
|
|
rl.BeginDrawing()
|
|
rl.ClearBackground(rl.WHITE)
|
|
|
|
rl.BeginMode3D(state.cam)
|
|
draw(state)
|
|
rl.EndMode3D()
|
|
|
|
rl.EndDrawing()
|
|
}
|
|
|
|
rl.CloseWindow()
|
|
}
|