35 lines
1.0 KiB
C++
35 lines
1.0 KiB
C++
// Copyright (c) 2023 Dominic Masters
|
|
//
|
|
// This software is released under the MIT License.
|
|
// https://opensource.org/licenses/MIT
|
|
|
|
#include "PlayerController.hpp"
|
|
#include "game/DawnGame.hpp"
|
|
|
|
using namespace Dawn;
|
|
|
|
PlayerController::PlayerController(SceneItem *i) : SceneItemComponent(i) {}
|
|
|
|
void PlayerController::onSceneUpdate() {
|
|
auto im = &getGame()->inputManager;
|
|
auto delta = getGame()->timeManager.delta;
|
|
|
|
glm::vec2 iMove = im->getAxis2D(
|
|
INPUT_BIND_NEGATIVE_X, INPUT_BIND_POSITIVE_X,
|
|
INPUT_BIND_NEGATIVE_Y, INPUT_BIND_POSITIVE_Y
|
|
);
|
|
|
|
glm::vec2 pos = this->transform->getLocalPosition();
|
|
this->transform->setLocalPosition(
|
|
this->transform->getLocalPosition() + glm::vec3(iMove * delta * 20.0f, 0)
|
|
);
|
|
}
|
|
|
|
void PlayerController::onStart() {
|
|
assertNotNull(this->camera);
|
|
getScene()->eventSceneUnpausedUpdate.addListener(this, &PlayerController::onSceneUpdate);
|
|
}
|
|
|
|
PlayerController::~PlayerController() {
|
|
getScene()->eventSceneUnpausedUpdate.removeListener(this, &PlayerController::onSceneUpdate);
|
|
} |