Saturday, 15 September 2012

libgosu - I want to have objects interact each other. (Ruby) -



libgosu - I want to have objects interact each other. (Ruby) -

i making game pong in ruby using library gosu. right now, trying create ball interacts 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 lastly line, tried pass field @board1 downwards class @ball knows cordinate of board see whether should jump off. maintain throwing me mistakes

pong.rb:105: formal argument cannot constant def bounceoffboard(board1,board2)

what should do?

for start, don't name instance variables capital letters:

@ball = ball.new(self) @board1 = board.new(self,15,360) @board2 = board.new(self,1425,360)

should be:

@ball = ball.new(self) @board1 = board.new(self,15,360) @board2 = board.new(self,1425,360)

and:

def bounceoffboard(board1,board2)

should be:

def bounceoffboard(board1, board2)

ruby libgosu

No comments:

Post a Comment