mini-refactoring
This commit is contained in:
parent
cd412f8249
commit
ef9caac601
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "core:math"
|
import "core:math"
|
||||||
|
import "core:math/rand"
|
||||||
import rl "vendor:raylib"
|
import rl "vendor:raylib"
|
||||||
|
|
||||||
Vec3 :: [3]f32
|
Vec3 :: [3]f32
|
||||||
|
@ -11,20 +12,15 @@ Entity :: struct {
|
||||||
size: Vec3,
|
size: Vec3,
|
||||||
}
|
}
|
||||||
|
|
||||||
PAL_INT :: [6]u32 {
|
PAL_INT :: [6]u32{0x272744ff, 0x494d7eff, 0x8b6d9cff, 0xc69fa5ff, 0xf2d3abff, 0xfbf5efff}
|
||||||
0x272744ff,
|
|
||||||
0x494d7eff,
|
|
||||||
0x8b6d9cff,
|
|
||||||
0xc69fa5ff,
|
|
||||||
0xf2d3abff,
|
|
||||||
0xfbf5efff,
|
|
||||||
}
|
|
||||||
|
|
||||||
PAL := [6]rl.Color{}
|
PAL := [6]rl.Color{}
|
||||||
|
|
||||||
CAMERA: ^rl.Camera3D
|
CAMERA: ^rl.Camera3D
|
||||||
TEXTURES: Textures
|
TEXTURES: Textures
|
||||||
|
|
||||||
|
discard_shader: rl.Shader // See shader below. Required for drawing sprites
|
||||||
|
|
||||||
main :: proc() {
|
main :: proc() {
|
||||||
for v, i in PAL_INT {
|
for v, i in PAL_INT {
|
||||||
PAL[i] = rl.GetColor(v)
|
PAL[i] = rl.GetColor(v)
|
||||||
|
@ -38,27 +34,32 @@ main :: proc() {
|
||||||
|
|
||||||
discard_shader = rl.LoadShaderFromMemory(nil, alpha_discard)
|
discard_shader = rl.LoadShaderFromMemory(nil, alpha_discard)
|
||||||
|
|
||||||
|
// Floor checkerboard
|
||||||
img := rl.GenImageChecked(64, 64, 8, 8, PAL[1], PAL[2])
|
img := rl.GenImageChecked(64, 64, 8, 8, PAL[1], PAL[2])
|
||||||
defer rl.UnloadImage(img)
|
defer rl.UnloadImage(img)
|
||||||
tex := rl.LoadTextureFromImage(img)
|
tex := rl.LoadTextureFromImage(img)
|
||||||
defer rl.UnloadTexture(tex)
|
defer rl.UnloadTexture(tex)
|
||||||
rl.SetTextureFilter(tex, rl.TextureFilter.POINT)
|
|
||||||
|
|
||||||
|
// Floor mesh
|
||||||
plane := rl.GenMeshPlane(32, 32, 16, 16)
|
plane := rl.GenMeshPlane(32, 32, 16, 16)
|
||||||
defer rl.UnloadMesh(plane)
|
defer rl.UnloadMesh(plane)
|
||||||
mat := rl.LoadMaterialDefault()
|
mat := rl.LoadMaterialDefault()
|
||||||
rl.SetMaterialTexture(&mat, rl.MaterialMapIndex.ALBEDO, tex)
|
rl.SetMaterialTexture(&mat, rl.MaterialMapIndex.ALBEDO, tex)
|
||||||
|
|
||||||
player_load_resources()
|
player_load_resources()
|
||||||
defer player_unload_resources()
|
defer player_unload_resources()
|
||||||
player := player_create()
|
player := player_create()
|
||||||
CAMERA = &(player.camera)
|
|
||||||
|
|
||||||
rl.DisableCursor()
|
CAMERA = &(player.camera)
|
||||||
|
|
||||||
torches := [10]Torch{}
|
torches := [10]Torch{}
|
||||||
for &v, i in torches {
|
for &v, i in torches {
|
||||||
torches[i] = Torch{position = Vec3{f32(i) * 2, 2, 0}}
|
torches[i] = Torch {
|
||||||
|
position = Vec3{rand.float32_range(-10, 10), 2, rand.float32_range(-10, 10)},
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rl.DisableCursor()
|
||||||
|
|
||||||
for !rl.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
using rl
|
using rl
|
||||||
|
@ -79,7 +80,6 @@ main :: proc() {
|
||||||
torch_draw(&v)
|
torch_draw(&v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
EndShaderMode()
|
EndShaderMode()
|
||||||
|
|
||||||
EndMode3D()
|
EndMode3D()
|
||||||
|
@ -87,7 +87,6 @@ main :: proc() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
discard_shader : rl.Shader
|
|
||||||
|
|
||||||
alpha_discard :: `
|
alpha_discard :: `
|
||||||
#version 330
|
#version 330
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "core:math"
|
|
||||||
import "core:fmt"
|
import "core:fmt"
|
||||||
|
import "core:math"
|
||||||
import rl "vendor:raylib"
|
import rl "vendor:raylib"
|
||||||
|
|
||||||
Player :: struct {
|
Player :: struct {
|
||||||
|
@ -21,9 +21,6 @@ player_sword_mat : rl.Material
|
||||||
|
|
||||||
player_load_resources :: proc() {
|
player_load_resources :: proc() {
|
||||||
player_sword_tex = TEXTURES["sword.png"] // rl.LoadTexture("sword.png")
|
player_sword_tex = TEXTURES["sword.png"] // rl.LoadTexture("sword.png")
|
||||||
fmt.println(TEXTURES)
|
|
||||||
fmt.println(player_sword_tex)
|
|
||||||
rl.SetTextureFilter(player_sword_tex, rl.TextureFilter.POINT)
|
|
||||||
player_sword_mesh = rl.GenMeshPlane(1.5, 3.6, 1, 1)
|
player_sword_mesh = rl.GenMeshPlane(1.5, 3.6, 1, 1)
|
||||||
player_sword_mat = rl.LoadMaterialDefault()
|
player_sword_mat = rl.LoadMaterialDefault()
|
||||||
player_sword_mat.shader = discard_shader
|
player_sword_mat.shader = discard_shader
|
||||||
|
@ -32,12 +29,12 @@ player_load_resources :: proc() {
|
||||||
|
|
||||||
player_unload_resources :: proc() {
|
player_unload_resources :: proc() {
|
||||||
rl.UnloadMaterial(player_sword_mat)
|
rl.UnloadMaterial(player_sword_mat)
|
||||||
//rl.UnloadTexture(player_sword_tex)
|
|
||||||
rl.UnloadMesh(player_sword_mesh)
|
rl.UnloadMesh(player_sword_mesh)
|
||||||
}
|
}
|
||||||
|
|
||||||
player_create :: proc() -> Player {
|
player_create :: proc() -> Player {
|
||||||
return Player {
|
return(
|
||||||
|
Player {
|
||||||
size = {0.5, 2, 0.5},
|
size = {0.5, 2, 0.5},
|
||||||
cameraOffset = {0, 1.8, 0},
|
cameraOffset = {0, 1.8, 0},
|
||||||
camera = rl.Camera3D {
|
camera = rl.Camera3D {
|
||||||
|
@ -46,7 +43,8 @@ player_create :: proc() -> Player {
|
||||||
target = {0, 0, 10},
|
target = {0, 0, 10},
|
||||||
projection = rl.CameraProjection.PERSPECTIVE,
|
projection = rl.CameraProjection.PERSPECTIVE,
|
||||||
},
|
},
|
||||||
}
|
} \
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
player_update :: proc(using player: ^Player, delta: f32) {
|
player_update :: proc(using player: ^Player, delta: f32) {
|
||||||
|
@ -78,11 +76,9 @@ player_update :: proc(using player: ^Player, delta: f32) {
|
||||||
velocity.xz = Vector3MoveTowards(velocity, motion * 100, 100 * delta).xz
|
velocity.xz = Vector3MoveTowards(velocity, motion * 100, 100 * delta).xz
|
||||||
position += velocity * delta
|
position += velocity * delta
|
||||||
|
|
||||||
|
// camera positioning, targetting and bobbing
|
||||||
//bob_position = Vec3{math.sin_f32(f32(bob_timer * math.PI * 2 + math.PI/4)), math.sin_f32(f32(bob_timer*math.PI * 4)), 0} * bob_factor * 0.3
|
|
||||||
bob_position = Vec3{0, math.sin_f32(f32(bob_timer * math.PI * 4)), 0} * bob_factor * 0.3
|
bob_position = Vec3{0, math.sin_f32(f32(bob_timer * math.PI * 4)), 0} * bob_factor * 0.3
|
||||||
bob_position = Vector3RotateByAxisAngle(bob_position, Vec3{0, 1, 0}, direction)
|
bob_position = Vector3RotateByAxisAngle(bob_position, Vec3{0, 1, 0}, direction)
|
||||||
|
|
||||||
camera.position = position + cameraOffset + bob_position
|
camera.position = position + cameraOffset + bob_position
|
||||||
target := Vec3 {
|
target := Vec3 {
|
||||||
math.sin(direction) * math.cos(yaw),
|
math.sin(direction) * math.cos(yaw),
|
||||||
|
@ -95,7 +91,6 @@ player_update :: proc(using player: ^Player, delta: f32) {
|
||||||
player_draw :: proc(using player: ^Player) {
|
player_draw :: proc(using player: ^Player) {
|
||||||
using rl
|
using rl
|
||||||
|
|
||||||
|
|
||||||
rlPushMatrix()
|
rlPushMatrix()
|
||||||
offset := position + cameraOffset + (bob_position / 2)
|
offset := position + cameraOffset + (bob_position / 2)
|
||||||
rlTranslatef(offset.x, offset.y, offset.z)
|
rlTranslatef(offset.x, offset.y, offset.z)
|
||||||
|
@ -108,8 +103,6 @@ player_draw :: proc(using player: ^Player) {
|
||||||
rlRotatef(210, 0, 1, 0)
|
rlRotatef(210, 0, 1, 0)
|
||||||
rlScalef(0.3, 0.3, 0.3)
|
rlScalef(0.3, 0.3, 0.3)
|
||||||
DrawMesh(player_sword_mesh, player_sword_mat, rl.Matrix(1))
|
DrawMesh(player_sword_mesh, player_sword_mat, rl.Matrix(1))
|
||||||
// DrawCube({0, 0, 0}, 1,1,1, PAL[4])
|
|
||||||
// DrawCube({0, 0, 0}, 1,1,1, PAL[4])
|
|
||||||
|
|
||||||
rlPopMatrix()
|
rlPopMatrix()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import rl "vendor:raylib"
|
|
||||||
import "core:slice"
|
|
||||||
import "core:path/filepath"
|
import "core:path/filepath"
|
||||||
|
import "core:slice"
|
||||||
|
import rl "vendor:raylib"
|
||||||
|
|
||||||
Textures :: map[string]rl.Texture
|
Textures :: map[string]rl.Texture
|
||||||
tex_filepaths: rl.FilePathList
|
tex_filepaths: rl.FilePathList
|
||||||
|
|
Loading…
Reference in New Issue