This file contains hidden or 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
scope "/", BreakoutexWeb do | |
pipe_through :browser | |
get "/", GameController, :index | |
end |
This file contains hidden or 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 BreakoutexWeb.GameController do | |
use BreakoutexWeb, :controller | |
alias Phoenix.LiveView | |
alias BreakoutexWeb.Live.Game | |
def index(conn, _) do | |
opts = [ | |
session: %{cookies: conn.cookies} | |
] |
This file contains hidden or 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 BreakoutexWeb.Live.Game do | |
@moduledoc """ | |
Main module, contains the entry point for the live view socket and | |
all the game logic | |
""" | |
use Phoenix.LiveView | |
alias Phoenix.LiveView.Socket | |
alias BreakoutexWeb.Live.Blocks |
This file contains hidden or 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 BreakoutexWeb.GameView do | |
use BreakoutexWeb, :view | |
end |
This file contains hidden or 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
.game-container { | |
position: relative; | |
margin-top: 4rem; | |
/* Subtract half of the board width*/ | |
left: calc(50% - 260px); | |
} | |
.game-container .block { | |
display: block; | |
position: absolute; |
This file contains hidden or 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
<!-- ...other styles above --> | |
@import "../../deps/phoenix_live_view/assets/css/live_view.css"; | |
@import "./game.css"; | |
html { | |
background: #292a2d; | |
color: #a9a9b3; | |
} | |
body { |
This file contains hidden or 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
<div phx-keydown="keydown" phx-keyup="keyup" phx-target="window"> | |
<%# Here should be the div with .game-container class %> | |
</div> |
This file contains hidden or 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
@spec handle_event(String.t(), map(), Socket.t()) :: {:noreply, Socket.t()} | {:stop, Socket.t()} | |
def handle_event("keydown", payload, socket) do | |
IO.puts("Received keydown event") | |
IO.inspect(payload, label: "Payload for keydown") | |
{:noreply, socket} | |
end | |
def handle_event("keyup", payload, socket) do | |
IO.puts("Received keyup event") |
This file contains hidden or 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
Received keyup event | |
Payload for keyup: %{ | |
"altKey" => false, | |
"charCode" => 0, | |
"code" => "ArrowDown", | |
"ctrlKey" => false, | |
"key" => "ArrowDown", | |
"keyCode" => 40, | |
"location" => 0, | |
"metaKey" => false, |
This file contains hidden or 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
# Coordinates of the top-left vertex of the paddle. They are relative to the board matrix | |
@paddle_left 11 | |
@paddle_top 18 | |
# Paddle length/height expressed in basic units | |
@paddle_length 5 | |
@paddle_height 1 | |
# Misc | |
@paddle_speed 5 |