Upgrade to Pro — share decks privately, control downloads, hide ads and more …

分散オブジェクトで遊ぼう!〜dRubyで作るマルチプレイヤー迷路ゲーム〜 関西Ruby会議08

Avatar for yumu yumu
June 27, 2025
220

 分散オブジェクトで遊ぼう!〜dRubyで作るマルチプレイヤー迷路ゲーム〜 関西Ruby会議08

Avatar for yumu

yumu

June 27, 2025
Tweet

Transcript

  1. 自己紹介 yumu(湯村 美吹香) • 新卒3年目 Webエンジニア • 最近はTerraform > k8s

    manifest > Ruby • 好きな漫画:メイドインアビス • X:@myumura3
  2. ゲームの概要 • https://github.com/myumura/druby-game • 通信にdRuby、WebSocketを使用 • 3D迷路環境 • マルチプレイヤー対戦 •

    プレイヤーのロールによって異なる目標 • 5分間のタイムリミット 簡略化した地図
  3. dRubyで”Hello, World!” require 'drb'
 
 class HelloWorld
 def say_hello(name)
 "Hello,

    #{name}!"
 end
 end
 
 # オブジェクトを公開
 DRb.start_service('druby://localhost:8787', HelloWorld.new)
 DRb.thread.join
 サーバー側 require 'drb'
 
 # リモートオブジェクトへの接続
 DRb.start_service
 hello = DRbObject.new_with_uri('druby://localhost: 8787')
 
 puts hello.say_hello("関西Ruby会議") # => "Hello, 関西Ruby会議!"
 クライアント側
  4. ゲーム全体のアーキテクチャ • 3D迷路の描画 (Three.js) • ユーザー入力の処理 ブラウザ JavaScript • WebSocketサーバー

    (faye-websocket) • dRubyクライアント 中間サーバー Sinatra • • dRubyサーバー • ゲームロジックの • 集中管理 ゲームサーバー Ruby WebSocket dRuby
  5. GameServerクラスの役割 • ゲーム状態の一元管理 プレイヤー・迷路・鍵・脱出ポイントなど • プレイヤーの参加・離脱処理 • プレイヤーの移動・衝突判定 • ゲームタイマーの管理

    class GameServer
 def initialize
 @game_logic = GameLogic.new
 @timer_thread = start_timer
 end
 
 def move_player(name, position, rotation)
 # 移動処理
 end
 
 def collect_key(name, key_id)
 # 鍵の収集
 end
 # 省略
 end

  6. GameLogicクラスの役割 register_player move_player get_game_state collect_key escape def move_player(name, position, rotation)


    player = @players[name]
 return false unless player
 return false unless player.can_move?
 
 # 障害物との衝突チェック
 return false if collision_with_obstacles?(position)
 
 player.position = position
 player.rotation = rotation
 # 鍵・脱出・捕獲チェック
 check_game_state
 true
 end