miyako/sample/rubyma.rb

#! /usr/bin/ruby
# Miyakoサンプルスクリプト
# 「るびま」で掲載したRGSS用スクリプトのMiyako版

$LOAD_PATH.push("../")

require 'miyako'

module Miyako

setTitle("るびまサンプル・Miyako版?")

class Spr
  def initialize(name, vp)
    @final = false
    @sp = Sprite.new(name)
    @sp.setViewPort(vp.x, vp.y, vp.w, vp.h)
    @sp.x = 0
    @sp.y = 0
    @sp.visible = true
    @stride = 8
  end
  
  def rect
    @sp.rect
  end
  
  def adjustment(n, min, max, size)
    if n < min
      min
    elsif n + size > max
      max - size
    else
      n
    end
  end
  
  def update
    br = @sp.rect
    sr = @sp.viewPort

    dx, dy = Input.triggerAmount

    @sp.x = adjustment(@sp.x + dx * @stride, sr.x, sr.w, br.w)
    @sp.y = adjustment(@sp.y + dy * @stride, sr.y, sr.h, br.h)
    
    @final = Input::quit? || Input::pushed_any?(:esc, :btn2)
  end
  
  def final?
    @final
  end
end

def_viewport = Rect.new(0, 0, 640, 480)
sp = Spr.new("ruby.png", def_viewport)
loop{
  update()
  sp.update()
  if sp.final?()
    break
  end
}

end