Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Tomple

macrumors 6502a
Original poster
Dec 12, 2008
604
0
New York, New York
I continue to get the "unexpected end, expecting kEND" error

Could someone please take a look at this :D

main.rb

Code:
require 'rubygems'
require 'gosu'
require 'player'

class MyGame < Gosu::Window
  def initialize
    super(300, 400, false)
    @player = Player.new(self)
  end
  
  def update
    if button_down? Gosu::Button::KbLeft
      @player.move_left
    if button_down? Gosu::Button::KbRight
      @player.move_right
  end
  
  def draw
    @player.draw
  end
  
end

window = MyGame.new
window.show

player.rb

Code:
class Player
  
  def initialize(game_window)
    @game_window = game_window
    @icon = Gosu::Image.new(@game_window, "images/orgbad.png", true)
    @x = 50
    @y = 50
  end
  
  def draw
    @icon.draw(@x, @y, 1)
  end
  
  def move_left
    @x = @x - 2
  end
  
  def move_right
    @x = @x + 2
  end
    
end
 
In update, you haven't terminated the two ifs.

Code:
  def update
    if button_down? Gosu::Button::KbLeft
      @player.move_left
    [color="red"]end[/color]
    if button_down? Gosu::Button::KbRight
      @player.move_right
    [color="red"]end[/color]
  end
 
Well, might as well ask another question while im here...

Is there an easy way to add/center text other then @message = " " and font.draw
 
Last edited:
Perhaps you could use font's text_width method like this:

Code:
class Gosu::Font
  def draw_centered(area_width,
                    text, x, y, z,
                    factor_x = 1, factor_y = 1, 
                    color = 0xffffffff, mode = :default)
    w = text_width(text, factor_x)
    dx = (area_width - w) / 2
    draw(text, x + dx, y, z, factor_x, factory_y, color, mode)
  end
end
 
Perhaps you could use font's text_width method like this:

Code:
class Gosu::Font
  def draw_centered(area_width,
                    text, x, y, z,
                    factor_x = 1, factor_y = 1, 
                    color = 0xffffffff, mode = :default)
    w = text_width(text, factor_x)
    dx = (area_width - w) / 2
    draw(text, x + dx, y, z, factor_x, factory_y, color, mode)
  end
end

Hmm thanks for this, should help :D
 
Ok, time for another dumb question.

When using

Code:
class Gosu::Font
  def draw_centered(area_width,
                    text, x, y, z,
                    factor_x = 1, factor_y = 1, 
                    color = 0xffffffff, mode = :default)
    w = text_width(text, factor_x)
    dx = (area_width - w) / 2
    draw(text, x + dx, y, z, factor_x, factory_y, color, mode)
  end
end

How do I then have it say something, where does the text go?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.