2024-08-17 19:43:08 +02:00
|
|
|
defmodule Example.Game do
|
2024-08-18 13:44:09 +02:00
|
|
|
require Logger
|
2024-10-04 09:45:23 +02:00
|
|
|
@behaviour Amethyst.Game
|
2024-08-17 19:43:08 +02:00
|
|
|
|
|
|
|
@impl true
|
2024-08-25 13:17:25 +02:00
|
|
|
def instantiate(supervisor) do
|
|
|
|
Logger.info("The supervisor for this game is at #{inspect(supervisor)}")
|
|
|
|
{:ok, %{}}
|
2024-08-17 19:43:08 +02:00
|
|
|
end
|
2024-08-18 13:44:09 +02:00
|
|
|
|
|
|
|
@impl true
|
2024-08-25 21:03:09 +02:00
|
|
|
def login(from, cfg, refs) do
|
2024-08-19 00:00:03 +02:00
|
|
|
Logger.info("Player logged in from #{inspect(from)}: #{inspect(cfg)}")
|
2024-08-25 21:03:09 +02:00
|
|
|
Logger.info("The refs for this game are #{inspect(refs)}")
|
2024-10-04 11:36:08 +02:00
|
|
|
{:accept, {0.0, 270.0, 0.0}, {0.0, 0.0}}
|
2024-08-18 13:44:09 +02:00
|
|
|
end
|
2024-09-03 19:29:19 +02:00
|
|
|
|
|
|
|
@impl true
|
2024-10-03 20:36:26 +02:00
|
|
|
@spec player_position(any(), {any(), any(), any()}, any()) :: :ok
|
2024-09-09 18:45:52 +02:00
|
|
|
def player_position(from, {x, y, z}, _refs) do
|
2024-10-06 13:49:14 +02:00
|
|
|
# Logger.info("Player at #{inspect(from)} moved to #{x}, #{y}, #{z}")
|
2024-10-04 11:36:08 +02:00
|
|
|
send(from, {:set_position, {x, y, z}})
|
2024-09-03 19:29:19 +02:00
|
|
|
:ok
|
|
|
|
end
|
2024-09-04 11:24:04 +02:00
|
|
|
|
2024-10-03 20:36:26 +02:00
|
|
|
@impl true
|
2024-10-04 11:36:08 +02:00
|
|
|
def player_rotation(_from, {_yaw, _pitch}, _refs) do
|
|
|
|
# Logger.info("Player at #{inspect(from)} rotated to #{yaw}, #{pitch}")
|
2024-10-03 20:36:26 +02:00
|
|
|
:ok
|
|
|
|
end
|
|
|
|
|
|
|
|
@impl true
|
|
|
|
def accept_teleport(from, id, _state_refs) do
|
|
|
|
Logger.info("Player at #{inspect(from)} accepted teleport #{inspect(id)}")
|
|
|
|
:ok
|
|
|
|
end
|
|
|
|
|
2024-09-04 11:24:04 +02:00
|
|
|
@impl true
|
2024-09-09 18:45:52 +02:00
|
|
|
def joinable?(_refs) do
|
2024-09-04 11:24:04 +02:00
|
|
|
true
|
|
|
|
end
|
2024-10-03 20:36:26 +02:00
|
|
|
|
|
|
|
@impl true
|
2024-10-05 19:03:22 +02:00
|
|
|
def chunk(_from, {cx, cz}, _state_refs) do
|
2024-10-04 11:36:08 +02:00
|
|
|
# Logger.info("Player at #{inspect(from)} wants to know chunk #{cx}, #{cz}")
|
2024-10-03 20:36:26 +02:00
|
|
|
(0..255) |> Enum.map(fn y ->
|
2024-10-04 11:36:08 +02:00
|
|
|
(0..15) |> Enum.map(fn z ->
|
|
|
|
(0..15) |> Enum.map(fn x ->
|
2024-10-05 19:03:22 +02:00
|
|
|
gx = cx*16 + x
|
|
|
|
gz = cz*16 + z
|
|
|
|
gy = y
|
|
|
|
if rem(gx, 4) == 0 && rem(gy, 4) == 0 && rem(gz, 4) == 0 do
|
|
|
|
1
|
2024-10-04 11:36:08 +02:00
|
|
|
else
|
|
|
|
0
|
|
|
|
end
|
2024-10-03 20:36:26 +02:00
|
|
|
end)
|
2024-10-04 11:36:08 +02:00
|
|
|
end)
|
2024-10-03 20:36:26 +02:00
|
|
|
end)
|
|
|
|
end
|
2024-08-17 19:43:08 +02:00
|
|
|
end
|