1

Ruby gosu 横スクロール ゲームで背景画像をループさせたいです。背景画像と複製された背景画像を変換するために使用されるカウンターに問題があります@k@pそれらを追加する良い方法が思いつきません。より明確にするためのコード。

require 'gosu'

class GameWindow < Gosu::Window
attr_accessor :x, :y

SHIFT = 700

 def initialize
  super 640,440
  @background  = Gosu::Image.new("./images/bg.png")
  @player      = Gosu::Image.new("./images/000.png")
  @x1, @y1 = 0, 0
  @player_x, @player_y = 50, 50
  @k = 0    #counter
  @p = 1    #counter
 end

 def update
  @x1 -= 3
  @player_y += 1 if @player_y <= 375
  @player_y -= 3 if button_down?(Gosu::KbSpace) and @player_y >= 0

  @coordinates = Gosu::Image.from_text(
    self, "#{@x1},#{@k}", Gosu.default_font_name, 30)
  #here should be the code for @k and @p
 end

 def draw
  @background.draw(@x1  + @k*SHIFT, @y1, 0)
  @background.draw(@x1 +  @p*SHIFT, @y1, 0)
  @player.draw(@player_x, @player_y, 0)
  @coordinates.draw(0, 0, 1)
 end

 def button_down(id)
  $window.close if id == Gosu::KbEscape
 end

end

window = GameWindow.new
window.show

では、どうすればカウンター@k@p.Tried this

if @x1 > -(SHIFT+5)*@p and @x1 < -SHIFT*@p  #705 and 700
  @k += 2
end

if @k > 0 and @x1 > -SHIFT*@k - 5 and @x1 < -SHIFT*@k - 3  #1405 and 1403
  @p += 2 
end

しかし、それは最初にしか機能しません(2〜3回の画像シフト)。これも試してみました

if @x1 == -SHIFT*@p
  @k += 2
end

そしてそれはうまくいきませんでした。

4

1 に答える 1