require "dxruby"
require "ostruct"
class O
attr_accessor :x
attr_accessor :y
attr_accessor :img
attr_accessor :func
attr_accessor :sym
attr_accessor :f
attr_accessor :st
def initialize oo = Hash.new
@y = oo[:y]
@x = oo[:x]
@img = oo[:img]
@func = oo[:func]
@sym = oo[:sym]
@st = OpenStruct.new
end
end
def hit_check o , m
o.x + o.img.width > m.x && o.x < m.x + m.img.width &&
o.y + o.img.height > m.y && o.y < m.y + m.img.height
end
task = []
#自機オブジェクト生成
task.push O.new x:300 , y:400 , img:Image.new(20,20,[100,150,150]) , sym: :user ,
func:->o{
o.x += 2 if Input.keyDown? K_RIGHT
o.x -= 2 if Input.keyDown? K_LEFT
o.y -= 2 if Input.keyDown? K_UP
o.y += 2 if Input.keyDown? K_DOWN
Window.drawEx o.x , o.y , o.img
#ショット
if Input.keyPush? K_Z
task.push O.new x:o.x , y:o.y , img:Image.new(7,15,[100,100,170]) , sym: :user_shot ,
func:->o{
o.y -= 0.5
Window.drawEx o.x , o.y , o.img
}
end
#ホーミングショット
if Input.keyPush? K_X
task.push O.new x:o.x , y:o.y , img:Image.new(7,15,[100,100,170]) , sym: :user_shot2 ,
func:->o{
#何か処理する
o.y -= 0.3
Window.drawEx o.x , o.y , o.img
}
end
#時限式で加速か何か
if Input.keyPush? K_C
task.push O.new x:o.x , y:o.y , img:Image.new(7,15,[100,100,170]) , sym: :user_shot3 ,
func:->o{
o.st.n ||= 0
o.st.n += 1
o.y -= 0.5 + (o.st.n/100.0)
Window.drawEx o.x , o.y , o.img
}
end
#全オブジェクトにアクセス可能
if Input.keyPush? K_A
p task
end
}
#敵オブジェクト生成
task.push O.new x:rand(Window.width-50) , y:rand(50) ,
img:Image.new(rand(40)+30,15,[100+rand(100),150+rand(100),150+rand(100)]) , sym: :enemy ,
func:->o{
o.y += 0.5
Window.drawEx o.x , o.y , o.img
}
Window.loop do
exit if Input.keyDown? K_ESCAPE
task.each do | o |
o.func.call o
end
end
cmVxdWlyZSAiZHhydWJ5IgpyZXF1a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