Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Forum
Search
Topic Make lots of random sprites move in a 'wave' pattern By max_n_ruby Date 2017-06-19 23:30
Nice! Thanks. I didn't know ||= was a thing. :)
Topic Make lots of random sprites move in a 'wave' pattern By max_n_ruby Date 2017-06-17 01:43
That works. I was overthinking the problem. I thought I could do it within a method without additional instance variables. But especially because I have a lot of random sprites, I need the additional instance variables.
Thanks for your feedback.
Topic Make lots of random sprites move in a 'wave' pattern By max_n_ruby Date 2017-06-15 19:45
Here's my problem I've been working on for a while.
I have a shoot-em-up with lots of randomly generated sprites. I want to have the sprites move in a wave or oscillating pattern as they cross the screen. Basically the sprites will move across the screen. Bouncing up and down between two points within the Gosu window.  So they'll be harder to hit.
I've been trying to do this in a method of my 'Enemies' class. The method is called wave.

def wave
  top_of_wave = @y_sprite_coordinate - 20
  bottom_of_wave =@y_sprite_coordinate + 20
  sprite_at_top_of_wave = false
  #heres some pseudo code
if sprite_at_top_of_wave is false and @y_sprite_coordinate is greater than top_of_wave
  then @y_sprite_coordinate -= 5
else if @y_sprite_coordinate <= top_of_wave
  then sprite_at_top_of_wave = true
  else if sprite_at_top_of_wave == true and @y_sprite_coordinate is less than bottom_of_wave
then @y_sprite_coordinate += 5
  else if @y_sprite_coordinate greater than bottom_of_wave
  then sprite_at_top_of_wave = true
end


I write this code but then the sprites just move UP or @y_sprite_coordinate -= 5 I think this is happening because it calls the method during the update phase. So I think its calling the method 60 times a second. If that's the case then the method just keeps resetting the @y_sprite_coordinate  and it goes up and up and up.

Any suggestions on how to solve this?
Topic Two gamepad buttons at once? By max_n_ruby Date 2017-05-25 21:32
Ok. that makes sense. I'll give it a try.
Thx :)
Topic Two gamepad buttons at once? By max_n_ruby Date 2017-05-24 22:37
Can you do it? Press two gamepad buttons at once? I want to press a direction on the D pad and press a button and have something happen.

I've tried

def button_down(id)
  if id == Gosu::GP_BUTTON_1 and Gosu::GP_RIGHT
    #do thing
  end
end


and I've tried

def button_down(id)
  case id
    when (Gosu::BUTTON_1 and Gosu::GP_RIGHT)
      #do thing
    end
end


When I run the code it does #thing only when I press the second button. The buttons don't seem to work together. The one that fulfills the if/then statement or the case statement is the last thing. ie: Gosu::GP_RIGHT

Is this a limitation of ruby? Or Gosu?
Or am I not getting something?
Topic How does the Map Class in Captain Ruby work? By max_n_ruby Date 2016-11-16 02:31
Thanks for the reply.
That helped a lot to figure it out in IRB.
Previously I was loading the entire Map class into IRB. Breaking it down to the individual methods and processes made a difference.
Topic How does the Map Class in Captain Ruby work? By max_n_ruby Date 2016-11-14 23:41
How does Gosu get the tiles on the screen?
While trying to write my own map class I use some code to assign every tile a pixel coordinate. Gosu then draws the tile where I want it.
But in Captain Ruby game, the Map class reads an array full of either ones or zeros and somehow knows where to put the tiles on the screen.
Here's where it creates the array the maps are in.

@tiles = Array.new(@width) do |x|
      Array.new(@height) do |y|
        case lines[y][x, 1]
        when '"'
          Tiles::Grass
        when '#'
          Tiles::Earth
        when 'x'
          @gems.push(CollectibleGem.new(gem_img, x * 50 + 25, y * 50 + 25))
          nil
        else
          nil
        end
      end
    end


Here we get the multi-dimensional array. It's full of 1's and 0's and nil. (I'm ignoring the gems for right now. Trying to keep things simple.)
This array becomes the raw material for the draw method:

