[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
+5
View File
@@ -9,6 +9,7 @@
#include "enums/EMusic.h"
#include "enums/EBackground.h"
#include "enums/EMap.h"
#include "enums/ESprite.h"
#include "services/Service.h"
class AssetService: public Service<AssetService>
@@ -27,6 +28,9 @@ public:
std::string getMapUrl(EMap map) {
return this->assetDir + this->maps[map];
}
Texture2D getSprite(ESprite sprite) {
return this->sprites[sprite];
}
protected:
AssetService();
@@ -41,6 +45,7 @@ private:
std::unordered_map<EMusic, Music> music;
std::unordered_map<EBackground, Texture2D> backgrounds;
std::unordered_map<EMap, std::string> maps;
std::unordered_map<ESprite, Texture2D> sprites;
void setAssets();
+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;
+27
View File
@@ -0,0 +1,27 @@
#ifndef MAP_SERVICE_H
#define MAP_SERVICE_H
#include "services/Service.h"
#include "entities/Map.h"
#include "entities/TextureWrapper.h"
/**
* Allows all rigidbodies to check against the current Map
*/
class MapService : public Service<MapService>
{
public:
void setMap(Map map)
{
this->map = Map();
}
Map& getMap() {
return this->map;
}
private:
Map map;
};
#endif