E
E
Evgeny Petryaev2019-06-02 05:09:01
Game development
Evgeny Petryaev, 2019-06-02 05:09:01

How to make a single keypress?

In general, you need to prohibit a long press on a key, i.e. make one-time
here is part of the code

bool keyboard::IsMouseButtonUp(byte key, bool bonus, Logic *Logic_,SDL_Event event_)
{
    SDL_PollEvent(&event_);
    if(event_.type == SDL_MOUSEBUTTONUP && !bonus)
  {
    GetButtonDownCoords(event_);
    if (point.y >407 && point.y<444)
    {
      if (point.x >123 && point.x<190)
        setF(false, 0);
      if (point.x >228 && point.x<296)
        setF(false, 1);
      if (point.x >330 && point.x<401)
        setF(false, 2);
      if (point.x >436 && point.x<506)
      {
        if (getF(3))
          SetBet_(GetBet_() + 1);
        setF(false, 3);
      }
      if (point.x >543 && point.x<608)
      {
        setF(false, 4);
        setdone(true);
      }
    }
    return true;
  }
  else
    if(event_.type == SDL_MOUSEBUTTONUP && bonus&&!GetAny())
    {
      GetButtonDownCoords(event_);
      if (point.y >407 && point.y<444)
      {
        if (point.x >123 && point.x<190)
          setF(false, 0);
        if (point.x >228 && point.x<296)
          setF(false, 1);
        if (point.x >330 && point.x<401)
          setF(false, 2);
        if (point.x >436 && point.x<506)
        {
          if (getF(3))
            SetBet_(GetBet_() + 1);
          setF(false, 3);
        }
        if (point.x >543 && point.x<608)
        {
          setF(false, 4);
          setdone(true);
        }
      }
      return true;
    }
    if(event_.type == SDL_MOUSEBUTTONDOWN)
    {
    return true;
    }
  return false;
}
    bool keyboard::IsMouseButtonDown(byte key,bool bonus,SDL_Event event_)
{
    SDL_PollEvent(&event_);
    if(event_.type == SDL_MOUSEBUTTONDOWN && !bonus)
  {
    GetButtonDownCoords(event_);
    if(point.y >407 && point.y<444)
    {
      if(point.x >123 && point.x<190)
        setF(true, 0);
      if(point.x >228 && point.x<296)
        setF(true, 1);
      if (point.x > 330 && point.x < 401)
      {
        setF(true, 2);
      }
      if (point.x > 436 && point.x < 506)
        setF(true, 3);
      if(point.x >543 && point.x<608)
        setF(true, 4);
    }
    return true;
  }
  else
    if(event_.type == SDL_MOUSEBUTTONDOWN && bonus&&!GetAny())
    {
      GetButtonDownCoords(event_);
      std::cout << point.x << " " << point.y<<std::endl;
      if (point.y >407 && point.y<444)
      {
        if (point.x >123 && point.x<190)
          setF(true, 0);
        if (point.x >228 && point.x<296)
          setF(true, 1);
        if (point.x >330 && point.x<401)
          setF(true, 2);
        if (point.x >436 && point.x<506)
          setF(true, 3);
        if (point.x >543 && point.x<608)
          setF(true, 4);
      }
      return true;
    }
    if(event_.type == SDL_MOUSEBUTTONDOWN)
  {
    GetButtonDownCoords(event_);
    return true;
  }
  return false;
}
    POINT keyboard::GetButtonDownCoords()
{
  point.x=event_.button.x;
  point.y=event_.button.y;
  std::cout << "Coordinats x:" << event_.button.x << "y:"<< event_.button.y << std::endl;
  return point;
}
void Scene1::ShowDrum(int countdrums,/* float*rotate_,*/ int counttextureondrums/*, int**drum,
  int credits, int win, int totalbet, const char*line, int bet, bool*lines, int**ms*/, bool*buttons)
{
  glEnable(GL_ALPHA_TEST);
  glEnable(GL_BLEND);
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  glBlendFunc(GL_SRC_ALPHA,GL_ONE);
  glAlphaFunc(GL_GREATER, 0.0f); 
  //29.03.2019
  if (buttons[2]) {
    StartRotate();
  }
  Rotate();
  int k = -1;
  for (int i = 0; i<countdrums; i++)
  {
    glPushMatrix();
    glRotatef(rotate[i], 1, 0, 0);
    for (int j = 0; j<counttextureondrums; j++)
    {
      glBindTexture(GL_TEXTURE_2D, image->IndexTexture[FindTexture(vectordrum[GetMassive(++k)])]);
      EnableTexture(i, j);
    }
    glPopMatrix();
  }
  glPopMatrix();
  glDisable(GL_BLEND);
  glDisable(GL_ALPHA_TEST);
}
void Scene1::Rotate()
{
  for (int i = 0; i<CountDrum; i++)
  {
    if (startrotate[i])
    {
      if (rotate[i]<360.0f)
        rotate[i] += 5.0f;
      else
      {
        startrotate[i] = false;
        rotate[i] = 0.0f;
      }
    }
  }
}
void Scene1::StartRotate()
{
  for (int i = 0; i<CountDrum; i++)
  {
    if (startrotate[i] && rotate[i] != 0.0f)
      continue;
    startrotate[i] = true;
    rotate[i] = 0.0f;
    srand(time(0));
    GetRandomMassive();
  }
}

It is necessary because when you press it for a long time, startrotate () restarts where if (buttons [2]) is setF (true, 2) - press the F2 key and setF (false, 2) - release the F2 key, and here is the code for mouse button

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question