Selection and setting target_p
This commit is contained in:
@@ -102,6 +102,7 @@ ANI_SetTiles: Array(ANI_SetTile)
|
||||
MouseSelecting := false
|
||||
MouseSelectionPivot: Vector2
|
||||
MouseSelectionBox: Rectangle
|
||||
MouseSelectedActors: Array(*MAP_Actor) // @todo: ids
|
||||
|
||||
main :: (): int
|
||||
MAP_Init()
|
||||
@@ -150,6 +151,13 @@ main :: (): int
|
||||
MouseP.y - MouseSelectionPivot.y
|
||||
}
|
||||
|
||||
if MouseSelectionBox.width < 0
|
||||
MouseSelectionBox.x += MouseSelectionBox.width
|
||||
MouseSelectionBox.width = -MouseSelectionBox.width
|
||||
if MouseSelectionBox.height < 0
|
||||
MouseSelectionBox.y += MouseSelectionBox.height
|
||||
MouseSelectionBox.height = -MouseSelectionBox.height
|
||||
|
||||
if IsKeyPressed(KEY_F1)
|
||||
Mode = 0
|
||||
|
||||
@@ -270,10 +278,30 @@ main :: (): int
|
||||
DrawCircleV(p0, 4, LIGHTGRAY)
|
||||
DrawCircleV(p1, 4, LIGHTGRAY)
|
||||
|
||||
if Mode == 1 && MouseSelecting
|
||||
COLOR_SelectionBox := GREEN
|
||||
COLOR_SelectionBox.a = 255/2
|
||||
DrawRectangleRec(MouseSelectionBox, COLOR_SelectionBox)
|
||||
if Mode == 1
|
||||
for actor_i := 0, actor_i < MouseSelectedActors.len, actor_i += 1
|
||||
actor_it := MouseSelectedActors.data[actor_i]
|
||||
actor_box := MAP_Rectangle(actor_it.p)
|
||||
DrawRectangleRec(actor_box, GREEN)
|
||||
|
||||
if IsMouseButtonPressed(MOUSE_BUTTON_RIGHT)
|
||||
p := MAP_ScreenToMap(MouseP)
|
||||
MAP_SetTargetP(actor_it, p)
|
||||
|
||||
if MouseSelecting
|
||||
Reset(&MouseSelectedActors)
|
||||
COLOR_SelectionBox := GREEN
|
||||
COLOR_SelectionBox.a = 255/2
|
||||
|
||||
for actor_i := 0, actor_i < map.actors.len, actor_i += 1
|
||||
actor_it := map.actors.data + actor_i
|
||||
actor_box := MAP_Rectangle(actor_it.p)
|
||||
|
||||
if CheckCollisionRecs(actor_box, MouseSelectionBox)
|
||||
Add(&MouseSelectedActors, actor_it)
|
||||
|
||||
DrawRectangleRec(MouseSelectionBox, COLOR_SelectionBox)
|
||||
|
||||
|
||||
menu_open := false
|
||||
if menu_open
|
||||
|
||||
@@ -37,6 +37,12 @@ MAP_Circle :: (p: V2I): Vector2
|
||||
result := Vector2{p.x->F32 * RectX + RectX/2, p.y->F32 * RectY + RectY/2}
|
||||
return result
|
||||
|
||||
MAP_ScreenToMap :: (p: Vector2): V2I
|
||||
p0 := p.x / RectX
|
||||
p1 := p.y / RectY
|
||||
result := V2I{p0->int, p1->int}
|
||||
return result
|
||||
|
||||
MAP_AddActor :: (map: *MAP_Map, p: V2I): *MAP_Actor
|
||||
Add(&map.actors, {p, p, map})
|
||||
Assert(map.data[p.x + p.y * map.x] == 0)
|
||||
@@ -61,6 +67,13 @@ MAP_ActorSetP :: (actor: *MAP_Actor, p: V2I)
|
||||
Reset(&actor.open_paths)
|
||||
Reset(&actor.close_paths)
|
||||
|
||||
MAP_SetTargetP :: (s: *MAP_Actor, p: V2I)
|
||||
s.target_p = p
|
||||
Reset(&s.tiles_visited)
|
||||
Reset(&s.history)
|
||||
Reset(&s.open_paths)
|
||||
Reset(&s.close_paths)
|
||||
|
||||
MAP_GetRandomP :: (m: *MAP_Map): V2I
|
||||
result := V2I{GetRandomValue(0, MAP_CurrentMap.x), GetRandomValue(0, MAP_CurrentMap.y)}
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user