Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Only 2 keys at the same time  (Read 4307 times)

0 Members and 1 Guest are viewing this topic.

CptnRoughnight

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Only 2 keys at the same time
« on: September 21, 2016, 11:27:11 am »
Hi dudes,

I've searched for several days now and did'nt find anything. I'm writing an asteroids-like game (classic and extended version) and I'm stuck at Game Input. My Gameloop follows the instruction from http://www.koonsolo.com/news/dewitters-gameloop/ .

All is working fine, gameloop,interpolation movement. But if I want to fly my ship away from those nasty asteroids and start shooting another the input stucks at two keys. So I can accelerate and rotate, or accelerate and shoot, or rotate and shoot. But not accelerate,rotate and shoot at the same time.

I'm using SFML 2.1(config.hpp) on Linux Mint 17.1. I query the keys by using

if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
{
           // rotate
}
 

Can someone help me to figure out the problem?

regards
CptnRoughnight
I am Cptn. Ferdinand Darth Roughnight Timelord of the ancient Enterprise Earl of Tatooine.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
AW: Only 2 keys at the same time
« Reply #1 on: September 21, 2016, 11:28:26 am »
What keys are you using? What's your code?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

CptnRoughnight

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: Only 2 keys at the same time
« Reply #2 on: September 21, 2016, 11:31:00 am »
My bad.. 

here's the code:

 if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
    {
        rotangle += rotspeed;
    }

    if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
    {
        rotangle -= rotspeed;
    }

    if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
    {
        speed += acc;

        if (speed>maxspeed)
            speed=maxspeed;

             // when the user wants to move forward:
        radangle = rotangle * M_PI / 180;

        vel_x += cos( radangle ) * acc * 1.0f;
        vel_y -= sin( radangle ) * acc * 1.0f;

        totalvelocity = sqrt( (vel_x*vel_x) + (vel_y*vel_y) );

        if( totalvelocity > maxspeed )
        {
            // ship is moving too fast.  Scale the velocity down
            vel_x *= maxspeed / totalvelocity;
            vel_y *= maxspeed / totalvelocity;
        }
    }

    if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
    {
        vel_x *= brake;
        vel_y *= brake;
    }

    if (sf::Keyboard::isKeyPressed(sf::Keyboard::Space))
    {
        // bullets abfeuern
        if (starttime+wpDelay < GetTicks())
        {
            starttime = GetTicks();
            Bullet *dummy = new Bullet(this->posx,this->posy,this->vel_x,this->vel_y,this->rotangle);
            bullets->push_back(*dummy);
            delete dummy;
        }
    }
I am Cptn. Ferdinand Darth Roughnight Timelord of the ancient Enterprise Earl of Tatooine.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Only 2 keys at the same time
« Reply #3 on: September 21, 2016, 11:50:35 am »
Laurent Gomila - SFML developer

CptnRoughnight

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: Only 2 keys at the same time
« Reply #4 on: September 21, 2016, 11:55:43 am »
 ???

wow... i changed to LControl for shooting and all is working...

thank you very much. I didn't thought of that at all.
I am Cptn. Ferdinand Darth Roughnight Timelord of the ancient Enterprise Earl of Tatooine.