def draw
    # Very primitive drawing function:
    # Draws all the tiles, some off-screen, some on-screen.
    @height.times do |y|
      @width.times do |x|
        tile = @tiles[x][y]
        if tile
          # Draw the tile with an offset (tile images have some overlap)
          # Scrolling is implemented here just as in the game objects.
          @tileset[tile].draw(x * 50 - 5, y * 50 - 5, 0)
        end
      end
    end
    @gems.each { |c| c.draw }
  end


This draw method is hard for me to understand. I don't know enough about ruby to decipher what's going on here.
What I do know:
I know the .times method. We do 'something' @height and @width times. Where height and width are the values taken from the map text file.
I get a little fuzzy when it creates the tile variable.
Then we get to the Gosu draw method.
The method parameters x * 50 -5 & y * 50 -5 decide where the tiles are drawn in the window.(I think.) But I don't understand what the x and y are and why you times them by 50. I mean, I know that x and y represent items in the @tiles array but... I'm confused :)
Any help to clarify would be appreciated.
Topic Collision detection in a roguelike By max_n_ruby Date 2016-01-05 02:51
Yes. In this roguelike the player will move one 'square' at a time. In this case, the squares are 20 px high. I'm actually not sure how wide the Gosu::Font class makes things. I'll look that up.

I'll try this out. Thanks!
Topic Gosu without Xcode on Mac By max_n_ruby Date 2016-01-04 14:41
I was clearing out hard drive space on my Macbook Air and I deleted Xcode. Has anyone had any problems with using ruby and/or Gosu without Xcode?
When I installed Gosu I had to open Xcode and agree to the terms so that Gosu would download. I think It needed command line tools or something to get Gosu working.
Now that I've deleted Xcode, Gosu seems to be working fine without it.
Will this give me any problems in the future?
Topic Collision detection in a roguelike By max_n_ruby Date 2016-01-04 14:24
Yes, I am comparing points. I think I'm on the right track because my solid? method returns true/false when it's next to a map tile.
But I'll try out comparing area to area. See what happens.
Here's a link to my code:
https://github.com/ceejaay/ruby_rogue/blob/master/map.rb#L19-L20

My solid? method is only checking for a map tile in one direction right now.

When I run the program, I get this:

[http://i.imgur.com/6883y7W.png?1]

I'm not sure if it matters, but I'm using text instead of sprites. If I'm correct the X/Y coordinates I'm using start from the top-left corner of the text.

What I'm having trouble with now is checking for which button is being pressed and if the space next to the player is occupied by a map tile.
Plus, I guess I have to check for map tiles in all four directions at the same time.
I think I'm missing a fundamental programming concept. I'm still working through it.
You can see from my code where I've tried some things.
https://github.com/ceejaay/ruby_rogue/blob/master/map.rb#L21-L36

I'll show some of my other attempts at solutions later. I have like 4 branches in my code trying to figure this out. :)
Thanks for your response!
Topic Collision detection in a roguelike By max_n_ruby Date 2016-01-03 00:14
Ha ha!
  @x and @y are the x and y coordinates of the tile in the Map class. Sorry.
Thanks. I didn't think of this. I'll give it a try.
Topic Collision detection in a roguelike By max_n_ruby Date 2016-01-02 22:36
I'm writing a basic roguelike and I can't figure out collision detection from all four sides. Looking for suggestions.

I've been trying this method from the Captain Ruby code:

     def solid?(x, y)
      @x.between?(x, x + 20) and @y.between?(y, y + 20)
    end


This method is in my Map class. It detects collisions on two of four sides.

If I reverse the instance variable and the method arguments like so:

      def solid?(x, y)
          x.between?(@x, @x + 20) and y.between(@y, @y + 20)
        end


It detects collisions on the other 2 of 4 sides. :P

Any suggestions on how to put this into one method?

side note: I really like Gosu. With my modest ruby knowledge I've been able to make some real strides on making games. :D

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill