Fixed input
This commit is contained in:
@ -6,4 +6,5 @@
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
Entity.cpp
|
||||
Player.cpp
|
||||
)
|
@ -10,7 +10,7 @@ using namespace Dawn;
|
||||
|
||||
void Entity::onInit() {
|
||||
auto world = this->world.lock();
|
||||
assertNotNull(world, "World is no longer active.");
|
||||
assertNotNull(world, "World is no longer active? ");
|
||||
}
|
||||
|
||||
void Entity::onDispose() {
|
||||
|
23
src/dawnrpg/component/entity/Player.cpp
Normal file
23
src/dawnrpg/component/entity/Player.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
// Copyright (c) 2024 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "Player.hpp"
|
||||
#include "scene/Scene.hpp"
|
||||
#include "input/InputBinds.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
void Player::onInit() {
|
||||
listenerUpdate = getScene()->onUnpausedUpdate.listen([this](float delta) {
|
||||
InputManager &im = getGame()->inputManager;
|
||||
if(im.isDown(InputBind::Up)) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void Player::onDispose() {
|
||||
listenerUpdate();
|
||||
}
|
18
src/dawnrpg/component/entity/Player.hpp
Normal file
18
src/dawnrpg/component/entity/Player.hpp
Normal file
@ -0,0 +1,18 @@
|
||||
// Copyright (c) 2024 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "scene/SceneComponent.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class Player : public SceneComponent {
|
||||
protected:
|
||||
std::function<void()> listenerUpdate;
|
||||
|
||||
public:
|
||||
void onInit() override;
|
||||
void onDispose() override;
|
||||
};
|
||||
}
|
13
src/dawnrpg/input/InputBinds.hpp
Normal file
13
src/dawnrpg/input/InputBinds.hpp
Normal file
@ -0,0 +1,13 @@
|
||||
// Copyright (c) 2024 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace Dawn {
|
||||
enum class InputBind : uint8_t {
|
||||
Up,
|
||||
Down
|
||||
};
|
||||
}
|
@ -4,6 +4,7 @@
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "PlayerPrefab.hpp"
|
||||
#include "display/mesh/QuadMesh.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
@ -12,9 +13,27 @@ struct PlayerPrefab Dawn::createPlayerPrefab(
|
||||
) {
|
||||
struct PlayerPrefab player;
|
||||
player.item = world->getScene()->createSceneItem();
|
||||
player.item->setParent(world->getItem());
|
||||
|
||||
player.entity = player.item->addComponent<Entity>();
|
||||
player.entity->world = world;
|
||||
|
||||
player.player = player.item->addComponent<Player>();
|
||||
|
||||
player.mesh = std::make_shared<Mesh>();
|
||||
player.mesh->createBuffers(QUAD_VERTICE_COUNT, QUAD_INDICE_COUNT);
|
||||
QuadMesh::buffer(
|
||||
player.mesh,
|
||||
glm::vec4(0, 0, 1, 1),
|
||||
glm::vec4(0, 0, 1, 1),
|
||||
0, 0
|
||||
);
|
||||
|
||||
player.meshRenderer = player.item->addComponent<MeshRenderer>();
|
||||
player.meshRenderer->mesh = player.mesh;
|
||||
|
||||
player.material = player.item->addComponent<SimpleTexturedMaterial>();
|
||||
player.material->setColor(COLOR_MAGENTA);
|
||||
|
||||
return player;
|
||||
}
|
@ -6,11 +6,18 @@
|
||||
#pragma once
|
||||
#include "prefab/Prefab.hpp"
|
||||
#include "component/world/World.hpp"
|
||||
#include "component/display/MeshRenderer.hpp"
|
||||
#include "component/display/material/SimpleTexturedMaterial.hpp"
|
||||
#include "component/entity/Player.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
struct PlayerPrefab : public Prefab {
|
||||
public:
|
||||
std::shared_ptr<Entity> entity;
|
||||
std::shared_ptr<Player> player;
|
||||
std::shared_ptr<Mesh> mesh;
|
||||
std::shared_ptr<MeshRenderer> meshRenderer;
|
||||
std::shared_ptr<SimpleTexturedMaterial> material;
|
||||
};
|
||||
|
||||
struct PlayerPrefab createPlayerPrefab(const std::shared_ptr<World> world);
|
||||
|
@ -4,6 +4,7 @@
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "WorldPrefab.hpp"
|
||||
#include "display/mesh/QuadMesh.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include "scenes/SceneList.hpp"
|
||||
#include "prefab/PlayerPrefab.hpp"
|
||||
#include "prefab/WorldPrefab.hpp"
|
||||
// #include "component/display/Camera.hpp"
|
||||
#include "component/display/Camera.hpp"
|
||||
// #include "prefab/SimpleSpinningCube.hpp"
|
||||
// #include "component/display/material/SimpleTexturedMaterial.hpp"
|
||||
// #include "display/mesh/CubeMesh.hpp"
|
||||
@ -24,10 +24,10 @@
|
||||
using namespace Dawn;
|
||||
|
||||
void Dawn::worldScene(Scene &s) {
|
||||
// auto cameraItem = s.createSceneItem();
|
||||
// auto camera = cameraItem->addComponent<Camera>();
|
||||
// cameraItem->lookAt({ 3, 3, 3 }, { 0, 0, 0 }, { 0, 1, 0 });
|
||||
// camera->clipFar = 99999.99f;
|
||||
auto cameraItem = s.createSceneItem();
|
||||
auto camera = cameraItem->addComponent<Camera>();
|
||||
cameraItem->lookAt({ 3, 3, 3 }, { 0, 0, 0 }, { 0, 1, 0 });
|
||||
camera->clipFar = 99999.99f;
|
||||
|
||||
// auto cube = s.createSceneItem();
|
||||
// auto cubeMesh = std::make_shared<Mesh>();
|
||||
|
Reference in New Issue
Block a user