From 2d5c2d89bc100ef9bb7ecd4cb1c360a703155b6f Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Wed, 19 Apr 2023 15:01:43 +0200 Subject: [PATCH] RTS: Trail --- build/rtsgame/main.core | 69 +++++++++++++++++++++++++---------------- build/rtsgame/map.core | 3 ++ 2 files changed, 46 insertions(+), 26 deletions(-) diff --git a/build/rtsgame/main.core b/build/rtsgame/main.core index 35615a0..14ff9ca 100644 --- a/build/rtsgame/main.core +++ b/build/rtsgame/main.core @@ -77,9 +77,7 @@ Add(&guys, {100, 100}) #load "array.core" #load "map.core" -V2I :: struct - x: int - y: int +V2I :: struct ;; x: int; y: int WinX := 1280 WinY := 720 @@ -108,6 +106,21 @@ main :: (): int InitWindow(WinX, WinY, "Testing") 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() WinX = GetScreenWidth() WinY = GetScreenHeight() @@ -117,12 +130,6 @@ main :: (): int Dt = GetFrameTime() map := &MAP_CurrentMap - orange := ORANGE - orange.a = 255/2 - - brown := BROWN - brown.a = 255/2 - if IsKeyPressed(KEY_F1) ;; Mode = 0 if IsKeyPressed(KEY_F2) ;; Mode = 1 @@ -203,11 +210,20 @@ main :: (): int for i := 0, i < map.actors.len, i += 1 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} - DrawRectangleRec(r, YELLOW) - DrawRectangleRec(target_r, PURPLE) + main_p := Vector2{actor_it.p.x->F32 * RectX + RectX/2, actor_it.p.y->F32 * RectY + RectY/2} + 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 path_it := actor_it.open_paths.data + path_i @@ -237,22 +253,23 @@ main :: (): int DrawCircleV(p0, 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 - text_p := 4 - text_y := WinY - text_size + DrawText("Space :: PathFind", text_p, text_y, text_size, GRAY) + text_y -= 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) - text_y -= text_size - DrawText("F4 :: Randomize actors", text_p, text_y, text_size, GRAY) - text_y -= text_size - - DrawText("F3 :: Simulate actors", text_p, text_y, text_size, GRAY) - 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 + DrawText("F3 :: Simulate actors", text_p, text_y, text_size, GRAY) + text_y -= text_size + text: *char = "Mode(F1) :: Block placing" + if Mode == 1 ;; text = "Mode(F2) :: Actor placing" + DrawText(text, text_p, text_y, text_size, GRAY) + text_y -= text_size diff --git a/build/rtsgame/map.core b/build/rtsgame/map.core index 9732755..2e1d355 100644 --- a/build/rtsgame/map.core +++ b/build/rtsgame/map.core @@ -22,6 +22,7 @@ MAP_Actor :: struct state: int open_paths: Array(MAP_Path) close_paths: Array(MAP_Path) + tiles_visited: Array(V2I) history: Array(MAP_Path) MAP_Path :: struct @@ -127,6 +128,8 @@ MAP_MoveTowardsTarget :: (s: *MAP_Actor) *tile &= ~MAP_TILE_ACTOR_IS_STANDING Assert((*tile & MAP_TILE_ACTOR_IS_STANDING) == 0) + Add(&s.tiles_visited, s.p) + step := s.history.data[s.history.len-2] s.p = step.p