Skip to content

Commit 7f74e10

Browse files
committed
Display A* stats on player tile with semi-transparency
1 parent 1986413 commit 7f74e10

File tree

2 files changed

+66
-17
lines changed

2 files changed

+66
-17
lines changed

assets/css/tile_map.css

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,38 @@
11
body {
22
font-family: sans-serif;
33
}
4+
45
* {
56
margin: 0;
67
padding: 0;
78
}
9+
810
h3 {
911
margin: 1em;
1012
text-align: center;
1113
}
14+
15+
.semi-transparent {
16+
opacity: 0.5;
17+
}
18+
1219
div.tilemap-container {
1320
display: flex;
1421
flex-flow: column wrap;
1522
justify-content: baseline;
1623
}
24+
1725
div.tile_map {
1826
background-color: black;
1927
display: table;
2028
table-layout: fixed;
2129
width: min-content;
2230
}
31+
2332
div.tile_map div.row {
2433
display: table-row;
2534
}
35+
2636
div.tile_map div.tile {
2737
width: 64px;
2838
height: 64px;
@@ -33,14 +43,18 @@ div.tile_map div.tile {
3343
border-bottom: none;
3444
text-align: center;
3545
}
36-
div.tile_map div.tile img, div.tile_map div.tile div {
46+
47+
div.tile_map div.tile img,
48+
div.tile_map div.tile div {
3749
height: 64px;
3850
width: 64px;
3951
position: absolute;
4052
}
53+
4154
div.tile_map div.tile img {
4255
position: static;
4356
}
57+
4458
div.tile_map div.tile .tile-position {
4559
background-color: black;
4660
color: white;
@@ -52,75 +66,97 @@ div.tile_map div.tile .tile-position {
5266
font-size: 8px;
5367
text-align: center;
5468
}
69+
5570
div.tile_map div.tile.tile-clear {
5671
background-color: sandybrown;
5772
cursor: pointer;
5873
}
74+
5975
div.tile_map div.tile div.tile-wall {
6076
background-color: saddlebrown;
6177
cursor: not-allowed;
6278
}
63-
div.tile_map div.tile div.entity, div.tile_map div.tile div.target, div.tile_map div.tile div.open_list {
79+
80+
div.tile_map div.tile div.entity,
81+
div.tile_map div.tile div.target,
82+
div.tile_map div.tile div.open_list {
6483
width: 64px;
6584
height: 64px;
6685
}
86+
6787
div.tile_map div.tile div.entity-player {
6888
display: flex;
6989
justify-content: space-around;
7090
}
91+
7192
div.tile_map div.tile div.entity-player span {
7293
margin: auto;
7394
}
95+
7496
div.tile_map div.tile div.target {
7597
display: flex;
7698
justify-content: space-around;
7799
}
100+
78101
div.tile_map div.tile div.target span {
79102
margin: auto;
80103
}
104+
81105
div.tile_map div.tile div.path {
106+
background-color: white;
82107
display: flex;
83108
justify-content: space-around;
84109
}
110+
85111
div.tile_map div.tile div.path span {
86112
margin: auto;
87113
}
114+
88115
div.tile_map div.tile div.open_list {
89116
background-color: lightblue;
90117
}
118+
91119
div.tile_map div.tile div.closed_list {
92120
background-color: orange;
93121
}
122+
94123
div.tile_map div.tile div.info-container {
95124
display: flex;
96125
flex-flow: row wrap;
97126
justify-content: space-evenly;
98127
}
128+
99129
div.tile_map div.tile div.info-container span.span-g {
100130
width: 50%;
101131
text-align: left;
102132
}
133+
103134
div.tile_map div.tile div.info-container span.span-h {
104135
width: 50%;
105136
text-align: right;
106137
}
138+
107139
div.tile_map div.tile div.info-container span.span-f {
108140
font-size: 1.4em;
109141
}
142+
110143
div.toolbar {
111144
flex: auto;
112145
display: flex;
113146
flex-flow: row nowrap;
114147
justify-content: left;
115148
}
149+
116150
div.toolbar button {
117151
cursor: pointer;
118152
}
153+
119154
div.toolbar * {
120155
margin: 0.5rem;
121156
padding: 0.5rem;
122157
font-size: 1.4em;
123158
}
159+
124160
ul.entities-list {
125161
background-color: black;
126162
color: white;

lib/path_demo_web/live/map_live.ex

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ defmodule PathDemoWeb.MapLive do
2020

2121
map_type = Map.get(params, "map", "small")
2222

23-
tile_map = case map_type do
24-
"small" ->
25-
SmallMapGenerator.build(12, 12)
26-
"complex" ->
27-
ComplexMapGenerator.build()
28-
end
23+
tile_map =
24+
case map_type do
25+
"small" ->
26+
SmallMapGenerator.build(12, 12)
27+
28+
"complex" ->
29+
ComplexMapGenerator.build()
30+
end
2931

3032
player = tile_map.entities |> Enum.find(fn entity -> entity.type == "player" end)
3133
Pathfinder.set_position(worker_name, player.position)
@@ -74,14 +76,6 @@ defmodule PathDemoWeb.MapLive do
7476
<%= display_tile_position(tile.position) %>
7577
</span>
7678
<%= cond do %>
77-
<% tile_has_player?(@player_position, tile.position) -> %>
78-
<div class="entity entity-player">
79-
<span>🤖</span>
80-
</div>
81-
<% tile_is_target?(@player_target, tile.position) -> %>
82-
<div class="target">
83-
<span>👀</span>
84-
</div>
8579
<% tile_in_final_path?(@path, tile.position) -> %>
8680
<div class="path">
8781
<span>🦶</span>
@@ -101,7 +95,14 @@ defmodule PathDemoWeb.MapLive do
10195
</div>
10296
</div>
10397
<% tile_in_closed_list?(@path, tile.position) -> %>
104-
<div class="closed_list">
98+
<%= cond do %>
99+
<% tile_has_player?(@player_position, tile.position) -> %>
100+
<div class="closed_list entity entity-player">
101+
<span>🤖</span>
102+
<% true -> %>
103+
<div class="closed_list">
104+
<% end %>
105+
105106
<div class="info-container">
106107
<span class="span-g">
107108
<%= get_tile_node(@path.closed_list, tile.position).g %>
@@ -116,6 +117,14 @@ defmodule PathDemoWeb.MapLive do
116117
</div>
117118
<% Atom.to_string(tile.type) == "wall" -> %>
118119
<div class="tile-wall">&nbsp;</div>
120+
<% tile_has_player?(@player_position, tile.position) -> %>
121+
<div class="entity entity-player">
122+
<span>🤖</span>
123+
</div>
124+
<% tile_is_target?(@player_target, tile.position) -> %>
125+
<div class="target">
126+
<span>👀</span>
127+
</div>
119128
<% true -> %>
120129
<% end %>
121130
</div>
@@ -214,20 +223,23 @@ defmodule PathDemoWeb.MapLive do
214223
def tile_in_final_path?(nil, _), do: false
215224
def tile_in_final_path?(%{final_path: nil}, _), do: false
216225
def tile_in_final_path?(%{final_path: []}, _), do: false
226+
217227
def tile_in_final_path?(%{final_path: final_path}, position) do
218228
final_path |> Enum.any?(fn node -> node.position == position end)
219229
end
220230

221231
def tile_in_open_list?(nil, _), do: false
222232
def tile_in_open_list?(%{open_list: nil}, _), do: false
223233
def tile_in_open_list?(%{open_list: []}, _), do: false
234+
224235
def tile_in_open_list?(%{open_list: open_list}, position) do
225236
open_list |> Enum.any?(fn node -> node.position == position end)
226237
end
227238

228239
def tile_in_closed_list?(nil, _), do: false
229240
def tile_in_closed_list?(%{closed_list: nil}, _), do: false
230241
def tile_in_closed_list?(%{closed_list: []}, _), do: false
242+
231243
def tile_in_closed_list?(%{closed_list: closed_list}, position) do
232244
closed_list |> Enum.any?(fn node -> node.position == position end)
233245
end
@@ -239,6 +251,7 @@ defmodule PathDemoWeb.MapLive do
239251
""
240252
end
241253
end
254+
242255
defp update_disable(%{player_target: nil}), do: "disabled"
243256
defp update_disable(_), do: ""
244257

0 commit comments

Comments
 (0)