controller and mouse support

This commit is contained in:
2024-09-13 12:12:31 +01:00
parent 9e7ba471ae
commit fa76489449
5 changed files with 91 additions and 16 deletions

View File

@@ -2,6 +2,27 @@
#include <map>
#include <string>
struct Controller
{
SDL_GameController* controller;
std::string name;
std::map<Uint8, bool> buttons;
Sint16 leftStickX = 0;
Sint16 leftStickY = 0;
Sint16 rightStickX = 0;
Sint16 rightStickY = 0;
Sint16 leftTrigger = 0;
Sint16 rightTrigger = 0;
};
struct Mouse
{
int x;
int y;
int wheel;
std::map<int, bool> buttons;
};
class Input
{
private:
@@ -9,6 +30,10 @@ class Input
public:
bool exit;
std::map<int, Controller> controllers;
std::map<SDL_Keycode, bool> activeKeys;
Mouse mouse;
Input();
void update();
};

View File

@@ -1,9 +1,14 @@
// prevent multiple inclusion
#pragma once
// class for 2D float vector
class float_vec2
{
// public members
public:
// x and y coordinates
float x, y;
// operator functions
float_vec2 operator+(float_vec2 vec)
{
return { x + vec.x, y + vec.y };
@@ -26,10 +31,14 @@ class float_vec2
}
};
// class for 2D integer vector
class int_vec2
{
// public members
public:
// x and y coordinates
int x, y;
// operator functions
int_vec2 operator+(int_vec2 vec)
{
return { x + vec.x, y + vec.y };