Not logged inGosu Forums
Forum back to Help Search Register Login
Up Forum
Topic Simple card memory game demo By OldBoy Date 2016-08-01 20:55

> Most of it is nitpicking, but I think that's what you asked for - hope that helps :)

yes, this is great stuff, thanks alot :). Hearing other people's opinion is good way to learn something. I totally forgot I could use question mark for method names, "game_ended?" is more clear, also Array#compact is nice shortcut, I should have known that Ruby has built in methods for almost everything :). Other stuff like ".rb" in require and hash curly braces, etc are mostly for my own conveniance, since I do get lost easily when looking in large chunks of text/code (I assume I'm kinda reading impaired or something like that).

As for Bundler and Rubocop, that'll have to wait, I'm still figuring out git and github. I tried Bundler a while ago but I couldn't make it work the way I expected.
Topic Simple card memory game demo By OldBoy Date 2016-07-31 19:46
Thanks! My current priority is to improve my ruby knowledge, there will be time to polish game(s) later. At first I made game with only one class and no states, but I couldn't get the timer work no matter what I tried. So I refactored code to three classes/states, it took me almost a week to figure that out ... Today I tried for learning purpose (and also I thought game would look more professional) to make additional class Card, and put all card logic inside, but I messed up everything and finished with deleting the project. I am much more comfortable working with arrays and hashes than with classes and OOP, my only fear is that people gonna laugh when they see my code ...
Topic Simple card memory game demo By OldBoy Date 2016-07-30 09:46
This little game is the biggest "project" I've ever done, so before I start doing anything further, I'd like to hear critique.
Anything I'm doing wrong, from file/class naming to coding style practices and github related stuff.

Also, I want to make .zip file and mail it to a friend who (probably) doesn't want to install ruby.
Which files I need to copy from ruby installation folder to my game root folder to make it portable?
Topic Can you reset Gosu.milliseconds back to zero? By OldBoy Date 2016-07-21 16:29
it's not that easy, there is an unknown time gap between when the game ends, and when the player click on "play again" button. looks like I'll have to implement custom Stopwatch class (or add 5 extra variables ...). It would be much easier if I could just restart Gosu::milliseconds :/
Topic get clicked pixel color By OldBoy Date 2016-07-20 17:34
I've set my goal to make a simpler game first, hopefully I'll be back to your explanation sometime ... :)

> Also, :retro only sets a few OpenGL parameters that change how the image is rendered when it is stretched or rotated, it does not affect the image's pixel data.

is "Gosu::enable_undocumented_retrofication", the same thing?
Topic Can you reset Gosu.milliseconds back to zero? By OldBoy Date 2016-07-20 17:27
I made a simple card-memory game, and I want to implement timer/stopwatch (to record fastest time).
Gosu.milliseconds works for the first playthrough, but then just keeps counting.
Can I reset Gosu.milliseconds back to zero or should I use ruby time class (or something else)?
Topic get clicked pixel color By OldBoy Date 2016-07-05 17:40
I'm not sure if this helps me, what would solution with gl_tex_info look like? All of my images will be single color + transparent only (but irregular shapes) and will be smaller than 512x512 pixels, something like Risk map. I was thinking to identify specific objects/instances on screen like it's suggested on page 2 (fourth take on the problem). Also all images would be loaded with :retro => true, to prevent problems with anti-aliasing
Topic get clicked pixel color By OldBoy Date 2016-07-05 13:02
In plain Gosu (no extensions) how to get pixel color at clicked place (of topmost image, or shape)? Something like this
Topic What's the proper way to do room transitions ? By OldBoy Date 2014-07-23 15:56
like old-school platformers (VVVVVV, Prince Of Persia ...etc). Should I delete all the assets from old room and draw new ones every time I need to change the room, or there is some other way ? I also need room transitions for: main menu --> game --> show end game screen cycle, but I couldn't find any working examples (plain gosu, without other gems)
Topic zooming/unzooming background image By OldBoy Date 2014-02-28 17:26
yep, that did the trick ... thank you very much ... now I have only one (two) problem(s) left:

a- How to zoom image at the center of the screen
b- How to zoom/unzoom image at the point of mouse cursor (google maps way)

