Prep for walls, not done
This commit is contained in:
@ -14,4 +14,5 @@ target_include_directories(${DAWN_TARGET_NAME}
|
|||||||
|
|
||||||
# Subdirs
|
# Subdirs
|
||||||
add_subdirectory(game)
|
add_subdirectory(game)
|
||||||
add_subdirectory(save)
|
add_subdirectory(save)
|
||||||
|
add_subdirectory(scene)
|
7
src/dawnrose/scene/CMakeLists.txt
Normal file
7
src/dawnrose/scene/CMakeLists.txt
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# Copyright (c) 2023 Dominic Masters
|
||||||
|
#
|
||||||
|
# This software is released under the MIT License.
|
||||||
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
# Subdirs
|
||||||
|
add_subdirectory(components)
|
11
src/dawnrose/scene/components/CMakeLists.txt
Normal file
11
src/dawnrose/scene/components/CMakeLists.txt
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# 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
|
||||||
|
GameCamera.cpp
|
||||||
|
PlayerController.cpp
|
||||||
|
)
|
29
src/dawnrose/scene/components/GameCamera.cpp
Normal file
29
src/dawnrose/scene/components/GameCamera.cpp
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
// Copyright (c) 2023 Dominic Masters
|
||||||
|
//
|
||||||
|
// This software is released under the MIT License.
|
||||||
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
#include "GameCamera.hpp"
|
||||||
|
|
||||||
|
using namespace Dawn;
|
||||||
|
|
||||||
|
GameCamera::GameCamera(SceneItem *i) : SceneItemComponent(i) {}
|
||||||
|
|
||||||
|
std::vector<SceneItemComponent*> GameCamera::getDependencies() {
|
||||||
|
return {
|
||||||
|
(this->camera = item->getComponent<Camera>())
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
void GameCamera::onStart() {
|
||||||
|
assertNotNull(this->camera);
|
||||||
|
assertNotNull(this->player);
|
||||||
|
|
||||||
|
useEvent([&](float_t delta) {
|
||||||
|
glm::vec3 cameraTarget = player->transform->getLocalPosition();
|
||||||
|
camera->transform->lookAt(
|
||||||
|
cameraTarget + glm::vec3(0, 10.0f, 1.5f),
|
||||||
|
cameraTarget
|
||||||
|
);
|
||||||
|
}, getScene()->eventSceneUpdate);
|
||||||
|
}
|
22
src/dawnrose/scene/components/GameCamera.hpp
Normal file
22
src/dawnrose/scene/components/GameCamera.hpp
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
// Copyright (c) 2023 Dominic Masters
|
||||||
|
//
|
||||||
|
// This software is released under the MIT License.
|
||||||
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "scene/components/display/Camera.hpp"
|
||||||
|
#include "scene/components/PlayerController.hpp"
|
||||||
|
|
||||||
|
namespace Dawn {
|
||||||
|
class GameCamera : public SceneItemComponent {
|
||||||
|
protected:
|
||||||
|
Camera *camera = nullptr;
|
||||||
|
|
||||||
|
public:
|
||||||
|
PlayerController *player = nullptr;
|
||||||
|
|
||||||
|
GameCamera(SceneItem *item);
|
||||||
|
std::vector<SceneItemComponent*> getDependencies() override;
|
||||||
|
void onStart() override;
|
||||||
|
};
|
||||||
|
}
|
38
src/dawnrose/scene/components/PlayerController.cpp
Normal file
38
src/dawnrose/scene/components/PlayerController.cpp
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
// 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 *item) : SceneItemComponent(item) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlayerController::onStart() {
|
||||||
|
useEvent([&](float_t delta){
|
||||||
|
auto camera = getScene()->findComponent<Camera>();
|
||||||
|
assertNotNull(camera);
|
||||||
|
|
||||||
|
// Friction
|
||||||
|
velocity -= velocity * friction * delta;
|
||||||
|
|
||||||
|
// Movement
|
||||||
|
auto inputMove = getGame()->inputManager.getAxis2D(
|
||||||
|
INPUT_BIND_NEGATIVE_X, INPUT_BIND_POSITIVE_X,
|
||||||
|
INPUT_BIND_NEGATIVE_Y, INPUT_BIND_POSITIVE_Y
|
||||||
|
) * delta * moveSpeed;
|
||||||
|
|
||||||
|
if(inputMove.x != 0 || inputMove.y != 0) {
|
||||||
|
float_t angle = atan2(inputMove.y, inputMove.x);
|
||||||
|
glm::vec3 movement = glm::vec3(cos(angle), 0, sin(angle));
|
||||||
|
velocity += movement * delta * moveSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Move / Update
|
||||||
|
transform->setLocalPosition(transform->getLocalPosition() + (velocity * delta));
|
||||||
|
}, getScene()->eventSceneUpdate);
|
||||||
|
}
|
20
src/dawnrose/scene/components/PlayerController.hpp
Normal file
20
src/dawnrose/scene/components/PlayerController.hpp
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
// Copyright (c) 2023 Dominic Masters
|
||||||
|
//
|
||||||
|
// This software is released under the MIT License.
|
||||||
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "scene/SceneItemComponent.hpp"
|
||||||
|
|
||||||
|
namespace Dawn {
|
||||||
|
class PlayerController : public SceneItemComponent {
|
||||||
|
public:
|
||||||
|
glm::vec3 velocity;
|
||||||
|
float_t moveSpeed = 40.0f;
|
||||||
|
float_t friction = 12.0f;
|
||||||
|
|
||||||
|
PlayerController(SceneItem *item);
|
||||||
|
|
||||||
|
void onStart() override;
|
||||||
|
};
|
||||||
|
}
|
@ -5,57 +5,36 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "scene/Scene.hpp"
|
#include "scene/Scene.hpp"
|
||||||
#include "prefabs/SimpleSpinningCubePrefab.hpp"
|
#include "scene/components/PlayerController.hpp"
|
||||||
#include "scene/components/ui/UILabel.hpp"
|
#include "scene/components/GameCamera.hpp"
|
||||||
#include "scene/components/ui/UIImage.hpp"
|
#include "scene/components/physics/3d/CubeCollider.hpp"
|
||||||
#include "display/font/BitmapFont.hpp"
|
#include "scene/components/GameCamera.hpp"
|
||||||
|
|
||||||
namespace Dawn {
|
namespace Dawn {
|
||||||
class HelloWorldScene : public Scene {
|
class HelloWorldScene : public Scene {
|
||||||
protected:
|
protected:
|
||||||
Camera *camera;
|
Camera *camera;
|
||||||
SimpleSpinningCubePrefab *cube;
|
|
||||||
UICanvas *canvas;
|
|
||||||
UILabel *label;
|
|
||||||
UIImage *image;
|
|
||||||
BitmapFont font;
|
|
||||||
|
|
||||||
void stage() override {
|
void stage() override {
|
||||||
camera = Camera::create(this);
|
camera = Camera::create(this);
|
||||||
camera->transform->lookAt(glm::vec3(0, 0, 8), glm::vec3(0, 0, 0));
|
camera->transform->lookAt(glm::vec3(0, 0, 8), glm::vec3(0, 0, 0));
|
||||||
|
auto gameCamera = camera->item->addComponent<GameCamera>();
|
||||||
|
|
||||||
cube = SimpleSpinningCubePrefab::create(this);
|
auto playerItem = this->createSceneItem();
|
||||||
|
auto player = playerItem->addComponent<PlayerController>();
|
||||||
|
auto hitbox = playerItem->addComponent<CubeCollider>();
|
||||||
|
|
||||||
canvas = UICanvas::create(this);
|
auto wall = this->createSceneItem();
|
||||||
|
auto wallHitbox = wall->addComponent<CubeCollider>();
|
||||||
|
wall->transform.setLocalPosition(glm::vec3(-10, 0, 0));
|
||||||
|
wallHitbox->min = -(wallHitbox->max = glm::vec3(1, 1, 5));
|
||||||
|
|
||||||
auto imageItem = this->createSceneItem();
|
gameCamera->player = player;
|
||||||
image = imageItem->addComponent<UIImage>();
|
|
||||||
image->color = COLOR_BLACK;
|
|
||||||
imageItem->transform.setParent(canvas->transform);
|
|
||||||
|
|
||||||
auto labelItem = this->createSceneItem();
|
|
||||||
label = labelItem->addComponent<UILabel>();
|
|
||||||
labelItem->transform.setParent(canvas->transform);
|
|
||||||
|
|
||||||
auto assMan = &this->game->assetManager;
|
|
||||||
auto texture = assMan->get<TextureAsset>("testbitmap_texture");
|
|
||||||
auto tileset = assMan->get<TilesetAsset>("testbitmap_tileset");
|
|
||||||
this->font.texture = &texture->texture;
|
|
||||||
this->font.tileset = &tileset->tileset;
|
|
||||||
|
|
||||||
label->text = "Hello World, how are you today? I hope you are doing well. I really like the fact I can ramble in my text for once.";
|
|
||||||
label->font = &font;
|
|
||||||
label->maxWidth = 220;
|
|
||||||
|
|
||||||
image->alignment = glm::vec4(0, 0, label->getContentWidth(), label->getContentHeight());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Asset*> getRequiredAssets() override {
|
std::vector<Asset*> getRequiredAssets() override {
|
||||||
auto assMan = &this->game->assetManager;
|
auto assMan = &this->game->assetManager;
|
||||||
std::vector<Asset*> assets;
|
std::vector<Asset*> assets;
|
||||||
vectorAppend(&assets, SimpleSpinningCubePrefab::getRequiredAssets(assMan));
|
|
||||||
assets.push_back(assMan->get<TextureAsset>("testbitmap_texture"));
|
|
||||||
assets.push_back(assMan->get<TilesetAsset>("testbitmap_tileset"));
|
|
||||||
return assets;
|
return assets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user