New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Gosu examples: available keys? #576
Comments
Hmm found it already. Via google though. :D https://www.rubydoc.info/gems/minigl/2.0.4/MiniGL/KB Perhaps I will contribute my own implementation here some time later; https://www.gamedev.net/blogs/entry/2254256-tetris-in-ruby/ By the way, perhaps we could have a meta-gem for gosu-games People move on a lot, due to reallife and stuff. But for new generation |
I use this require 'gosu'
module Gosu
module Button
NAME_MAP =
constants
.each_with_object({}.compare_by_identity) do |name, ret|
ret[Button.const_get(name)] = name
end
.freeze
def self.name(button_id)
NAME_MAP[button_id] || button_id.to_s
end
end
end With this you can call |
Iterating through |
Mmmm - I prefer to have such "magic constants" in a separate module - it works like a namespace and allows something like the code above. Ruby |
Ooohh, thanks for the pointer! Looks like it has been introduced in Ruby 2.4, which is safe to use in Gosu now. |
By the way, you can work around the lack of a namespace in the global Gosu module by grepping for |
@mblumtritt Resurrecting this issue because I just got a chance to play around with Module#deprecate_constant. Does it work for you? It has almost no documentation and doesn't emit anything in quick tests. Maybe I'm doing it wrong? (Haven't checked out the C source code yet.) |
module Gosu
KB_SPACE = 0
KbSpace = KB_SPACE
deprecate_constant :KbSpace
end
puts Gosu::KbSpace, Gosu::KB_SPACE I just ran this and also didn't get any warning. I added the
|
Oooohh, I forgot about -w 🤦♂️ Well, it's almost useless then, but I'll start using it regardless. Our own const deprecation mechanism still has the issue that Edit: Also, thanks! |
@mblumtritt Thanks, but unlike in a "normal" Ruby project I'm trying my best to avoid dependencies, mostly because I've been burned by all the sketchy deployment processes that are in use for Ruby/Gosu games. |
Hey guys,
I am currently SLOWLY (really slowly) ... learning Gosu.
I know a lot of ruby; also a lot of ruby-gtk.
I am also reading other people's old Gosu code. :D
(I work so much faster with working examples that I can tweak).
Anyway - I am currently studying and modifying an old tetris game
written in gosu from 2012 (almost 10 years old!).
There is a lot of code checks like:
if button_down?(Gosu::KbSpace)
if button_down?(Gosu::KbEscape)
I assume these are keys gosu registered. I am sure I can look
up somewhere too BUT! Being a very lazy person, I was
wondering whether the examples/ directory could simply
have a tiny widget that outputs the name of the keys when
pressed?
That way gosu-users can quickly find out on their own,
without even having to read online documentation. I am
sure I'll find out in a few hours from now on anyway (that
happened to me with ruby-gtk; I found solutions accidentally
heheh), but before I forget it, I wanted to suggest to
add such a small .rb file as an example.
Really simple!
Something that, in pseudo code, says:
"if user hits the escape-key, output the name of the constant on the commandline".
The text was updated successfully, but these errors were encountered: