update gitignore and commit new files to vcs
This commit is contained in:
parent
0fa4bb23e9
commit
2e9b930783
7 changed files with 175 additions and 39 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -0,0 +1,3 @@
|
||||||
|
*.exe
|
||||||
|
*.rdi
|
||||||
|
*.bin
|
||||||
|
|
@ -126,7 +126,7 @@ draw_entities :: proc() {
|
||||||
})
|
})
|
||||||
for e in entities {
|
for e in entities {
|
||||||
if .Allocated not_in e.flags {continue}
|
if .Allocated not_in e.flags {continue}
|
||||||
#partial switch &data in e.data {
|
#partial switch data in e.data {
|
||||||
case TileData:
|
case TileData:
|
||||||
draw_tile(e)
|
draw_tile(e)
|
||||||
}
|
}
|
||||||
|
|
@ -137,7 +137,7 @@ draw_entities :: proc() {
|
||||||
// Draw debug circle
|
// Draw debug circle
|
||||||
//rl.DrawCircleV(e.pos, 1, rl.RED)
|
//rl.DrawCircleV(e.pos, 1, rl.RED)
|
||||||
|
|
||||||
switch &data in e.data {
|
switch data in e.data {
|
||||||
case TileData:
|
case TileData:
|
||||||
draw_tile_plant(e)
|
draw_tile_plant(e)
|
||||||
case PlayerData:
|
case PlayerData:
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,8 @@ tween_ctx_vec2: t.TweenContext([2]f32)
|
||||||
player_inventory: [InventoryItem]int
|
player_inventory: [InventoryItem]int
|
||||||
hotbar: Hotbar
|
hotbar: Hotbar
|
||||||
|
|
||||||
|
should_run: bool = true
|
||||||
|
|
||||||
InventoryItem :: enum {
|
InventoryItem :: enum {
|
||||||
//Tools
|
//Tools
|
||||||
hoe,
|
hoe,
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package game
|
package game
|
||||||
|
|
||||||
import t "../tween"
|
// import t "../tween"
|
||||||
import "core:fmt"
|
import "core:fmt"
|
||||||
import "core:log"
|
import "core:log"
|
||||||
import "core:mem"
|
import "core:mem"
|
||||||
|
|
@ -41,6 +41,17 @@ main :: proc() {
|
||||||
}
|
}
|
||||||
|
|
||||||
run :: proc() {
|
run :: proc() {
|
||||||
|
init()
|
||||||
|
defer shutdown()
|
||||||
|
|
||||||
|
for should_run {
|
||||||
|
free_all(context.temp_allocator)
|
||||||
|
update()
|
||||||
|
draw()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
init :: proc() {
|
||||||
rl.SetConfigFlags({.VSYNC_HINT, .WINDOW_RESIZABLE, .MSAA_4X_HINT})
|
rl.SetConfigFlags({.VSYNC_HINT, .WINDOW_RESIZABLE, .MSAA_4X_HINT})
|
||||||
rl.InitWindow(1280, 720, "Raylib Minimal")
|
rl.InitWindow(1280, 720, "Raylib Minimal")
|
||||||
rl.SetTargetFPS(rl.GetMonitorRefreshRate(rl.GetCurrentMonitor()))
|
rl.SetTargetFPS(rl.GetMonitorRefreshRate(rl.GetCurrentMonitor()))
|
||||||
|
|
@ -53,24 +64,22 @@ run :: proc() {
|
||||||
}
|
}
|
||||||
|
|
||||||
load_resources()
|
load_resources()
|
||||||
|
|
||||||
for !rl.WindowShouldClose() {
|
|
||||||
free_all(context.temp_allocator)
|
|
||||||
update()
|
|
||||||
draw()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
shutdown :: proc() {
|
||||||
free_resources()
|
free_resources()
|
||||||
rl.CloseAudioDevice()
|
rl.CloseAudioDevice()
|
||||||
rl.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
||||||
update :: proc() {
|
update :: proc() {
|
||||||
|
dt := rl.GetFrameTime()
|
||||||
|
|
||||||
// :tween update
|
// :tween update
|
||||||
t.tween_update(&tween_ctx_f32, auto_cast rl.GetFrameTime())
|
tick_tweens(dt)
|
||||||
t.tween_update(&tween_ctx_vec2, auto_cast rl.GetFrameTime())
|
|
||||||
|
|
||||||
// :scaling update
|
// :scaling update
|
||||||
|
{
|
||||||
screen_width := rl.GetScreenWidth()
|
screen_width := rl.GetScreenWidth()
|
||||||
screen_height := rl.GetScreenHeight()
|
screen_height := rl.GetScreenHeight()
|
||||||
screen_scale = min(
|
screen_scale = min(
|
||||||
|
|
@ -79,7 +88,8 @@ update :: proc() {
|
||||||
)
|
)
|
||||||
mouse := rl.GetMousePosition()
|
mouse := rl.GetMousePosition()
|
||||||
virtual_mouse := rl.Vector2 {
|
virtual_mouse := rl.Vector2 {
|
||||||
(mouse.x - (f32(screen_width) - (GAME_SCREEN_WIDTH * screen_scale)) * 0.5) / screen_scale,
|
(mouse.x - (f32(screen_width) - (GAME_SCREEN_WIDTH * screen_scale)) * 0.5) /
|
||||||
|
screen_scale,
|
||||||
(mouse.y - (f32(screen_height) - (GAME_SCREEN_HEIGHT * screen_scale)) * 0.5) /
|
(mouse.y - (f32(screen_height) - (GAME_SCREEN_HEIGHT * screen_scale)) * 0.5) /
|
||||||
screen_scale,
|
screen_scale,
|
||||||
}
|
}
|
||||||
|
|
@ -96,12 +106,15 @@ update :: proc() {
|
||||||
GAME_SCREEN_HEIGHT * screen_scale,
|
GAME_SCREEN_HEIGHT * screen_scale,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// :hotbar update
|
||||||
update_hotbar()
|
update_hotbar()
|
||||||
|
|
||||||
// :animation update
|
// :animation update
|
||||||
update_entities()
|
update_entities()
|
||||||
|
|
||||||
// :sell
|
// :sell button update
|
||||||
hover_sell_button := rl.CheckCollisionPointRec(
|
hover_sell_button := rl.CheckCollisionPointRec(
|
||||||
world_mouse,
|
world_mouse,
|
||||||
{SELL_BUTTON_POS.x, SELL_BUTTON_POS.y, TILE_SIZE * 2, TILE_SIZE * 2},
|
{SELL_BUTTON_POS.x, SELL_BUTTON_POS.y, TILE_SIZE * 2, TILE_SIZE * 2},
|
||||||
|
|
|
||||||
39
src/sequencer.odin
Normal file
39
src/sequencer.odin
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
package game
|
||||||
|
|
||||||
|
sequences: [dynamic]Sequence
|
||||||
|
|
||||||
|
Seq_Payload :: union {
|
||||||
|
SEQ_MOVE_CIRCLE,
|
||||||
|
}
|
||||||
|
|
||||||
|
SEQ_MOVE_CIRCLE :: struct {
|
||||||
|
pos: ^[2]f32,
|
||||||
|
target_pos: [2]f32,
|
||||||
|
duration: f32,
|
||||||
|
}
|
||||||
|
|
||||||
|
Sequence :: struct {
|
||||||
|
delay: f32,
|
||||||
|
payload: Seq_Payload,
|
||||||
|
}
|
||||||
|
|
||||||
|
add_seq :: proc(sequences: ^[dynamic]Sequence, delay: f32, payload: Seq_Payload) -> f32 {
|
||||||
|
append_elem(sequences, Sequence{delay = delay, payload = payload})
|
||||||
|
return delay
|
||||||
|
}
|
||||||
|
|
||||||
|
tick_sequences :: proc(sequences: ^[dynamic]Sequence, dt: f32) {
|
||||||
|
if len(sequences) == 0 do return
|
||||||
|
|
||||||
|
seq := &sequences[0]
|
||||||
|
seq.delay -= dt
|
||||||
|
if seq.delay <= 0.0 {
|
||||||
|
switch s in seq.payload
|
||||||
|
{
|
||||||
|
case SEQ_MOVE_CIRCLE:
|
||||||
|
add_vector2_tween(s.pos, s.target_pos, s.duration, .IN_OUT_QUAD)
|
||||||
|
}
|
||||||
|
|
||||||
|
ordered_remove(sequences, 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
78
src/tween.odin
Normal file
78
src/tween.odin
Normal file
|
|
@ -0,0 +1,78 @@
|
||||||
|
package game
|
||||||
|
|
||||||
|
import "core:math"
|
||||||
|
import "core:log"
|
||||||
|
|
||||||
|
// :tweening
|
||||||
|
Tween_Func :: enum {
|
||||||
|
LINEAR,
|
||||||
|
IN_OUT_QUAD,
|
||||||
|
}
|
||||||
|
|
||||||
|
Tween :: struct {
|
||||||
|
ptr: ^f32,
|
||||||
|
start: f32,
|
||||||
|
target: f32,
|
||||||
|
duration: f32,
|
||||||
|
time: f32,
|
||||||
|
eval: proc(x: f32) -> f32,
|
||||||
|
}
|
||||||
|
|
||||||
|
tweens: [dynamic]Tween
|
||||||
|
|
||||||
|
append_ret :: proc(container: ^$T/[dynamic]$E, element: E) -> ^E {
|
||||||
|
append(container, element)
|
||||||
|
return &container[len(container) - 1]
|
||||||
|
}
|
||||||
|
|
||||||
|
add_f32_tween :: proc(ptr: ^f32, target: f32, duration: f32, func: Tween_Func) {
|
||||||
|
tween := append_ret(&tweens, Tween{})
|
||||||
|
tween.ptr = ptr
|
||||||
|
tween.start = ptr^
|
||||||
|
tween.target = target
|
||||||
|
tween.duration = duration
|
||||||
|
|
||||||
|
switch func {
|
||||||
|
case .LINEAR:
|
||||||
|
tween.eval = proc(x: f32) -> f32 {return x}
|
||||||
|
|
||||||
|
case .IN_OUT_QUAD:
|
||||||
|
tween.eval = proc(x: f32) -> f32 {
|
||||||
|
log.infof("x = {}", x)
|
||||||
|
if x < 0.5 {
|
||||||
|
return x * x * 2.0
|
||||||
|
} else {
|
||||||
|
return 1.0 - math.pow(-2.0 * x + 2.0, 2.0) / 2.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info(tween.eval)
|
||||||
|
}
|
||||||
|
|
||||||
|
add_vector2_tween :: proc(ptr: ^[2]f32, target: [2]f32, duration: f32, func: Tween_Func) {
|
||||||
|
add_f32_tween(&ptr.x, target.x, duration, func)
|
||||||
|
add_f32_tween(&ptr.y, target.y, duration, func)
|
||||||
|
}
|
||||||
|
|
||||||
|
tick_tweens :: proc(dt: f32) {
|
||||||
|
for i := 0; i < len(tweens); i += 1 {
|
||||||
|
log.infof("i = {}", i)
|
||||||
|
|
||||||
|
tween := &tweens[i]
|
||||||
|
|
||||||
|
tween.time = math.min(tween.time + dt, tween.duration)
|
||||||
|
log.info(1)
|
||||||
|
log.info(tween.eval)
|
||||||
|
t := tween.eval(tween.time / tween.duration)
|
||||||
|
log.info(2)
|
||||||
|
log.infof("t = {}", t)
|
||||||
|
tween.ptr^ = math.lerp(tween.start, tween.target, t)
|
||||||
|
log.info(3)
|
||||||
|
|
||||||
|
if t == 1.0 {
|
||||||
|
unordered_remove(&tweens, i)
|
||||||
|
i -= 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
1
src/utils.odin
Normal file
1
src/utils.odin
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
package game
|
||||||
Loading…
Add table
Add a link
Reference in a new issue