Thanks Alberto
class Window < Gosu::Window
....
def run_game
live_bullets.each {|bullet| bullet.update(@player.laser)}
@player.update
end
def live_bullets
@bullets.select{|bullet| bullet.alive == true}
end
...
end
and
class Bullet
attr_reader :x, :y, :alive, :laser
...
def update
@y=@y+10
if @y>@window.width
@y=0
@x=rand(@window.width)
end
hit_by?(laser)
end
...
end
The Player class doesn't have a .laser method.
Adding :laser to the attr_reader in the Player class confuses the program because it now expects @player.laser to be a variable but is not expecting a variable to be passed to the bullet.update method (the laser variable in the "hit_by?(laser)" call is dragged into Bullet by attr_reader).
So I'm a bit confused, and my program is too.
I'm wondering if it has to do with the "bullet" words: the Window class now has a number of "bullets" defined as
@bullets = 2.times.map {Bullet.new(self)}
but no definition of "bullet" (single and lowercase) - could it be that I need to change the calls such as
live_bullets.each {|bullet| bullet.update(@player.laser)}
to reflect this?
Thanks so much for your help.
Mark