Good day, everyone.
I'm working on a shooter project (you know, another classic 2d sh'mup) merely as a way to learn to program games with Ruby (and Gosu of course).
I'm really enjoying my experience, so I try to figure out every problem I come across. But, unfortunately, I don't have the slightest idea what to do with this. I already made a search on the forums, but I didn't find a similar post (maybe there is, but I overlooked it).
Long story short, I have my standard ship, which can move up, down, left, right, and shoot. Here's the code for the update method of the Player class (which is passed to the main window through a manager):
@x = @last_x if @x < 0 || @x > $window.width
@y = @last_y if @y < 0 || @y > $window.height
@last_x, @last_y = @x, @y
if button_down? Gosu::KbLeft or button_down? Gosu::GpLeft then izquierda end
if button_down? Gosu::KbRight or button_down? Gosu::GpRight then derecha end
if button_down? Gosu::KbUp or button_down? Gosu::GpUp then arriba end
if button_down? Gosu::KbDown or button_down? Gosu::GpDown then abajo end
if button_down? Gosu::KbZ or button_down? Gosu::GpButton1 then fire end
I used "button_down?", because I need that the player keeps moving as along as I press the direction, and keeps shooting while holding down the Z key. When I test it, it does well, I can press 2 directions and it goes in angles (8 ways). And if I press 2 opposing keys, the player stays in place (as expected). If I shoot, the bullets keep coming.
The problem is, that it seems that Gosu can't handle more than 2 inputs at the same time, because if I'm not shooting, player can move 8-way, but if I'm shooting, thent player can only move 4 way. In other words, while I'm holding the Z button, the game only recognizes one other button, one of the arrows. This is a problem, because on a sh'ump you need to dodge enemy bullets from any direction, and that means you have to be able to move 8 ways while shooting.
So, the question is: is there a way to solve this? can I make Gosu to handle both things (8way move + shooting) at the same time?
Thanks in advance for any answer.
Have you tried using a different key than Z? I know that keyboards used to have bizarre limits on which keys you could press at the same time. It was usually the safest choice to use non-letter keys like shift and ctrl. Or do you have a gamepad to test this with?
In any case, this doesn't look like a problem with your code :)
Thanks for your answer. I just tried it, and these are my results:
First, I changed " if button_down? Gosu::KbZ" for " if button_down? Gosu::KbSpace", and the player could go 7ways while shooting (it couldn't go northwest).
Then I tried with " if button_down? Gosu::KbLeftShift", and then it could go 8way while shooting. At last :)
Thanks a lot, I would never thought the problem would be the keyboard itself. Go figure.
Thanks for the link, that was a really interesting read. It's useful to know about gosthing and jamming :)
I still have some questions about it, I may look a little further into it later. For example, I recalled why I used Z key in the first place, and it was because that's the default key for shooting on the Touhou series. I played Touhou 6 before posting, just to be sure, and I was right: you use arrows to move, Z to shoot, and X to bomb; but the game didn't have any trouble handling all the inputs (and I'm using the same keyboard).
I even tried to force a jamming, but I couldn't (with 2 arrows + shooting, or even 2 arrows + another key + shooting). So that makes me think the game itself has something to do with the handling. Certainly a point I want to research a little more.
Thanks again :)
Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill