#!ruby # -*- mode: ruby; coding: utf-8 -*- # Last updated: <2017/10/09 11:08:35 +0900> # # sprite draw test # # Windows10 x64 + Ruby 2.2.6 p396 mingw32 + DXRuby 1.5.22dev require "dxruby" class MySprite < Sprite def initialize(img) super self.image = img self.init_pos() end def init_pos self.x = rand(640 - self.image.width) self.y = 480 @dy = -rand(1.0..4.0) end def update self.y += @dy self.init_pos() if self.y + self.image.height < 0 end end imgs = [] ["grafx2_02.png", "grafx2_03.png", "grafx2_04.png"].each do |fn| imgs.push(Image.load(fn)) end sprs = [] 64.times do |i| sprs.push(MySprite.new(imgs[rand(imgs.size)])) end Window.scale = 2 Window.loop do break if Input.keyPush?(K_ESCAPE) Sprite.update(sprs) Sprite.draw(sprs) end