Core RTS: Multiple actors
This commit is contained in:
@@ -155,11 +155,16 @@ main :: (): int
|
||||
path_r := Rectangle{path_it.p.x->F32 * RectX, path_it.p.y->F32 * RectY, RectX, RectY}
|
||||
DrawRectangleRec(path_r, ORANGE)
|
||||
|
||||
if actor_it.state == MAP_PATH_REACHED
|
||||
for path_i := 0, path_i < actor_it.history.len, path_i += 1
|
||||
path_it := actor_it.history.data + path_i
|
||||
path_r := Rectangle{path_it.p.x->F32 * RectX, path_it.p.y->F32 * RectY, RectX, RectY}
|
||||
DrawRectangleRec(path_r, BLACK)
|
||||
for path_i := 0, path_i < actor_it.close_paths.len, path_i += 1
|
||||
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}
|
||||
DrawRectangleRec(path_r, BROWN)
|
||||
|
||||
MAP_RecomputeHistory(actor_it)
|
||||
for path_i := 0, path_i < actor_it.history.len, path_i += 1
|
||||
path_it := actor_it.history.data + path_i
|
||||
path_r := Rectangle{path_it.p.x->F32 * RectX, path_it.p.y->F32 * RectY, RectX, RectY}
|
||||
DrawRectangleRec(path_r, BLACK)
|
||||
|
||||
|
||||
if Mode == 0 ;; DrawText("F1", 0, 0, 32, BLACK)
|
||||
|
||||
@@ -45,6 +45,9 @@ MAP_Init :: ()
|
||||
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}
|
||||
|
||||
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.y < 0 || p.y >= s.map.y ;; return
|
||||
@@ -72,11 +75,22 @@ MAP_GetCloseP :: (s: *MAP_Actor, p: V2I): *MAP_Path
|
||||
Assert(false)
|
||||
return 0
|
||||
|
||||
MAP_RecomputeHistory :: (s: *MAP_Actor)
|
||||
if s.close_paths.len > 1
|
||||
Reset(&s.history)
|
||||
it := GetLast(&s.close_paths)
|
||||
Add(&s.history, *it)
|
||||
for !(it.p.x == s.p.x && it.p.y == s.p.y)
|
||||
it = MAP_GetCloseP(s, it.came_from)
|
||||
Add(&s.history, *it)
|
||||
|
||||
MAP_MoveTowardsTarget :: (s: *MAP_Actor)
|
||||
if s.history.len != 1
|
||||
tile := s.map.data + s.p.x + s.p.y * s.map.x
|
||||
Assert((*tile & MAP_TILE_ACTOR_IS_STANDING) != 0)
|
||||
Assert((*tile & MAP_TILE_BLOCKER) == 0)
|
||||
tile := s.map.data + s.p.x + s.p.y * s.map.x
|
||||
Assert((*tile & MAP_TILE_ACTOR_IS_STANDING) != 0)
|
||||
Assert((*tile & MAP_TILE_BLOCKER) == 0)
|
||||
|
||||
MAP_RecomputeHistory(s)
|
||||
if s.history.len > 1
|
||||
*tile &= ~MAP_TILE_ACTOR_IS_STANDING
|
||||
Assert((*tile & MAP_TILE_ACTOR_IS_STANDING) == 0)
|
||||
|
||||
@@ -103,10 +117,6 @@ MAP_PathFindStep :: (s: *MAP_Actor)
|
||||
reached_target := it.p.x == s.target_p.x && it.p.y == s.target_p.y
|
||||
if reached_target
|
||||
s.state = MAP_PATH_REACHED
|
||||
Add(&s.history, it)
|
||||
for !(it.p.x == s.p.x && it.p.y == s.p.y)
|
||||
it = *MAP_GetCloseP(s, it.came_from)
|
||||
Add(&s.history, it)
|
||||
return
|
||||
|
||||
// @language_todo: Add continue keyword
|
||||
|
||||
Reference in New Issue
Block a user