amethyst/apps/example_game/lib/example/game.ex
Kodi Craft 5fae9aa1ff
All checks were successful
Build & Test / nix-build (pull_request) Successful in 2m39s
Build & Test / nix-build (push) Successful in 2m40s
Some progress towards sending the map
2024-10-01 19:26:24 +02:00

58 lines
1.4 KiB
Elixir

defmodule Example.Game do
require Logger
@behaviour Amethyst.API.Game
@impl true
def instantiate(supervisor) do
Logger.info("The supervisor for this game is at #{inspect(supervisor)}")
{:ok, %{}}
end
@impl true
def login(from, cfg, refs) do
Logger.info("Player logged in from #{inspect(from)}: #{inspect(cfg)}")
Logger.info("The refs for this game are #{inspect(refs)}")
{:accept, {0.0, 10.0, 0.0}, {0.0, 0.0}}
end
@impl true
@spec player_position(any(), {any(), any(), any()}, any()) :: :ok
def player_position(from, {x, y, z}, _refs) do
Logger.info("Player at #{inspect(from)} moved to #{x}, #{y}, #{z}")
:ok
end
@impl true
def player_rotation(from, {yaw, pitch}, _refs) do
Logger.info("Player at #{inspect(from)} rotated to #{yaw}, #{pitch}")
:ok
end
@impl true
def accept_teleport(from, id, _state_refs) do
Logger.info("Player at #{inspect(from)} accepted teleport #{inspect(id)}")
:ok
end
@impl true
def joinable?(_refs) do
true
end
@impl true
def chunk(from, {x, z}, _state_refs) do
Logger.info("Player at #{inspect(from)} wants to know chunk #{x}, #{z}")
(0..255) |> Enum.map(fn y ->
if y < 5 do
(0..15) |> Enum.map(fn _z ->
(0..15) |> Enum.map(fn _x -> 1 end)
end)
else
(0..15) |> Enum.map(fn _z ->
(0..15) |> Enum.map(fn _x -> 0 end)
end)
end
end)
end
end