我试图创建一个武器升级,我的基本,教程式的飞船,使用libGosu和清谷。
在播放器类中,我尝试了以下几种变体:
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它有点工作,但不完全是它理想中应该做的。作为参考,以下是子弹类的样子:
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火“才能使额外的子弹正确排列?
发布于 2013-09-06 01:13:24
以下简单的解决方案成功地做到了这一点:
Bullet.create(:x => @x + Gosu::offset_x(@angle+90, 25), :y => @y + Gosu::offset_y(@angle+90, 25), :angle => @angle)有一个深入的描述在this answer的力量在GameDev.StackExchange的工作.
我还看到了以下“在谷仓周围的很长一段路”,使用Sin和Cos,并使用PI将角度转换为弧度:
Bullet.create(:x => @x + 20 * Math.cos(@angle*Math::PI/180) , :y => @y + 20 * Math.sin(@angle*Math::PI/180), :angle => @angle)关于Sin/Cos方法的更详细描述可以找到here。
将度转换为弧度的公式是degrees*Π/180。
发布于 2013-09-02 02:45:29
x需要以与y相同的偏移方式进行偏移。
另外,如果@weapon == 2的话,为什么要以不同的方式两次创建这个项目呢?
https://stackoverflow.com/questions/18564243
复制相似问题