| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- // ----------------------------------------------------------------
- // From Game Programming in C++ by Sanjay Madhav
- // Copyright (C) 2017 Sanjay Madhav. All rights reserved.
- //
- // Released under the BSD License
- // See LICENSE in root directory for full details.
- // ----------------------------------------------------------------
- #pragma once
- #include <vector>
- #include "Math.h"
- #include <cstdint>
- class Actor
- {
- public:
- enum State
- {
- EActive,
- EPaused,
- EDead
- };
- Actor(class Game* game);
- virtual ~Actor();
- // Update function called from Game (not overridable)
- void Update(float deltaTime);
- // Updates all the components attached to the actor (not overridable)
- void UpdateComponents(float deltaTime);
- // Any actor-specific update code (overridable)
- virtual void UpdateActor(float deltaTime);
- // ProcessInput function called from Game (not overridable)
- void ProcessInput(const uint8_t* keyState);
- // Any actor-specific input code (overridable)
- virtual void ActorInput(const uint8_t* keyState);
- // Getters/setters
- const Vector2& GetPosition() const { return mPosition; }
- void SetPosition(const Vector2& pos) { mPosition = pos; }
- float GetScale() const { return mScale; }
- void SetScale(float scale) { mScale = scale; }
- float GetRotation() const { return mRotation; }
- void SetRotation(float rotation) { mRotation = rotation; }
- Vector2 GetForward() const { return Vector2(Math::Cos(mRotation), -Math::Sin(mRotation)); }
- State GetState() const { return mState; }
- void SetState(State state) { mState = state; }
- class Game* GetGame() { return mGame; }
- // Add/remove components
- void AddComponent(class Component* component);
- void RemoveComponent(class Component* component);
- private:
- // Actor's state
- State mState;
- // Transform
- Vector2 mPosition;
- float mScale;
- float mRotation;
- std::vector<class Component*> mComponents;
- class Game* mGame;
- };
|