Skip to content

Latest commit

 

History

History
75 lines (64 loc) · 3.67 KB

3.4. Functions and 3.4.1. input.h.md

File metadata and controls

75 lines (64 loc) · 3.67 KB

3.4. Functions

This section was last checked in the 2.0.3. version of the engine

This section of the third chapter of the documentation will not go over the functions in order of appearance (as opposed to the previous sections) but in the order that they are in their header files. Thus this section will have the following parts:

3.4.1. input.h

This section was last checked in the 2.0.3. version of the engine

This header file contains functions that deal with the input coming form the keyboard.

3.4.1.1. ___Pressed

This section was last checked in the 2.0.3. version of the engine
//   These functions return true if the correct button was pressed.
bool wPressed()
{
	return (GetKeyState('W') & 0x8000);
}

bool aPressed()
{
	return (GetKeyState('A') & 0x8000);
}

bool sPressed()
{
	return (GetKeyState('S') & 0x8000);
}

bool dPressed()
{
	return (GetKeyState('D') & 0x8000);
}

bool ePressed()
{
	return (GetKeyState('E') & 0x8000);
}

bool escPressed()
{
	return (GetKeyState(VK_ESCAPE) & 0x8000);
}

Usage: These functions return true when the correct key is pressed down.

Variables: -

How it's done & notes: The functions use another function called GetKeyState. This function can be found in the windows.h header which contains lots of useful functions from the windows API. The ___Pressed functions are one of the three places where I used external resources to solve a problem (this was before version 2.0.2.). The other link I used to write these can be found here. To reduce the amount of clutter for the 3.0.0. version I plan to write a universal keyPressed function, so one function will be able to deal with all the key presses.

3.4.1.2. cancelOut

This section was last checked in the 2.0.3. version of the engine
//   This function sets two bools to false if they were both true.
void cancelOut (bool plus, bool minus)
{
	//   The function checks if both of the bools are true, if they are it sets them to
	// fasle.
	if (plus && minus)
	{
		plus = false;
		minus = false;
	}
}

Usage: This function cancels out two bools if they are both true.

Variables:

  • plus: Holds the first bool we want to check.
  • minus: Holds the second bool we want to check.

How it's done & notes: We check if both of the variables are true. If they are we set them both to false. This is used to cancel out contradictory input (for example when both the 'A' and 'D' keys are pressed), but it could be used for any form of cancellation of contradictory bools.