I am making the game Pong in Ruby using the library Gosu. Right now, I am trying to make the ball interacts with the board.
class Window < Gosu::Window
# board size 30 X 298
def initialize
super 1440,720,false
self.caption = "Pong"
@Ball = Ball.new(self)
@Ball.warp(720,360)
@Board1 = Board.new(self,15,360)
@Board2 = Board.new(self,1425,360)
end
def update
@Ball.draw
@Ball.move
@Ball.bounceOffBoard(@Board1,@Board2)
........
At the last line, I tried to pass the field @Board1 down to another class so that the @Ball knows the cordinate of the board to see whether it should jump off. But it keep throwing me mistakes like
Pong.rb:105: formal argument cannot be a constant
def bounceOffBoard(Board1,Board2)
What should I do?
For a start, don’t name instance variables with capital letters:
should be:
And:
should be: