Last active
September 25, 2015 04:19
-
-
Save ir-norn/679fbe25751c9bde1f2b to your computer and use it in GitHub Desktop.
instance_evalの使い道
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#coding:utf-8 | |
# 2015 09 24 Req | |
require"dxruby" | |
class O | |
attr_accessor :x,:y,:d,:f,:task | |
def initialize h = {} | |
@x = h[:x] | |
@y = h[:y] | |
@d = h[:d] | |
@f = ->{ yield self } | |
@task = [] | |
end | |
def update | |
@f[] | |
end | |
end | |
task = [] | |
task << O.new( x:100 , y:400 , d:Image.new(50,50,[200,200,150])) do |o| | |
o.instance_eval do | |
Window.draw x , y , d | |
@x += Input.x * 2 | |
@y += Input.y * 2 | |
if Input.keyDown? K_Z | |
task << O.new( x:x , y:y , d:Image.new(5,10,[100,100,100])) do |o| | |
o.instance_eval do | |
Window.draw x , y , d | |
@y -= 2 | |
end | |
end | |
end # if | |
end | |
end | |
Window.loop do | |
task.map do |m| | |
m.update | |
m.task.map do |m| | |
m.update | |
end | |
end | |
exit if Input.keyDown? K_F9 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment