RTS: Trail

This commit is contained in:
Krzosa Karol
2023-04-19 15:01:43 +02:00
parent b7385221ac
commit 2d5c2d89bc
2 changed files with 46 additions and 26 deletions

View File

@@ -77,9 +77,7 @@ Add(&guys, {100, 100})
#load "array.core" #load "array.core"
#load "map.core" #load "map.core"
V2I :: struct V2I :: struct ;; x: int; y: int
x: int
y: int
WinX := 1280 WinX := 1280
WinY := 720 WinY := 720
@@ -108,6 +106,21 @@ main :: (): int
InitWindow(WinX, WinY, "Testing") InitWindow(WinX, WinY, "Testing")
SetTargetFPS(60) SetTargetFPS(60)
orange := ORANGE
orange.a = 255/2
brown := BROWN
brown.a = 255/2
actor_color := GREEN
actor_color.a = 255/2
past_actor_color := BLUE
past_actor_color.a = 255/2
target_color := RED
target_color.a = 255/2
for !WindowShouldClose() for !WindowShouldClose()
WinX = GetScreenWidth() WinX = GetScreenWidth()
WinY = GetScreenHeight() WinY = GetScreenHeight()
@@ -117,12 +130,6 @@ main :: (): int
Dt = GetFrameTime() Dt = GetFrameTime()
map := &MAP_CurrentMap map := &MAP_CurrentMap
orange := ORANGE
orange.a = 255/2
brown := BROWN
brown.a = 255/2
if IsKeyPressed(KEY_F1) ;; Mode = 0 if IsKeyPressed(KEY_F1) ;; Mode = 0
if IsKeyPressed(KEY_F2) ;; Mode = 1 if IsKeyPressed(KEY_F2) ;; Mode = 1
@@ -203,11 +210,20 @@ main :: (): int
for i := 0, i < map.actors.len, i += 1 for i := 0, i < map.actors.len, i += 1
actor_it := map.actors.data + i actor_it := map.actors.data + i
r := Rectangle{actor_it.p.x->F32 * RectX, actor_it.p.y->F32 * RectY, RectX, RectY} // r := Rectangle{actor_it.p.x->F32 * RectX, actor_it.p.y->F32 * RectY, RectX, RectY}
target_r := Rectangle{actor_it.target_p.x->F32 * RectX, actor_it.target_p.y->F32 * RectY, RectX, RectY} target_r := Rectangle{actor_it.target_p.x->F32 * RectX, actor_it.target_p.y->F32 * RectY, RectX, RectY}
DrawRectangleRec(r, YELLOW) main_p := Vector2{actor_it.p.x->F32 * RectX + RectX/2, actor_it.p.y->F32 * RectY + RectY/2}
DrawRectangleRec(target_r, PURPLE) DrawCircleV(main_p, RectX/3, actor_color)
// DrawRectangleRec(r, actor_color)
DrawRectangleRec(target_r, target_color)
smaller_the_further: F32 = 0
for tile_i := actor_it.tiles_visited.len - 1, tile_i >= 0, tile_i -= 1
tile_it := actor_it.tiles_visited.data + tile_i
p := Vector2{tile_it.x->F32 * RectX + RectX/2, tile_it.y->F32 * RectY + RectY/2}
DrawCircleV(p, RectX/3 - smaller_the_further, past_actor_color)
smaller_the_further += 0.3
for path_i := 0, path_i < actor_it.open_paths.len, path_i += 1 for path_i := 0, path_i < actor_it.open_paths.len, path_i += 1
path_it := actor_it.open_paths.data + path_i path_it := actor_it.open_paths.data + path_i
@@ -237,22 +253,23 @@ main :: (): int
DrawCircleV(p0, 4, LIGHTGRAY) DrawCircleV(p0, 4, LIGHTGRAY)
DrawCircleV(p1, 4, LIGHTGRAY) DrawCircleV(p1, 4, LIGHTGRAY)
menu_open := false
if menu_open
text_size := 24
text_p := 4
text_y := WinY - text_size
text_size := 24 DrawText("Space :: PathFind", text_p, text_y, text_size, GRAY)
text_p := 4 text_y -= text_size
text_y := WinY - text_size DrawText("F4 :: Randomize actors", text_p, text_y, text_size, GRAY)
text_y -= text_size
DrawText("Space :: PathFind", text_p, text_y, text_size, GRAY) DrawText("F3 :: Simulate actors", text_p, text_y, text_size, GRAY)
text_y -= text_size text_y -= text_size
DrawText("F4 :: Randomize actors", text_p, text_y, text_size, GRAY) text: *char = "Mode(F1) :: Block placing"
text_y -= text_size if Mode == 1 ;; text = "Mode(F2) :: Actor placing"
DrawText(text, text_p, text_y, text_size, GRAY)
DrawText("F3 :: Simulate actors", text_p, text_y, text_size, GRAY) text_y -= text_size
text_y -= text_size
text: *char = "F1 :: Block placing"
if Mode == 1 ;; text = "F2 :: Actor placing"
DrawText(text, text_p, text_y, text_size, GRAY)
text_y -= text_size

View File

@@ -22,6 +22,7 @@ MAP_Actor :: struct
state: int state: int
open_paths: Array(MAP_Path) open_paths: Array(MAP_Path)
close_paths: Array(MAP_Path) close_paths: Array(MAP_Path)
tiles_visited: Array(V2I)
history: Array(MAP_Path) history: Array(MAP_Path)
MAP_Path :: struct MAP_Path :: struct
@@ -127,6 +128,8 @@ MAP_MoveTowardsTarget :: (s: *MAP_Actor)
*tile &= ~MAP_TILE_ACTOR_IS_STANDING *tile &= ~MAP_TILE_ACTOR_IS_STANDING
Assert((*tile & MAP_TILE_ACTOR_IS_STANDING) == 0) Assert((*tile & MAP_TILE_ACTOR_IS_STANDING) == 0)
Add(&s.tiles_visited, s.p)
step := s.history.data[s.history.len-2] step := s.history.data[s.history.len-2]
s.p = step.p s.p = step.p