Take as much time as you need ... I am very slow and inconsistent with finishing my code anyway
Topic zooming/unzooming background image By OldBoy Date 2014-02-28 17:13
if button_down?(Gosu::MsLeft) #button is being hold
      if !@drag   #this executes only once,when we press mouse button @drag == nil means !@drag is true
        @drag = [mouse_x, mouse_y] #store the current position of mouse
        @origin = [@x, @y]         #store the current position of image
      else   #after initial mouse click, @drag != nil, meaning  !@drag == false, meaning this block executes while we hold mouse button pressed
        @x  = @origin[0] + (mouse_x - @drag[0]) #translate according to mouse movement
        @y  = @origin[1] + (mouse_y - @drag[1])
    else #button is released
      @drag = @origin = nil #clear variables, so you can re-use them


This is beautiful, works perfectly ... it took me some time to figure out whats going on though, so I added some comments if there are other newbies like me reading this.
You also solved my #4 question

Thank you very much !
Topic zooming/unzooming background image By OldBoy Date 2014-02-28 13:17
wow, it's already been a year since I asked this ... I must be the slowest programmer ever :)
Anyway, here's what I've came up with:
require 'rubygems'
require 'gosu'

class GameWindow < Gosu::Window
  POMAK = 5
  def initialize
    super 1366, 768, true, update_interval = 20
    @x = @y = 0
    @f_x = @f_y = 1.0
    @slika =, '18.jpg', false)
    @font =, Gosu::default_font_name, 20)
  def update
    if button_down?(Gosu::KbLeft)
      @x += POMAK
    if button_down?(Gosu::KbRight)
      @x -= POMAK
    if button_down?(Gosu::KbUp)
      @y += POMAK
    if button_down?(Gosu::KbDown)
      @y -= POMAK
    if button_down?(Gosu::KbNumpadAdd)
      @f_x += 0.01
      @f_y += 0.01
      @x -= 15
      @y -= 15
    if button_down?(Gosu::KbNumpadSubtract)
      @f_x -= 0.01
      @f_y -= 0.01
      @x += 15
      @y += 15
    if button_down?(Gosu::MsWheelUp)
      @f_x += 0.01
      @f_y += 0.01
      @x -= 15
      @y -= 15
    if button_down?(Gosu::MsWheelDown)
      @f_x -= 0.01
      @f_y -= 0.01
      @x += 15
      @y += 15
  def draw
    @slika.draw(@x, @y, 1, @f_x, @f_y)
    @font.draw("Mish_x: #{mouse_x}; Mish_y: #{mouse_y}", 10, 10, 3, 1.0, 1.0, 0xffffff00)

  def button_down(id)
    case id
    when Gosu::KbEscape
    # when MsLeft
    # not working ! 
    # end
  def needs_cursor?

window =

It's a good start, but I have few problems:

1- How to implement mouse wheel to work (wheel up should do same as KbNumpadAdd,  wheeldown = KbNumpadSubtract)
2- How to implement image movement when mouse left button is pressed and hold (like google maps) ... drag and drop, is that how it's called ?
3- How to ZOOM at the CENTER of the screen ?? You can notice that I am manually adding 15 pixels ( @x += 15 and @y += 15 ) when I'm changing factor_x/factor_y (@f_x -= 0.01 and @f_y -= 0.01) ... but it still isn't right ... I'm affraid I'll need some advanced math for this ?
4- How to set font to Courier New ?

Any help appreciated !
Topic zooming/unzooming background image By OldBoy Date 2013-01-17 20:58
I want to load large picture (above 3000x3000 pixels, static, like a background), and I want to be able to zoom/unzoom a portion of it (with mousewheel and/or keyboard) and also to move it to see other parts of whole image. Sort of like an imageviewer (acdsee, irfanview) - open image, zoom, unzoom, scroll to the edges.... The (big) plan is to load a map image, "surf" through it and record every movement and zoom(vent) and then play it at custom speed

I tried to achieve this with gamemaker studio, but scrolling feels unnatural, and I think it has a bug in latest version.

I just wonder if it's possible to do this with gosu and which methods am I looking for ?
I'm fairly new to ruby/gosu, just wanted to ask before I start to dig deeper

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill