Nox Engine
 
Loading...
Searching...
No Matches
Controller.h
Go to the documentation of this file.
1
6#pragma once
7
8#include "Collider.h"
9#include "ECS.h"
10#include <csignal>
11
16struct Controller : public Component {
17public:
18 Controller();
20
24 void init() override;
29 void updateKeyDown(SDL_Keycode key);
34 void updateKeyUp(SDL_Keycode key);
38 void update() override;
42 void reload() override;
43
44private:
45 Vector2D lastVel;
46 int lastAngle;
47 Transform* transform;
48 Collider* collider;
49
50 std::unordered_map<SDL_Keycode, bool> KEY_STATES {
51 { SDLK_w, false },
52 { SDLK_s, false },
53 { SDLK_a, false },
54 { SDLK_d, false },
55 };
56};
Defines a component for collision detection.
Defines the core classes for the Entity-Component-System (ECS) architecture.
Provides an entity with a physical bounding box for collision detection.
Definition Collider.h:22
The base class for all components in the ECS.
Definition ECS.h:53
Translates keyboard input (WASD) into entity movement.
Definition Controller.h:16
void updateKeyDown(SDL_Keycode key)
Updates the state when a key is pressed down.
Definition Controller.cpp:20
void update() override
Calculates and applies velocity to the Transform based on current key states.
Definition Controller.cpp:30
void reload() override
Resets the controller's state.
Definition Controller.cpp:66
void updateKeyUp(SDL_Keycode key)
Updates the state when a key is released.
Definition Controller.cpp:25
void init() override
Initializes the controller, grabbing the entity's Transform and Collider.
Definition Controller.cpp:10
Stores an entity's position, velocity, scale, and rotation.
Definition Transform.h:17
A simple struct for 2D mathematics (points, vectors).
Definition Vector2D.h:15