Ruby 创造额外的子弹,根据宇宙飞船的角度偏移,在libGosu/Chingu?

Ruby 创造额外的子弹,根据宇宙飞船的角度偏移,在libGosu/Chingu?,ruby,2d-games,libgosu,Ruby,2d Games,Libgosu,我正在尝试使用libGosu和Chingu为我的基本教程式宇宙飞船进行武器升级 在player类中,我尝试了以下几种变体: def fire Bullet.create(:x => @x, :y => @y, :angle => @angle) Bullet.create(:x => @x + Gosu::offset_x(90, 25), :y => @y + Gosu::offset_y(@angle, 0), :angle => @angle)

我正在尝试使用libGosu和Chingu为我的基本教程式宇宙飞船进行武器升级

在player类中,我尝试了以下几种变体:

def fire
  Bullet.create(:x => @x, :y => @y, :angle => @angle)
  Bullet.create(:x => @x + Gosu::offset_x(90, 25), :y => @y + Gosu::offset_y(@angle, 0), :angle => @angle)
end
这是一种工作方式,但并不是理想的工作方式。以下是Bullet类的外观,仅供参考:

class Bullet < Chingu::GameObject
  def initialize(options)
    super(options.merge(:image => Gosu::Image["assets/laser.png"]))
    @speed = 7
    self.velocity_x = Gosu::offset_x(@angle, @speed)
    self.velocity_y = Gosu::offset_y(@angle, @speed)
  end

  def update
    @y += self.velocity_y
    @x += self.velocity_x
  end
end
class-BulletGosu::image[“assets/laser.png”]))
@速度=7
self.velocity_x=Gosu::offset_x(@angle,@speed)
self.velocity_y=Gosu::offset_y(@angle,@speed)
结束
def更新
@y+=自速度
@x+=自速度
结束
结束

当宇宙飞船旋转时,我应该如何构造“def fire”以使多余的子弹正确对齐?

需要以与
y
偏移相同的方式偏移
x


另外,如果
@wearm==2

以下简单的解决方案成功了,为什么要以不同的方式创建子弹两次:

Bullet.create(:x => @x + Gosu::offset_x(@angle+90, 25), :y => @y + Gosu::offset_y(@angle+90, 25), :angle => @angle)
在GameDev.StackExchange中,有对工作力的深入描述

我还遇到了以下“绕谷仓走很长一段路”,使用正弦波和余弦,并使用圆周率将角度转换为弧度:

Bullet.create(:x => @x + 20 * Math.cos(@angle*Math::PI/180) , :y => @y + 20 * Math.sin(@angle*Math::PI/180), :angle => @angle)
有关Sin/Cos方法的更详细说明,请参见


将度转换为弧度的公式是
degrees*∏/180

,感谢您的回复。第一个项目符号是中心项目符号。如果
@武器==2
,它还会发射第二颗子弹。我试过在x和y偏移相同的情况下使用它,如果
@angle
为0,效果很好,但是当宇宙飞船旋转时,它们会移动位置。我想我需要用罪恶和罪恶之类的东西。。。