更に調整
妙なサンプルに更に手を加えた。
四角の加速計算に距離を追加して、キビキビしつつ細かい動きができるように。
んでもって、障害物はある程度かわせるように減らして、ついでに左クリックで周りの時間を遅くする機能を追加した。
# DXRuby Ver 0.0.2 サンプルプログラム require 'dxruby' Window.caption = "サンプル" # 配列からimageオブジェクトを生成 image = Image.createFromArray(32,32,[255,255,255,255]*32*32) #image = Image.new("data.png") # DXRubyに同梱のファイルを使うようにすると白い四角がサルになる image2 = Image.createFromArray(32,32,[255,255,0,0]*32*32) x = 100.0 y = 100.0 dx = 0.0 dy = 0.0 # 弾クラス class Tama @@tama_image = Image.createFromArray(16,16,[255,255,255,0]*16*16) def initialize @x = rand(640) @y = 0 @angle = (rand(90)+45) * 2 * Math::PI / 360 @speed = rand(5)+3 @slow = 1.0 end def move @x = @x + Math.cos(@angle) * @speed * @slow @y = @y + Math.sin(@angle) * @speed * @slow Window.draw(@x, @y, 0, @@tama_image) @slow = 1.0 end attr_reader :x, :y attr_writer :slow end # 弾配列 tama = [] # メインループ Window.loop do # 弾生成 if rand(7) == 0 then tama.push(Tama.new) end # マウスの左ボタンで周りが遅くなる if Input.mouseButton(M_LBUTTON) == true then tama.each do |t| if t.x < (x + 131) and (t.x + 115) > x and t.y < (y + 131) and (t.y + 115) > y then t.slow = 0.2 end end end # 弾移動と破棄 tama.delete_if do |t| t.move t.y > 480 end # カーソルとの位置関係から方向を求めて加速 mx, my = Input.mousePos rx = Math.cos(Math.atan2((my - y - 16), (mx - x - 16))) / 80 * Math.sqrt((mx - x)**2 + (my - y)**2) ry = Math.sin(Math.atan2((my - y - 16), (mx - x - 16))) / 80 * Math.sqrt((mx - x)**2 + (my - y)**2) dx = dx + rx dy = dy + ry # 画面から出たらはねかえる if x + dx < 0 or x + dx > 639 - image.width then dx = -dx end if y + dy < 0 or y + dy > 479 - image.height then dy = -dy end # 移動 # マウスの左ボタンで自分も遅くなる if Input.mouseButton(M_LBUTTON) == true then x = x + dx * 0.2 y = y + dy * 0.2 else x = x + dx y = y + dy end # 微妙に減速していく dx = dx * 0.99 dy = dy * 0.99 # 判定 flag = false tama.each do |t| if t.x < (x + 31) and (t.x + 15) > x and t.y < (y + 31) and (t.y + 15) > y then flag = true break end end # 描画 if flag == false then Window.draw(x, y, 0, image) else Window.draw(x, y, 0, image2) end # エスケープキーで終了 if Input.key(K_ESCAPE) == true then break end end
ひょっとしたらゲームとして成立するようなものが作れるのではないかと思い始めた。
弾を撃てるようにして敵を出して、自機が思い通りに動かないSTGとしてもいいし、たとえば迷路を制限時間内に抜ける、イライラ棒系にするのもアリだ。
細かく動かすだけじゃなく、大きく速く動かしつつ、ぶつからないように制御するような、イライラだけじゃなくて俺SUGEEEって感じの爽快感があるものがよいだろう。
いまの段階でも、サササッっと大きく速く動きつつうまく回避できるとちょっと嬉しい。
そういう、練習が必要だけどうまくできると嬉しいってのは、ゲームとして重要な要素だと思う。