controller and mouse support
This commit is contained in:
		@@ -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();
 | 
			
		||||
};
 | 
			
		||||
@@ -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 };
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user