我正在尝试使用 libGosu 和 Chingu 为我的基本教程式宇宙飞船创建武器升级。
在播放器类中,我尝试了以下几种变体:
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
我应该如何构建“def fire”以便在宇宙飞船旋转时让额外的子弹正确对齐?