fork download
  1. require "dxruby"
  2. require "ostruct"
  3.  
  4. class O
  5. attr_accessor :x
  6. attr_accessor :y
  7. attr_accessor :img
  8. attr_accessor :func
  9. attr_accessor :sym
  10. attr_accessor :f
  11. attr_accessor :st
  12. def initialize oo = Hash.new
  13. @y = oo[:y]
  14. @x = oo[:x]
  15. @img = oo[:img]
  16. @func = oo[:func]
  17. @sym = oo[:sym]
  18. @st = OpenStruct.new
  19. end
  20. end
  21.  
  22. def hit_check o , m
  23. o.x + o.img.width > m.x && o.x < m.x + m.img.width &&
  24. o.y + o.img.height > m.y && o.y < m.y + m.img.height
  25. end
  26.  
  27. task = []
  28. #自機オブジェクト生成
  29. task.push O.new x:300 , y:400 , img:Image.new(20,20,[100,150,150]) , sym: :user ,
  30. func:->o{
  31. o.x += 2 if Input.keyDown? K_RIGHT
  32. o.x -= 2 if Input.keyDown? K_LEFT
  33. o.y -= 2 if Input.keyDown? K_UP
  34. o.y += 2 if Input.keyDown? K_DOWN
  35. Window.drawEx o.x , o.y , o.img
  36.  
  37. #ショット
  38. if Input.keyPush? K_Z
  39. task.push O.new x:o.x , y:o.y , img:Image.new(7,15,[100,100,170]) , sym: :user_shot ,
  40. func:->o{
  41. o.y -= 0.5
  42. Window.drawEx o.x , o.y , o.img
  43. }
  44. end
  45. #ホーミングショット
  46. if Input.keyPush? K_X
  47. task.push O.new x:o.x , y:o.y , img:Image.new(7,15,[100,100,170]) , sym: :user_shot2 ,
  48. func:->o{
  49. #何か処理する
  50. o.y -= 0.3
  51. Window.drawEx o.x , o.y , o.img
  52. }
  53. end
  54. #時限式で加速か何か
  55. if Input.keyPush? K_C
  56. task.push O.new x:o.x , y:o.y , img:Image.new(7,15,[100,100,170]) , sym: :user_shot3 ,
  57. func:->o{
  58. o.st.n ||= 0
  59. o.st.n += 1
  60.  
  61. o.y -= 0.5 + (o.st.n/100.0)
  62. Window.drawEx o.x , o.y , o.img
  63. }
  64. end
  65. #全オブジェクトにアクセス可能
  66. if Input.keyPush? K_A
  67. p task
  68. end
  69. }
  70.  
  71. #敵オブジェクト生成
  72. task.push O.new x:rand(Window.width-50) , y:rand(50) ,
  73. img:Image.new(rand(40)+30,15,[100+rand(100),150+rand(100),150+rand(100)]) , sym: :enemy ,
  74. func:->o{
  75. o.y += 0.5
  76. Window.drawEx o.x , o.y , o.img
  77. }
  78. Window.loop do
  79. exit if Input.keyDown? K_ESCAPE
  80. task.each do | o |
  81. o.func.call o
  82. end
  83. end
  84.  
Runtime error #stdin #stdout 0.05s 5888KB
stdin
Standard input is empty
stdout
Standard output is empty