Moved Scene implementation around
This commit is contained in:
@ -7,4 +7,5 @@
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
TicTacToeTile.cpp
|
||||
TicTacToeGame.cpp
|
||||
)
|
27
src/dawntictactoe/components/TicTacToeGame.cpp
Normal file
27
src/dawntictactoe/components/TicTacToeGame.cpp
Normal file
@ -0,0 +1,27 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "TicTacToeGame.hpp"
|
||||
#include "game/DawnGame.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
TicTacToeGame::TicTacToeGame(SceneItem *item) : SceneItemComponent(item) {}
|
||||
|
||||
void TicTacToeGame::onStart() {
|
||||
std::cout << "Test" << std::endl;
|
||||
this->tiles = getScene()->findComponents<TicTacToeTile>();
|
||||
|
||||
getScene()->eventSceneUpdate.addListener(this, &TicTacToeGame::onSceneUpdate);
|
||||
}
|
||||
|
||||
void TicTacToeGame::onSceneUpdate() {
|
||||
// Get mouse in screen space.
|
||||
auto mouse = getGame()->inputManager.getAxis2D(INPUT_BIND_MOUSE_X, INPUT_BIND_MOUSE_Y);
|
||||
mouse *= 2.0f;
|
||||
mouse -= glm::vec2(1, 1);
|
||||
|
||||
|
||||
}
|
21
src/dawntictactoe/components/TicTacToeGame.hpp
Normal file
21
src/dawntictactoe/components/TicTacToeGame.hpp
Normal file
@ -0,0 +1,21 @@
|
||||
// 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 "TicTacToeTile.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class TicTacToeGame : public SceneItemComponent {
|
||||
public:
|
||||
std::vector<TicTacToeTile*> tiles;
|
||||
|
||||
TicTacToeGame(SceneItem *item);
|
||||
|
||||
void onStart() override;
|
||||
|
||||
void onSceneUpdate();
|
||||
};
|
||||
}
|
@ -13,7 +13,6 @@ DawnGame::DawnGame(DawnHost *host) :
|
||||
renderManager(this),
|
||||
inputManager(this),
|
||||
localeManager(this),
|
||||
physicsManager(this),
|
||||
saveManager(this)
|
||||
{
|
||||
}
|
||||
|
@ -20,7 +20,6 @@ namespace Dawn {
|
||||
TimeManager timeManager;
|
||||
LocaleManager localeManager;
|
||||
DawnGameSaveManager saveManager;
|
||||
PhysicsManager physicsManager;
|
||||
|
||||
DawnGame(DawnHost *host);
|
||||
int32_t init() override;
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "scene/components/display/MeshHost.hpp"
|
||||
#include "scene/components/display/MeshRenderer.hpp"
|
||||
#include "scene/components/display/material/SimpleTexturedMaterial.hpp"
|
||||
#include "scene/components/physics/2d/BoxCollider.hpp"
|
||||
#include "components/TicTacToeTile.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
@ -27,6 +28,7 @@ namespace Dawn {
|
||||
MeshRenderer *meshRenderer;
|
||||
SimpleTexturedMaterial *material;
|
||||
TicTacToeTile *ticTacToe;
|
||||
BoxCollider *boxCollider;
|
||||
|
||||
TicTacToeTilePrefab(Scene *s, sceneitemid_t i) :
|
||||
SceneItemPrefab<TicTacToeTilePrefab>(s,i)
|
||||
@ -48,7 +50,11 @@ namespace Dawn {
|
||||
sprite = this->addComponent<TiledSprite>();
|
||||
sprite->setTileset(&tileset->tileset);
|
||||
sprite->setSize(glm::vec2(1, 1));
|
||||
sprite->setTile(0x00);
|
||||
sprite->setTile(0x01);
|
||||
|
||||
boxCollider = this->addComponent<BoxCollider>();
|
||||
boxCollider->min = glm::vec2();
|
||||
boxCollider->max = glm::vec2(1, 1);
|
||||
|
||||
ticTacToe = this->addComponent<TicTacToeTile>();
|
||||
}
|
||||
|
@ -8,14 +8,12 @@
|
||||
#include "prefabs/SimpleSpinningCubePrefab.hpp"
|
||||
#include "prefabs/TicTacToeTilePrefab.hpp"
|
||||
#include "display/mesh/TriangleMesh.hpp"
|
||||
|
||||
#include "scene/components/physics/3d/RayTester3D.hpp"
|
||||
#include "components/TicTacToeGame.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class TicTacToeScene : public Scene {
|
||||
protected:
|
||||
Camera *camera;
|
||||
TicTacToeTilePrefab* tiles[9];
|
||||
|
||||
void stage() override {
|
||||
camera = Camera::create(this);
|
||||
@ -30,22 +28,19 @@ namespace Dawn {
|
||||
camera->orthoLeft = -s * ratio;
|
||||
camera->orthoRight = s * ratio;
|
||||
|
||||
auto cube = SimpleSpinningCubePrefab::create(this);
|
||||
TriangleMesh::createTriangleMesh(&cube->meshHost->mesh);
|
||||
// auto cube = SimpleSpinningCubePrefab::create(this);
|
||||
// TriangleMesh::createTriangleMesh(&cube->meshHost->mesh);
|
||||
// SphereMesh::createSphere(&cube->meshHost->mesh, 1.0f, 16, 16);
|
||||
auto tester = cube->addComponent<RayTester3D>();
|
||||
tester->prefab = cube;
|
||||
tester->camera = camera;
|
||||
|
||||
auto gameItem = this->createSceneItem();
|
||||
auto game = gameItem->addComponent<TicTacToeGame>();
|
||||
|
||||
int32_t i = 0;
|
||||
for(int32_t x = -1; x <= 1; x++) {
|
||||
for(int32_t y = -1; y <= 1; y++) {
|
||||
continue;
|
||||
auto tile = TicTacToeTilePrefab::create(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;
|
||||
// tile->ticTacToe->setState(i % 2 == 0 ? TIC_TAC_TOE_CROSS : TIC_TAC_TOE_NOUGHT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user