加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

蒙娜丽莎的微笑 Ruby版

发布时间:2020-12-17 04:10:22 所属栏目:百科 来源:网络整理
导读:今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 #!/usr/bin/env rubyrequire "chingu"include Gosuinclude Chinguclass MonaLisa Chingu::Window def initialize super(600,550,false) self.input =

以下代码由PHP站长网 52php.cn收集自互联网

现在PHP站长网小编把它分享给大家,仅供参考

#!/usr/bin/env ruby
require "chingu"

include Gosu
include Chingu

class MonaLisa < Chingu::Window
  def initialize
    super(600,550,false)
    self.input = {:esc => :exit}
    push_game_state(Paint)
  end
end

class Pix < Chingu::GameObject
  traits :velocity
  def initialize(options)
    super(options)
  end

  def drop
    if rand(2) == 0
      @velocity_x = rand(0..2)
    else
      @velocity_x = -rand(0..2)
    end
    @velocity_y = rand(0..3)
    @acceleration_y = 1
  end

  def setup
    @image = Image["rect.png"]
  end
end

class Paint < Chingu::GameState

  def initialize
    @ground_y = $window.height+20
    super
  end

  def setup
    super
    IO.readlines("media/ml").each do |line|
      arr = line.chomp.split("x")
      x = arr[0].to_i
      y = arr[1].to_i
      w = arr[2].to_i
      h = arr[3].to_i
      r = arr[4][0...2].to_i(16)
      g = arr[4][2...4].to_i(16)
      b = arr[4][4...6].to_i(16)
      pix = Pix.create(:x => x,:y => y,:width => w,:height=> h,:color => Color.argb(255,r,g,b))
    end
    self.input = { :space => :drop }
  end

  def drop
    Pix.each { |pix| pix.drop }
  end

  def update
    Pix.each do |p|
      if p.y >= @ground_y
        slower = p.velocity_y / 3
        p.velocity_y = -(slower + rand(slower))
        if rand(2) == 0
          p.velocity_x = rand(0.4)
          p.acceleration_x = -(rand(0.05))
        else
          p.velocity_x = -rand(0.4)
          p.acceleration_x = (rand(0.05))
        end
      end
    end
    super
  end
end

MonaLisa.new.show

以上内容由PHP站长网【52php.cn】收集整理供大家参考研究

如果以上内容对您有帮助,欢迎收藏、点赞、推荐、分享。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读