Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualBeerNutts

Posted 10 December 2012 - 01:06 PM

Something else to consider would be to check the Input every frame; if a key is down, mark it in an Input Object, if it's not leave blank (false); then, you can pass the Input object to anyone who wants to know about Input. Like this (pseudo-code):

struct TInput {
  bool IsLeftPressed;
  bool IsRightPressed;
  bool IsUpPressed;
  bool IsFirePressed;
  bool IsJumpPressed;
};

// create this funciton to get the current keys being pressed
void GetInput(TInput& input)
{
  while(PollKeyEvent(&keyEvent) {
    if (keyEvent.IsPressed) {
      if (keyEvent.keycode == LEFT_KEY) {
        input.IsLeftPressed;
      }
      if (keyEvent.keycode == UP_KEY) {
        input.IsUpPressed;
      }
      // Continue checking them all
    }
  }
}

// in Main loop
while(IsRunning) {
  TInput input;
  GetInput(input);

  // now pass the input into your Update functions, which would check input.IsFirePressed to see if the user is pressing fire, etc.
  Player.Update(input);

  // Call other update functions for enemies, objects, background, etc as well as rendering for them.

#1BeerNutts

Posted 10 December 2012 - 01:04 PM

Something else to consider would be to check the Input every frame; if a key is down, mark it in an Input Object, if it's not leave blank (false); then, you can pass the Input object to anyone who wants to know about Input. Like this (pseudo-code):

struct TInput {
  bool IsLeftPressed;
  bool IsRightPressed;
  bool IsUpPressed;
  bool IsFirePressed;
  bool IsJumpPressed;
};

// in Main loop
TInput input;
while(PollKeyEvent(&keyEvent) {
  if (keyEvent.IsPressed) {
    if (keyEvent.keycode == LEFT_KEY) {
      input.IsLeftPressed;
    }
    if (keyEvent.keycode == UP_KEY) {
	  input.IsUpPressed;
    }
    // Continue checking them all
  }
}

// now pass the input into your Update functions, which would check input.IsFirePressed to see if the user is pressing fire, etc.
Player.Update(input);

PARTNERS