Forums Archived

The forums are being archived. See this topic for more information.

Mouse Pointer Events

Get help and support with Rubygame

Mouse Pointer Events

Postby KojaK » Tue Jun 29, 2010 3:05 am

So I noticed that there are events handling information coming from the mouse, but is there information on exactly what it's doing? I tried to look in the documentation but could not find the events relating to the mouse and where it is in-game.

I'm attempting to design a strategy game that I will build on over time. In order to do this, I need to be able to use the mouse to select soldiers.

Any information would be greatly appreciated, even if it's just a link to the documentation on mouse pointer events. I've worked with less in the past. ^.^
KojaK
 
Posts: 4
Joined: Tue Jun 29, 2010 2:59 am

Re: Mouse Pointer Events

Postby jacius » Tue Jun 29, 2010 4:26 am

Hello and welcome! :)

Here are links to the documentation for the most important mouse-related events:

You get these events by EventQueue and call enable_new_style_events. Then you can call each with a block to handle the events. E.g.:

Code: Select all
# Press Q key to quit

require 'rubygame'

screen = Rubygame::Screen.open([640,480])
queue = Rubygame::EventQueue.new
queue.enable_new_style_events

loop {
  queue.each { |event|
    case event
    when Rubygame::Events::MousePressed
      puts "Pressed #{event.button} at #{event.pos}"
    when Rubygame::Events::MouseReleased
      puts "Released #{event.button} at #{event.pos}"
    when Rubygame::Events::MouseMoved
      puts "Mouse moved to #{event.pos} with #{event.buttons.inspect} pressed"
    when Rubygame::Events::KeyPressed
      if event.key == :q
        puts "Quitting. Bye!"
        exit 0
      end
    end
  }
  sleep 0.01
}

Rubygame also offers a more high-level set of classes for handling events. Checkout EventHandler to get started, and also have a look at demo_rubygame.rb for a running example.

If you have any more questions, feel free to ask. :)
User avatar
jacius
Site Admin
 
Posts: 131
Joined: Fri Feb 06, 2009 11:13 pm

Re: Mouse Pointer Events

Postby KojaK » Wed Jun 30, 2010 7:28 pm

Thanks for all the help! ^.^

However, I'm also kinda lazy, so I have another question. How would I recreate the traditional green box you see in strategy games? Is there a method in Rubygame that allows you to draw lines on the screen, or do I have to make a new image, but make it very thin and fill it with green?

Also, on a completely unrelated note, if you have any suggestions for code that gives the player a window into the map, like a Command and Conquer style system, I would really appreciate it.
KojaK
 
Posts: 4
Joined: Tue Jun 29, 2010 2:59 am

Re: Mouse Pointer Events

Postby jacius » Thu Jul 01, 2010 6:21 am

KojaK wrote:How would I recreate the traditional green box you see in strategy games? Is there a method in Rubygame that allows you to draw lines on the screen, or do I have to make a new image, but make it very thin and fill it with green?

The Surface class has a variety of "draw" methods for drawing shapes. "draw_box" will allow you to draw a shape like you want. And because Screen is a special kind of Surface, it also has all the draw methods, so you can draw directly on the Screen if you want.

KojaK wrote:Also, on a completely unrelated note, if you have any suggestions for code that gives the player a window into the map, like a Command and Conquer style system, I would really appreciate it.

I'm afraid I don't understand what you mean by "window into the map". Could you explain more?
User avatar
jacius
Site Admin
 
Posts: 131
Joined: Fri Feb 06, 2009 11:13 pm

Re: Mouse Pointer Events

Postby shawn42 » Thu Jul 01, 2010 8:57 pm

An RTS reference:

You might want to glance at Snelps to see an example of an RTS in Rubygame.

http://github.com/shawn42/snelps

HTH
User avatar
shawn42
 
Posts: 109
Joined: Tue Feb 10, 2009 8:22 pm

Re: Mouse Pointer Events

Postby KojaK » Mon Jul 05, 2010 5:45 am

jacius wrote:I'm afraid I don't understand what you mean by "window into the map". Could you explain more?


Yeah I thought I didn't explain that properly. I want the map the player plays on to be larger than the screen itself. I'd have buildings and soldiers determine their positions based on the background map, and not the screen. This means that the player can move the screen to see different parts of the map. And that also means that I need to keep track of what the player is looking at, and then determine what needs to draw itself to the screen, and where.

I don't really expect any help on that front though. I was just curious about whether or not there were any rubygame methods that could make my life easier there. ^.^

Also, thanks for the link shawn. I will definitely check it out.
KojaK
 
Posts: 4
Joined: Tue Jun 29, 2010 2:59 am

Re: Mouse Pointer Events

Postby KojaK » Tue Jul 06, 2010 4:43 am

So I just looked at Snelps... and I must say, it has all the features I was looking for. The ability to move the screen to see different parts of the map, a sidebar, and pathfinding. Even a little mini-map there.

So if you don't mind, I will take time now to poke around the code for Snelps, and get some ideas.

^.^

Once again, thanks for all the help. :D
KojaK
 
Posts: 4
Joined: Tue Jun 29, 2010 2:59 am

Re: Mouse Pointer Events

Postby shawn42 » Tue Jul 06, 2010 12:55 pm

Great, glad I could help. As for the pathfinding, I'd use my newer pathfinding code in the polaris gem (its more accurate and faster).

You could also look into Gamebox to build your game, as it will help get you started and give you some structure to follow.

:D
User avatar
shawn42
 
Posts: 109
Joined: Tue Feb 10, 2009 8:22 pm


Return to Help & Support

Who is online

Users browsing this forum: No registered users and 1 guest

cron