the ball doesn't move

6 views
Skip to first unread message

Antonio Prieto

unread,
Mar 27, 2013, 12:04:24 PM3/27/13
to ruby...@googlegroups.com
Hi, and thanks in advance.

It seems as if the method update in class Ball wouldn't work.  The ball doesn´t fall...

Here is my code:
class Ball

def initialize(gamewindow)
@gamewindow = gamewindow
@icon = Gosu::Image.new(@gamewindow,"images/soccer.png", true)
@x = rand(@gamewindow.width)
@y = 0
end
def draw
@icon.draw(@x,@y,3)
end

def update
@y = @y + 10
end
end

and for gam_window.rb:

$: << File.expand_path(File.dirname(__FILE__)) 

require 'rubygems'  
require 'gosu'  
require 'player' 
require 'Ball'
 
class MyGame < Gosu::Window  
  
  def initialize  
@window_width = 900  
@window_height = 600  
@gosu_window = self  
super(@window_width, @window_height, false)
self.caption = "My first computer game!"  
@background_image = Gosu::Image.new(@gosu_window,"images/javi.jpg", true)  
@player1 = Player.new(self)
@ball = Ball.new(self)
   
  end  
  
  def update  
if button_down? Gosu::Button::KbLeft
@player1.move_left
end
if button_down? Gosu::Button::KbRight 
@player1.move_right
end 
if button_down? Gosu::Button::KbUp
@player1.move_up
end
if button_down? Gosu::Button::KbDown
@player1.move_down
end
   end
  
  def draw  
@background_image.draw(0,0,1)  
@player1.draw
@ball.draw
  end  
  
end  
  
window = MyGame.new  
window.show
Reply all
Reply to author
Forward
0 new messages