#!ruby -Ku # -*- mode: ruby; coding: utf-8 -*- # Last updated: <2017/04/30 17:51:28 +0900> # # Tiny pixelart draw test with Ruby + DXRuby require 'dxruby' class MySprite < Sprite def initialize(x, y, img) super(x, y, img) @dx = rand(-0.5..0.5) @dy = rand(1..4) self.z = @dy * 2 end def update super self.x += @dx self.y += @dy @dx *= -1 if self.x < 0 or self.x >= Window.width - self.image.width self.vanish if self.y > Window.height end end imgs = Image.loadTiles("0000.png", 16, 16) sprs = [] cnt = 0 Window.resize(800, 600) Window.loop do break if Input.keyPush?(K_ESCAPE) if cnt % 2 == 0 w = imgs[0].width x = rand() * (Window.width - w * 1.2) y = -64 sprs.push(MySprite.new(x, y, imgs[rand(imgs.size)])) end Sprite.update(sprs) Sprite.draw(sprs) Sprite.clean(sprs) cnt += 1 end