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):
def update
@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
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.
Loading...