Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
ReallyWeirdCat authored May 8, 2023
1 parent d98a047 commit cfc0edb
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
45 changes: 45 additions & 0 deletions ПР13/Keyboard.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include "Keyboard.h"

void Keyboard::init()
{ }

void Keyboard::update()
{
keyListen();
}

Keyboard::Keyboard()
{
filter = {};
}

Keyboard::Keyboard(std::set<SDL_Keycode> Filter)
{
filter = Filter;
}

void Keyboard::keyListen()
{
if (Game::event.type == SDL_KEYDOWN) {
keys.insert(Game::event.key.keysym.sym);
}

if (Game::event.type == SDL_KEYUP) {
keys.erase(Game::event.key.keysym.sym);
}
if (filter.size()) {
std::set<SDL_Keycode> temp;
std::set_intersection(keys.begin(), keys.end(), filter.begin(), filter.end(), std::inserter(temp, temp.begin()));
keys = temp;
}
}

std::set<SDL_Keycode> Keyboard::getKeys()
{
return keys;
}

bool Keyboard::key(SDL_Keycode k)
{
return keys.find(k) != keys.end();
}
29 changes: 29 additions & 0 deletions ПР13/Keyboard.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once

#include "Game.h"
#include "ECS.h"
#include "Components.h"
#include <set>
#include <algorithm>

class Keyboard : public Component
{
private:
std::set<SDL_Keycode> keys;
std::set<SDL_Keycode> filter;
public:

Keyboard();

Keyboard(std::set<SDL_Keycode> Filter);

void init() override;

void update() override;

void keyListen();

std::set<SDL_Keycode> getKeys();

bool key(SDL_Keycode);
};

0 comments on commit cfc0edb

Please sign in to comment.