Create extra bullets, offset according to angle of spaceship?
0
votes
0
votes
Posted by: mpl on 08/21/2015 | Add Revision
I am trying to create a weapons upgrade for my Spaceship, using libGosu and Chingu (in Ruby). This question is about how to deal with this issue specifically in Ruby, and more specifically in libGosu.
In the player class I have tried several variations of the following:
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
It sort of works, but not exactly how it ideally should. For reference, this is what the Bullet class looks like:
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
How should I construct "def fire" in order to get the extra bullets to align properly when the spaceship rotates?
In the first image (above) the bullets are separated as intended.
In the second image the bullets are clumping together when the spaceship is rotated.