Blockr Points
import IEx.Helpers
alias Blockr.Game.{Canvas, Group, Point, Tetromino}
one-point
p =
Point.new(1, 5)
|> Point.move_down()
|> Point.move_down()
|> Point.move_down()
|> Point.move_left()
|> Point.move_right()
Canvas.new(p)
Multiple Point
points =
[
Point.new(2, 5),
Point.new(2, 6),
Point.new(3, 4),
Point.new(3, 5)
]
Canvas.new(points)
# points =
# [
# (Point.new(2,5)|> Point.move_right()),
# (Point.new(2,6)|> Point.move_right()),
# (Point.new(3,4)|> Point.move_right()),
# (Point.new(3,5)|> Point.move_right()),
# ]
# points_data = [{2, 5}, {2, 6}, {3, 4}, {3, 5}]
# points = Enum.map(points_data, fn {x, y} ->
# Point.new(x, y) |> Point.move_right()
# end)
# points =
# [{2, 5}, {2, 6}, {3, 4}, {3, 5}]
# |> Enum.map(fn {x, y} -> Point.new(x, y) |> Point.move_right() end)
# Canvas.new(points)
# points =
# [{2, 5}, {2, 6}, {3, 4}, {3, 5}]
# |> Enum.map(&Point.new(elem(&1, 0), elem(&1, 1)) |> Point.move_right())
# |> Canvas.new()
points =
[
Point.new(2, 5),
Point.new(2, 6),
Point.new(3, 4),
Point.new(3, 5)
]
points
|> Enum.map(&Point.move_right/1)
|> Enum.map(&Point.move_right/1)
|> Enum.map(&Point.move_down/1)
|> Canvas.new()
Big Tetromino
points =
[
Point.new(2, 2),
Point.new(3, 2),
Point.new(4, 2),
Point.new(4, 3)
]
Canvas.tetromino(points)
defmodule Spinner do
def swap({row, col}) do
{col, row}
end
def flip_left_right({row, col}) do
{row, 5 - col}
end
def flip_top_bottom({row, col}) do
{5 - row, col}
end
def rotate(point, 0) do
point
end
def rotate(point, 90) do
point |> swap() |> flip_left_right()
end
def rotate(point, 180) do
point |> flip_top_bottom() |> flip_left_right()
end
def rotate(point, 270) do
point |> swap() |> flip_top_bottom()
end
def rotate(point, 360) do
point
end
end
{:module, Spinner, <<70, 79, 82, 49, 0, 0, 8, ...>>, {:rotate, 2}}
Canvas.tetromino(points)
points
|> Enum.map(&Spinner.rotate(&1, 90))
|> Canvas.tetromino()
points
|> Enum.map(&Spinner.rotate(&1, 180))
|> Canvas.tetromino()
points
|> Enum.map(&Spinner.rotate(&1, 270))
|> Canvas.tetromino()
nil
points
|> Enum.map(&Spinner.swap/1)
|> Canvas.tetromino()
points
|> Enum.map(&Spinner.flip_left_right/1)
|> Canvas.tetromino()
points
|> Enum.map(&Spinner.flip_top_bottom/1)
|> Canvas.tetromino()
Adding swap and all to Points module
Point.new(1, 2) |> Point.swap()
{2, 1}
Shapes
:i shape
Canvas.tetromino([{1, 2}, {2, 2}, {3, 2}, {4, 2}])
:l shape
Canvas.tetromino([{1, 2}, {2, 2}, {3, 2}, {3, 3}])
:j shape
Canvas.tetromino([{1, 3}, {2, 3}, {3, 2}, {3, 3}])
:o shape
Canvas.tetromino([{2, 2}, {3, 2}, {2, 3}, {3, 3}])
:t shape
Canvas.tetromino([{1, 2}, {2, 2}, {3, 2}, {2, 3}])
:s shape
Canvas.tetromino([{2, 3}, {2, 4}, {3, 2}, {3, 3}])
:z shape
Canvas.tetromino([{2, 2}, {2, 3}, {3, 3}, {3, 4}])
Tetromino.new(:z)
|> Tetromino.to_group()
|> Canvas.tetromino()
Canvas with color
Tetromino.new(:z)
|> Tetromino.to_group()
|> Group.paint(:z)
|> Canvas.tetromino()
Complete through part 1
Next in our implementation
-
Add a game
Board
-
Add walls to our
Board
-
Enhance
Canvas
dimensions to show walls -
Add score to our
Board
-
Add
Game.left
,Game.right
and check overlaps when tetromino moves -
Add
Game.fall
and check overlaps when tetromino moves -
Detach
Tetromino
iffall
fails -
Score
Testromino
iffall
falls -
Remove scored rows on
score
Moving within canvas
# CRC
Tetromino.new(:z)
|> Tetromino.rotate_right_90()
|> Tetrom