8
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Elixirで作る「DDJ-FLX4のジョグ対応ブロックくずし」 その2 ゲームの画面の枠を作る

Last updated at Posted at 2024-12-12

Elixirで作る「DDJ-FLX4のジョグ対応ブロックくずし」 その1 プロジェクト作成からライブラリ追加までの続きです

まずはゲームの画面の枠をつくる

画面の仕様

  • mainから始まる
  • main_loopは画面を閉じるまでループする
    • drawを呼ぶ
  • drawは画面を描画する
lib/ddj_block.ex
defmodule DdjBlock do
  @moduledoc """
  Documentation for `DdjBlock`.
  """
  alias Rayex.Structs.Rectangle
  use Rayex

  def main() do
    init_window(800, 800, "DdjBlock")
    main_loop(true)
  end

  defp main_loop(true) do
    begin_drawing()
    draw()
    end_drawing()

    Process.sleep(100)
    main_loop(!window_should_close())
  end

  defp main_loop(_), do: nil

  defp draw() do
    rectangle = %Rectangle{x: 100.0, y: 100.0, width: 100.0, height: 50.0}
    draw_rectangle_lines_ex(rectangle, 1, %{r: 0, g: 255, b: 0, a: 255})
  end
end

テストを消しておく
画面の自動テストは無理なので
実施するなら、関数ごとのテストかな

test/ddj_block_test.exs
defmodule DdjBlockTest do
  use ExUnit.Case
end

実行

iex -S mix

下記のエラーがでる
image.png

rayexビルド対策

音が鳴らないライブラリになっても文句を言わないこと

とりあえず、ビルドを通るようにする

deps/rayex/c_src/rayex/rayex.c
// 省略
UNIFEX_TERM is_sound_ready(UnifexEnv *env, UnifexPayload *payload) {
  Sound sound = get_sound_unifex_payload(env, payload);
- bool res = IsSoundReady(sound);
+ bool res = false; // IsSoundReady(sound);
  return is_sound_ready_result(env, res);
}
// 省略

rayexをビルド

$ mix deps.compile rayex --force

起動できた

image.png

だが、しかしバッテン押しても閉じない
image.png

終了対策

mix コマンドを作る

lib/mix/tasks/ddj.ex
defmodule Mix.Tasks.Ddj do
  use Mix.Task

  def run(_arg) do
    DdjBlock.main()
  end
end
$ mix ddj

無事に終了できるプログラムができました

ソース

今回はここまで
つづく

8
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?