Just breaking stuff
This commit is contained in:
30
archive/dawnplatformergame/CMakeLists.txt
Normal file
30
archive/dawnplatformergame/CMakeLists.txt
Normal file
@ -0,0 +1,30 @@
|
||||
# Copyright (c) 2022 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Build Project
|
||||
add_executable(${DAWN_TARGET_NAME})
|
||||
|
||||
# Includes
|
||||
target_include_directories(${DAWN_TARGET_NAME}
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(components)
|
||||
add_subdirectory(game)
|
||||
add_subdirectory(save)
|
||||
|
||||
# Assets
|
||||
set(DIR_GAME_ASSETS games/platformergame)
|
||||
tool_language(language_en ${DIR_GAME_ASSETS}/locale/en.csv)
|
||||
tool_texture(texture_test texture_test.png)
|
||||
tool_tileset(tileset_aqua texture_aqua ${DIR_GAME_ASSETS}/tileset/s4m_ur4i_minivania_tilemap_aqua.png 32 32)
|
||||
|
||||
add_dependencies(${DAWN_TARGET_NAME}
|
||||
language_en
|
||||
texture_test
|
||||
tileset_aqua
|
||||
)
|
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();
|
||||
};
|
||||
}
|
10
archive/dawnplatformergame/game/CMakeLists.txt
Normal file
10
archive/dawnplatformergame/game/CMakeLists.txt
Normal file
@ -0,0 +1,10 @@
|
||||
# Copyright (c) 2022 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Sources
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
DawnGame.cpp
|
||||
)
|
40
archive/dawnplatformergame/game/DawnGame.cpp
Normal file
40
archive/dawnplatformergame/game/DawnGame.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "DawnGame.hpp"
|
||||
#include "scenes/TestScene.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
DawnGame::DawnGame(DawnHost *host) :
|
||||
host(host),
|
||||
renderManager(this),
|
||||
inputManager(this),
|
||||
localeManager(this),
|
||||
saveManager(this)
|
||||
{
|
||||
}
|
||||
|
||||
int32_t DawnGame::init() {
|
||||
this->assetManager.init();
|
||||
this->localeManager.init();
|
||||
this->renderManager.init();
|
||||
|
||||
this->scene = new TestScene(this);
|
||||
|
||||
return DAWN_GAME_INIT_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t DawnGame::update(float_t delta) {
|
||||
this->assetManager.update();
|
||||
this->inputManager.update();
|
||||
this->timeManager.update(delta);
|
||||
|
||||
if(this->scene != nullptr) this->scene->update();
|
||||
|
||||
this->renderManager.update();
|
||||
|
||||
return DAWN_GAME_UPDATE_RESULT_SUCCESS;
|
||||
}
|
27
archive/dawnplatformergame/game/DawnGame.hpp
Normal file
27
archive/dawnplatformergame/game/DawnGame.hpp
Normal file
@ -0,0 +1,27 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "game/_DawnGame.hpp"
|
||||
#include "scene/components/Components.hpp"
|
||||
#include "save/DawnGameSaveManager.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class DawnGame : public IDawnGame {
|
||||
public:
|
||||
DawnHost *host;
|
||||
RenderManager renderManager;
|
||||
AssetManager assetManager;
|
||||
InputManager inputManager;
|
||||
TimeManager timeManager;
|
||||
LocaleManager localeManager;
|
||||
DawnGameSaveManager saveManager;
|
||||
PhysicsManager physicsManager;
|
||||
|
||||
DawnGame(DawnHost *host);
|
||||
int32_t init() override;
|
||||
int32_t update(float_t delta) override;
|
||||
};
|
||||
}
|
14
archive/dawnplatformergame/input/InputBinds.hpp
Normal file
14
archive/dawnplatformergame/input/InputBinds.hpp
Normal file
@ -0,0 +1,14 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "input/InputManager.hpp"
|
||||
|
||||
#define INPUT_BIND(n) ((inputbind_t)n)
|
||||
#define INPUT_BIND_ACCEPT INPUT_BIND(1)
|
||||
#define INPUT_BIND_NEGATIVE_X INPUT_BIND(2)
|
||||
#define INPUT_BIND_POSITIVE_X INPUT_BIND(3)
|
||||
#define INPUT_BIND_NEGATIVE_Y INPUT_BIND(4)
|
||||
#define INPUT_BIND_POSITIVE_Y INPUT_BIND(5)
|
46
archive/dawnplatformergame/prefabs/PlayerPrefab.hpp
Normal file
46
archive/dawnplatformergame/prefabs/PlayerPrefab.hpp
Normal file
@ -0,0 +1,46 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "prefab/SceneItemPrefab.hpp"
|
||||
#include "scene/components/Components.hpp"
|
||||
#include "components/PlayerController.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class PlayerPrefab : public SceneItemPrefab<PlayerPrefab> {
|
||||
public:
|
||||
static std::vector<Asset*> prefabAssets(AssetManager *man) {
|
||||
std::vector<Asset*> assets;
|
||||
assets.push_back(man->get<TilesetAsset>("tileset_aqua"));
|
||||
assets.push_back(man->get<TextureAsset>("texture_aqua"));
|
||||
return assets;
|
||||
}
|
||||
|
||||
//
|
||||
MeshHost *meshHost;
|
||||
TiledSprite *tiledSprite;
|
||||
Material *material;
|
||||
MeshRenderer *meshRenderer;
|
||||
PlayerController *playerController;
|
||||
|
||||
PlayerPrefab(Scene *s, sceneitemid_t i) : SceneItemPrefab(s, i) {}
|
||||
|
||||
void prefabInit(AssetManager *man) override {
|
||||
auto tileset = man->get<TilesetAsset>("tileset_aqua");
|
||||
auto texture = man->get<TextureAsset>("texture_aqua");
|
||||
|
||||
meshHost = addComponent<MeshHost>();
|
||||
tiledSprite = addComponent<TiledSprite>();
|
||||
material = addComponent<Material>();
|
||||
meshRenderer = addComponent<MeshRenderer>();
|
||||
playerController = addComponent<PlayerController>();
|
||||
|
||||
tiledSprite->setTilesetAndSize(&tileset->tileset);
|
||||
tiledSprite->setTile(896);
|
||||
|
||||
material->textureValues[material->getShader()->getParameterByName("u_Text")] = &texture->texture;
|
||||
}
|
||||
};
|
||||
}
|
10
archive/dawnplatformergame/save/CMakeLists.txt
Normal file
10
archive/dawnplatformergame/save/CMakeLists.txt
Normal file
@ -0,0 +1,10 @@
|
||||
# Copyright (c) 2022 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Sources
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
DawnGameSaveManager.cpp
|
||||
)
|
28
archive/dawnplatformergame/save/DawnGameSaveManager.cpp
Normal file
28
archive/dawnplatformergame/save/DawnGameSaveManager.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "DawnGameSaveManager.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
DawnGameSaveManager::DawnGameSaveManager(DawnGame *game) : SaveManager(game) {
|
||||
}
|
||||
|
||||
bool_t DawnGameSaveManager::validateSave(struct SaveFile raw) {
|
||||
if(!raw.has(POKER_SAVE_KEY_EXAMPLE)) return true;
|
||||
this->currentSave.copy(raw, POKER_SAVE_KEY_EXAMPLE);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void DawnGameSaveManager::setExample(int32_t val) {
|
||||
savedata_t value;
|
||||
value.i32 = val;
|
||||
this->currentSave.set(POKER_SAVE_KEY_EXAMPLE, value);
|
||||
}
|
||||
|
||||
int32_t DawnGameSaveManager::getExample() {
|
||||
return this->currentSave.get(POKER_SAVE_KEY_EXAMPLE).i32;
|
||||
}
|
22
archive/dawnplatformergame/save/DawnGameSaveManager.hpp
Normal file
22
archive/dawnplatformergame/save/DawnGameSaveManager.hpp
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "save/SaveManager.hpp"
|
||||
|
||||
#define POKER_SAVE_KEY_EXAMPLE "poker.example"
|
||||
|
||||
namespace Dawn {
|
||||
class DawnGameSaveManager : public SaveManager {
|
||||
protected:
|
||||
virtual bool_t validateSave(struct SaveFile raw) override;
|
||||
|
||||
public:
|
||||
DawnGameSaveManager(DawnGame *game);
|
||||
|
||||
void setExample(int32_t value);
|
||||
int32_t getExample();
|
||||
};
|
||||
}
|
33
archive/dawnplatformergame/scenes/TestScene.hpp
Normal file
33
archive/dawnplatformergame/scenes/TestScene.hpp
Normal file
@ -0,0 +1,33 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "scene/Scene.hpp"
|
||||
#include "prefabs/PlayerPrefab.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class TestScene : public Scene {
|
||||
protected:
|
||||
void stage() override {
|
||||
auto camera = Camera::create(this);
|
||||
camera->type = CAMERA_TYPE_ORTHONOGRAPHIC;
|
||||
camera->item->addComponent<PixelPerfectCamera>();
|
||||
camera->transform->lookAt(glm::vec3(0, 0, 10), glm::vec3(0, 0, 0));
|
||||
|
||||
auto player = PlayerPrefab::create(this);
|
||||
player->playerController->camera = camera;
|
||||
}
|
||||
|
||||
std::vector<Asset*> getRequiredAssets() override {
|
||||
auto assMan = &this->game->assetManager;
|
||||
std::vector<Asset*> assets;
|
||||
vectorAppend(&assets, PlayerPrefab::getRequiredAssets(assMan));
|
||||
return assets;
|
||||
}
|
||||
|
||||
public:
|
||||
TestScene(DawnGame *game) : Scene(game) {}
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user