[Added] Start of player class, start of collision detection

This commit is contained in:
Ninjaws
2024-12-10 19:26:48 +01:00
parent 97d93ab113
commit 774dc3806b
18 changed files with 433 additions and 50 deletions
+12
View File
@@ -20,11 +20,13 @@ public:
{
this->watchedKeys.clear();
this->keysPressed.clear();
this->keysDown.clear();
for (int i = 0; i < keysToWatch.size(); i++)
{
this->watchedKeys.insert(keysToWatch[i]);
this->keysPressed[keysToWatch[i]] = false;
this->keysDown[keysToWatch[i]] = false;
}
setMouseButtonsToWatch(mouseButtonsToWatch);
@@ -42,10 +44,15 @@ public:
for (auto key : watchedKeys)
{
keysPressed[key] = false;
keysDown[key] = false;
if (IsKeyPressed(key))
{
keysPressed[key] = true;
}
if (IsKeyDown(key))
{
keysDown[key] = true;
}
}
for (auto button : watchedMouseButtons)
{
@@ -62,6 +69,10 @@ public:
return keysPressed[key];
}
bool isKeyDown(KeyboardKey key) {
return keysDown[key];
}
bool isMouseButtonPressed(MouseButton button)
{
return mouseButtonsPressed[button];
@@ -70,6 +81,7 @@ public:
private:
std::unordered_set<KeyboardKey> watchedKeys;
std::unordered_map<KeyboardKey, bool> keysPressed;
std::unordered_map<KeyboardKey, bool> keysDown;
std::unordered_set<MouseButton> watchedMouseButtons;
std::unordered_map<MouseButton, bool> mouseButtonsPressed;