This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule SuperSlimeGame.Application do | |
use Application | |
# See https://hexdocs.pm/elixir/Application.html | |
# for more information on OTP Applications | |
def start(_type, _args) do | |
import Supervisor.Spec | |
# Define workers and child supervisors to be supervised | |
children = [ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def handle_in("playerAction", payload, socket) do | |
broadcast!(socket, "playerAction", Map.put(payload, :from_player, socket.assigns.player)) | |
{:noreply, socket} | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule SuperSlimeGame.GameState do | |
@moduledoc """ | |
This module holds the game current state. It also contains the game logic. | |
Allows to add new players to the board, move them and detect collisions. | |
""" | |
@doc """ | |
Used by the supervisor to start the Agent that will keep the game state persistent. | |
The initial value passed to the Agent is an empty map. | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule SuperSlimeGameWeb.GameChannel do | |
use SuperSlimeGameWeb, :channel | |
alias SuperSlimeGame.GameState | |
alias SuperSlimeGame.Error | |
# join to topic game:* | |
def join("game:" <> code, %{"email" => email}, socket) do | |
case Map.has_key?(GameState.games(), code) do | |
true -> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule SuperSlimeGameWeb.UserSocket do | |
use Phoenix.Socket | |
## Channels | |
## Define game channel | |
channel("game:*", SuperSlimeGameWeb.GameChannel) | |
## Transports - long polling | |
transport(:websocket, Phoenix.Transports.WebSocket) |
NewerOlder