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

@@ -48,17 +48,38 @@ MAP_ActorSetP :: (actor: *MAP_Actor, p: V2I)
*new_tile |= MAP_TILE_ACTOR_IS_STANDING
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_CurrentMap.x = WinX / RectX
MAP_CurrentMap.y = WinY / RectY
bytes := sizeof(MAP_Tile) * MAP_CurrentMap.x->U64 * MAP_CurrentMap.y->U64
MAP_CurrentMap.data = malloc(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})
actor2.target_p = V2I{8,8}
actor := MAP_AddActor(&MAP_CurrentMap, MAP_GetRandomUnblockedP(&MAP_CurrentMap))
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)
if p.x < 0 || p.x >= s.map.x ;; return