Core RTS :: Randomizing positions, improving visuals, info

This commit is contained in:
Krzosa Karol
2023-04-19 13:20:35 +02:00
parent 87657a99a6
commit b7385221ac
2 changed files with 51 additions and 8 deletions

View File

@@ -117,6 +117,12 @@ 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
@@ -124,6 +130,8 @@ main :: (): int
for i := 0, i < map.actors.len, i += 1 for i := 0, i < map.actors.len, i += 1
it := map.actors.data + i it := map.actors.data + i
MAP_MoveTowardsTarget(it) MAP_MoveTowardsTarget(it)
if IsKeyPressed(KEY_F4)
MAP_RandomizeActors()
if IsKeyDown(KEY_SPACE) if IsKeyDown(KEY_SPACE)
for i := 0, i < map.actors.len, i += 1 for i := 0, i < map.actors.len, i += 1
it := map.actors.data + i it := map.actors.data + i
@@ -204,12 +212,12 @@ main :: (): int
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
path_r := Rectangle{path_it.p.x->F32 * RectX, path_it.p.y->F32 * RectY, RectX, RectY} path_r := Rectangle{path_it.p.x->F32 * RectX, path_it.p.y->F32 * RectY, RectX, RectY}
DrawRectangleRec(path_r, ORANGE) DrawRectangleRec(path_r, orange)
for path_i := 0, path_i < actor_it.close_paths.len, path_i += 1 for path_i := 0, path_i < actor_it.close_paths.len, path_i += 1
path_it := actor_it.close_paths.data + path_i path_it := actor_it.close_paths.data + path_i
path_r := Rectangle{path_it.p.x->F32 * RectX, path_it.p.y->F32 * RectY, RectX, RectY} path_r := Rectangle{path_it.p.x->F32 * RectX, path_it.p.y->F32 * RectY, RectX, RectY}
DrawRectangleRec(path_r, BROWN) DrawRectangleRec(path_r, brown)
MAP_RecomputeHistory(actor_it) MAP_RecomputeHistory(actor_it)
for path_i := 0, path_i < actor_it.history.len, path_i += 1 for path_i := 0, path_i < actor_it.history.len, path_i += 1
@@ -230,8 +238,22 @@ main :: (): int
DrawCircleV(p1, 4, LIGHTGRAY) DrawCircleV(p1, 4, LIGHTGRAY)
if Mode == 0 ;; DrawText("F1", 0, 0, 32, BLACK) text_size := 24
if Mode == 1 ;; DrawText("F2", 0, 0, 32, BLACK) 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("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
EndDrawing() EndDrawing()

View File

@@ -48,17 +48,38 @@ MAP_ActorSetP :: (actor: *MAP_Actor, p: V2I)
*new_tile |= MAP_TILE_ACTOR_IS_STANDING *new_tile |= MAP_TILE_ACTOR_IS_STANDING
actor.p = p actor.p = p
MAP_GetRandomP :: (m: *MAP_Map): V2I
result := V2I{GetRandomValue(0, MAP_CurrentMap.x), GetRandomValue(0, MAP_CurrentMap.y)}
return result
MAP_GetRandomUnblockedP :: (m: *MAP_Map): V2I
for i := 0, i < 128, i += 1
p := MAP_GetRandomP(m)
if m.data[p.x + p.y * m.x] == 0
return p
Assert(false, "Invalid codepath")
r: V2I; return r
MAP_Init :: () MAP_Init :: ()
MAP_CurrentMap.x = WinX / RectX MAP_CurrentMap.x = WinX / RectX
MAP_CurrentMap.y = WinY / RectY MAP_CurrentMap.y = WinY / RectY
bytes := sizeof(MAP_Tile) * MAP_CurrentMap.x->U64 * MAP_CurrentMap.y->U64 bytes := sizeof(MAP_Tile) * MAP_CurrentMap.x->U64 * MAP_CurrentMap.y->U64
MAP_CurrentMap.data = malloc(bytes) MAP_CurrentMap.data = malloc(bytes)
memset(MAP_CurrentMap.data, 0, bytes) memset(MAP_CurrentMap.data, 0, bytes)
actor := MAP_AddActor(&MAP_CurrentMap, {4,4})
actor.target_p = V2I{8,8}
actor2 := MAP_AddActor(&MAP_CurrentMap, {16,16}) actor := MAP_AddActor(&MAP_CurrentMap, MAP_GetRandomUnblockedP(&MAP_CurrentMap))
actor2.target_p = V2I{8,8} actor.target_p = MAP_GetRandomUnblockedP(&MAP_CurrentMap)
actor2 := MAP_AddActor(&MAP_CurrentMap, MAP_GetRandomUnblockedP(&MAP_CurrentMap))
actor2.target_p = MAP_GetRandomUnblockedP(&MAP_CurrentMap)
MAP_RandomizeActors :: ()
map := &MAP_CurrentMap
for i := 0, i < map.actors.len, i += 1
it := map.actors.data + i
it.p = MAP_GetRandomUnblockedP(&MAP_CurrentMap)
it.target_p = MAP_GetRandomUnblockedP(&MAP_CurrentMap)
MAP_InsertOpenPath :: (s: *MAP_Actor, p: V2I, came_from: V2I, ignore_blocks: bool = false) MAP_InsertOpenPath :: (s: *MAP_Actor, p: V2I, came_from: V2I, ignore_blocks: bool = false)
if p.x < 0 || p.x >= s.map.x ;; return if p.x < 0 || p.x >= s.map.x ;; return