Just breaking stuff
This commit is contained in:
10
archive/dawnplatformergame/components/CMakeLists.txt
Normal file
10
archive/dawnplatformergame/components/CMakeLists.txt
Normal file
@ -0,0 +1,10 @@
|
||||
# Copyright (c) 2023 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Sources
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
PlayerController.cpp
|
||||
)
|
35
archive/dawnplatformergame/components/PlayerController.cpp
Normal file
35
archive/dawnplatformergame/components/PlayerController.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
// 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);
|
||||
}
|
23
archive/dawnplatformergame/components/PlayerController.hpp
Normal file
23
archive/dawnplatformergame/components/PlayerController.hpp
Normal file
@ -0,0 +1,23 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "scene/components/Components.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class PlayerController : public SceneItemComponent {
|
||||
protected:
|
||||
void onSceneUpdate();
|
||||
|
||||
public:
|
||||
Camera *camera = nullptr;
|
||||
|
||||
PlayerController(SceneItem *item);
|
||||
|
||||
void onStart() override;
|
||||
|
||||
~PlayerController();
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user