Physics time

This commit is contained in:
2023-02-18 21:10:14 -08:00
parent 87733d6299
commit 4bfec16ba7
8 changed files with 162 additions and 3 deletions

View File

@ -64,6 +64,7 @@ namespace Dawn {
*/
virtual void onDispose();
/**
* Cleanup the SceneItemComponent.
*/

View File

@ -16,10 +16,12 @@ target_include_directories(${DAWN_TARGET_NAME}
)
# Subdirs
add_subdirectory(components)
add_subdirectory(game)
add_subdirectory(save)
# Assets
set(DIR_GAME_ASSETS games/tictactoe)
tool_language(locale_en ${DIR_GAME_ASSETS}/locale/en.xml)
tool_language(locale_en ${DIR_GAME_ASSETS}/locale/en.xml)
tool_tileset(tileset_xo texture_xo ${DIR_GAME_ASSETS}/xo.png 1 3)

View 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
TicTacToeTile.cpp
)

View File

@ -0,0 +1,20 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "TicTacToeTile.hpp"
#include "scene/SceneItem.hpp"
using namespace Dawn;
TicTacToeTile::TicTacToeTile(SceneItem *item) : SceneItemComponent(item) {
}
void TicTacToeTile::setState(enum TicTacToeTileState state) {
auto ts = this->item->getComponent<TiledSprite>();
ts->setTile(state);
this->state = state;
}

View File

@ -0,0 +1,25 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "scene/SceneItemComponent.hpp"
#include "scene/components/display/TiledSprite.hpp"
namespace Dawn {
enum TicTacToeTileState {
TIC_TAC_TOE_BLANK,
TIC_TAC_TOE_NOUGHT,
TIC_TAC_TOE_CROSS
};
class TicTacToeTile : public SceneItemComponent {
public:
enum TicTacToeTileState state = TIC_TAC_TOE_BLANK;
TicTacToeTile(SceneItem *item);
void setState(enum TicTacToeTileState state);
};
}

View File

@ -4,7 +4,7 @@
// https://opensource.org/licenses/MIT
#include "DawnGame.hpp"
#include "scenes/TestScene.hpp"
#include "scenes/TicTacToeScene.hpp"
using namespace Dawn;
@ -23,7 +23,7 @@ int32_t DawnGame::init() {
this->localeManager.init();
this->renderManager.init();
this->scene = new TestScene(this);
this->scene = new TicTacToeScene(this);
return DAWN_GAME_INIT_RESULT_SUCCESS;
}

View File

@ -0,0 +1,56 @@
// 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/display/TiledSprite.hpp"
#include "scene/components/display/MeshHost.hpp"
#include "scene/components/display/MeshRenderer.hpp"
#include "scene/components/display/material/SimpleTexturedMaterial.hpp"
#include "components/TicTacToeTile.hpp"
namespace Dawn {
class TicTacToeTilePrefab : public SceneItemPrefab<TicTacToeTilePrefab> {
public:
static std::vector<Asset*> prefabAssets(AssetManager *ass) {
return std::vector<Asset*>{
ass->get<TextureAsset>("texture_xo"),
ass->get<TilesetAsset>("tileset_xo")
};
}
//
MeshHost *meshHost;
TiledSprite *sprite;
MeshRenderer *meshRenderer;
SimpleTexturedMaterial *material;
TicTacToeTile *ticTacToe;
TicTacToeTilePrefab(Scene *s, sceneitemid_t i) :
SceneItemPrefab<TicTacToeTilePrefab>(s,i)
{
}
void prefabInit(AssetManager *man) override {
auto tileset = man->get<TilesetAsset>("tileset_xo");
auto texture = man->get<TextureAsset>("texture_xo");
meshHost = this->addComponent<MeshHost>();
meshRenderer = this->addComponent<MeshRenderer>();
material = this->template addComponent<SimpleTexturedMaterial>();
material->texture = &texture->texture;
sprite = this->addComponent<TiledSprite>();
sprite->setTileset(&tileset->tileset);
sprite->setSize(glm::vec2(1, 1));
sprite->setTile(0x00);
ticTacToe = this->addComponent<TicTacToeTile>();
}
};
}

View File

@ -0,0 +1,45 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "scene/Scene.hpp"
#include "prefabs/SimpleSpinningCubePrefab.hpp"
#include "prefabs/TicTacToeTilePrefab.hpp"
namespace Dawn {
class TicTacToeScene : public Scene {
protected:
Camera *camera;
TicTacToeTilePrefab* tiles[9];
void stage() override {
camera = Camera::create(this);
camera->transform->lookAt(glm::vec3(5, 5, 5), glm::vec3(0, 0, 0));
int32_t i = 0;
for(int32_t x = -1; x <= 1; x++) {
for(int32_t y = -1; y <= 1; y++) {
auto tile = TicTacToeTilePrefab::prefabCreate(this);
tile->transform.setLocalPosition(glm::vec3(x * 1.25f, y * 1.25f, 0));
// tile->ticTacToe->setState(i % 2 == 0 ? TIC_TAC_TOE_CROSS : TIC_TAC_TOE_NOUGHT);
tiles[i++] = tile;
}
}
}
std::vector<Asset*> getRequiredAssets() override {
auto assMan = &this->game->assetManager;
std::vector<Asset*> assets;
vectorAppend(&assets, SimpleSpinningCubePrefab::getRequiredAssets(assMan));
vectorAppend(&assets, TicTacToeTilePrefab::getRequiredAssets(assMan));
return assets;
}
public:
TicTacToeScene(DawnGame *game) : Scene(game) {}
};
}