Skip to content

Instantly share code, notes, and snippets.

@ir-norn
Last active September 25, 2015 04:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ir-norn/679fbe25751c9bde1f2b to your computer and use it in GitHub Desktop.
Save ir-norn/679fbe25751c9bde1f2b to your computer and use it in GitHub Desktop.
instance_evalの使い道
#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