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