miyako/sample/game_designer_subroutine/subroutine.rb

#! /usr/bin/ruby
# Authorモジュールのサブルーチン利用サンプル

$LOAD_PATH.push("../../")

require 'miyako'

module Miyako

class Comps
  CURSOR_SIZE = 24
  pattern = 4
  cursor_other = Rect.new(0, 0, 1, 1)
  cursor_back  = Rect.new(0, CURSOR_SIZE, CURSOR_SIZE, CURSOR_SIZE)
  wait   = Rect.new(CURSOR_SIZE * 1, 0, CURSOR_SIZE, CURSOR_SIZE)
  cursor = Rect.new(CURSOR_SIZE * 2, 0, CURSOR_SIZE, CURSOR_SIZE)
  page   = Rect.new(CURSOR_SIZE * 3, 0, CURSOR_SIZE, CURSOR_SIZE)
  @@wparam = WindowParameter.new(
    "cursors.png",
    cursor_other,
    cursor_other,
    cursor_other,
    cursor_other,
    cursor_other,
    cursor_other,
    cursor_other,
    cursor_other,
    cursor_back
  )
  @@cparam = CursorParameter.new(
    "cursors.png",
    wait, pattern,
    cursor, pattern,
    page, pattern
  )
  @@window = TextBox.new([512, 400], @@cparam, 128, false)
  @@window.centering
  @@window.font = Font.sans_serif
  @@window.font.size = 24
  @@window.msg.separate = false
  @@window.pauseType = 1
  @@window.pauseWait = 0.1

  @@director = Yuki::Director.new(@@window)

  @@scrwait = 5
  @@scrcnt = 0

  def Comps.window
    @@window
  end

  def Comps.director
    @@director
  end

  def Comps.show
    @@director.show
  end
  
  def Comps.hide
    @@director.hide
  end
  
  def Comps.reset
    @@director.reset
  end
  
  def Comps.start
    @@director.start
  end

  def Comps.update
    @@director.update
  end

  def Comps.event
    @@director.event
  end

  def Comps.trigger?(*v)
    return Input.trigger_all?(v)
  end

  def Comps.pushed?(*v)
    return Input.pushed_all?(v)
  end

  def Comps.cansel_pause
    return @@director.cansel_pause
  end

  def Comps.quitEvent?
    Input.pushed_any?(:btn2, :esc) || Input::quit?
  end
end

class Test
  include Story

  @@class_prefix = "Paragraph"

  class Paragraph_1 < Scene
    @@num = 0

    def init
      @sprite = Sprite.new([640, 480], nil)
      @sprite.dp = -100
      @sprite.bitmap.fillRect(0, 0, @sprite.w, @sprite.h, Color::RED)
    end

    def setup
      @num = @@num
      @@num = @@num + 1
      Comps.director.set_text("[now:#{@now}][pre:#{@prev}][upp:#{@upper}]{cr}こっちはメインシーンです{cr}[#{@num}]回目の訪問です{pause}")
      Comps.show
      Comps.start
      @sprite.show
    end

    def update
      return nil if Comps.quitEvent?
      Comps.update
      if Comps.event[:pause_cansel]
        return "sub1"
      end
      return @now
    end

    def final
      Comps.hide
      Comps.reset
      @sprite.hide
    end

    def Paragraph_1.notice
      "最初のサブルーチン"
    end
  end

  class Sub_sub1 < Scene
    def init
      @sprite = Sprite.new([640, 480], nil)
      @sprite.dp = -100
      @sprite.bitmap.fillRect(0, 0, @sprite.w, @sprite.h, Color::BLUE)
    end

    def setup
      Comps.director.set_text("[now:#{@now}][pre:#{@prev}][upp:#{@upper}]{cr}こっちはサブシーンです{pause}")
      Comps.show
      Comps.start
      @sprite.show
    end

    def update
      return nil if Comps.quitEvent?
      Comps.update
      if Comps.event[:pause_cansel]
        return "2"
      end
      @now
    end

    def final
      Comps.hide
      Comps.reset
      @sprite.hide
    end
  end

  class Paragraph_2 < Scene
    @@num = 0

    def init
      @sprite = Sprite.new([640, 480], nil)
      @sprite.dp = -100
      @sprite.bitmap.fillRect(0, 0, @sprite.w, @sprite.h, Color::GREEN)
    end

    def setup
      @num = @@num
      @@num = @@num + 1
      Comps.director.set_text("[now:#{@now}][pre:#{@prev}][upp:#{@upper}]{cr}サブシーンから来ましたです{cr}[#{@num}]回目の訪問ですよ{pause}")
      Comps.show
      Comps.start
      @sprite.show
    end

    def update
      return nil if Comps.quitEvent?
      Comps.update
      if Comps.event[:pause_cansel]
        return "return"
      end
      @now
    end

    def final
      Comps.hide
      Comps.reset
      @sprite.hide
    end
  end
end

t = Test.new
t.run(1)
end