Created rudimentary board
This commit is contained in:
parent
63c7a1bb2d
commit
79736fc3bc
|
@ -5,11 +5,12 @@ layout (location = 1) in vec2 UV;
|
|||
|
||||
out vec2 uvCoord;
|
||||
|
||||
uniform mat4 model;
|
||||
uniform mat4 view;
|
||||
uniform mat4 projection;
|
||||
|
||||
void main()
|
||||
{
|
||||
uvCoord = UV;
|
||||
gl_Position = projection * view * vec4(position, 0.0f, 1.0f);
|
||||
gl_Position = projection * view * model * vec4(position, 0.0f, 1.0f);
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
#include "Application.hpp"
|
||||
|
||||
#include <chrono>
|
||||
#include <random>
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
@ -9,9 +10,11 @@
|
|||
#include <stbi_image.h>
|
||||
|
||||
#include "Window.hpp"
|
||||
#include "Card.hpp"
|
||||
#include "CardStack.hpp"
|
||||
#include "Board.hpp"
|
||||
|
||||
#include "resources.h"
|
||||
#include "ObjectIDs.hpp"
|
||||
|
||||
void Application::Run()
|
||||
{
|
||||
|
@ -22,32 +25,18 @@ void Application::Run()
|
|||
}
|
||||
|
||||
spdlog::debug("Launched Application");
|
||||
|
||||
int currentMonth = 0;
|
||||
int currentType = 0;
|
||||
std::chrono::system_clock::time_point begin = std::chrono::system_clock::now();
|
||||
while (!window->ShouldClose())
|
||||
{
|
||||
glfwPollEvents();
|
||||
|
||||
if (std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - begin).count() > 250)
|
||||
{
|
||||
begin = std::chrono::system_clock::now();
|
||||
currentType++;
|
||||
if (currentType > 3)
|
||||
{
|
||||
currentMonth++;
|
||||
if (currentMonth > 11)
|
||||
currentMonth = 0;
|
||||
|
||||
currentType = 0;
|
||||
}
|
||||
|
||||
card->UpdateSuitAndType(static_cast<Month>(currentMonth), currentType);
|
||||
}
|
||||
for (lol::Layer* layer : layerStack)
|
||||
layer->OnUpdate();
|
||||
|
||||
window->Clear();
|
||||
window->Draw(*card);
|
||||
|
||||
for (lol::Layer* layer : layerStack)
|
||||
window->Draw(*layer);
|
||||
|
||||
window->Display();
|
||||
}
|
||||
}
|
||||
|
@ -81,18 +70,28 @@ Application::Application() :
|
|||
spdlog::debug("Loading resources...");
|
||||
|
||||
lol::Image image((unsigned char*)card_atlas_png, card_atlas_png_size);
|
||||
manager.Create<lol::Texture2D>(0, image, lol::TextureFormat::RGBA);
|
||||
manager.Create<lol::Shader>(1, std::string((char*)card_vs, card_vs_size), std::string((char*)card_fs, card_fs_size));
|
||||
manager.Create<lol::Texture2D>(TEXTURE_CARD_ATLAS, image, lol::TextureFormat::RGBA);
|
||||
manager.Create<lol::Shader>(SHADER_CARD, std::string((char*)card_vs, card_vs_size), std::string((char*)card_fs, card_fs_size));
|
||||
spdlog::debug("Done!");
|
||||
|
||||
card = new Card(manager, Month::August, 0);
|
||||
spdlog::debug("Creating card stack");
|
||||
manager.Create<CardStack>(CARD_STACK, manager);
|
||||
|
||||
spdlog::debug("Setting up board");
|
||||
layerStack.push_back(new Board(manager));
|
||||
|
||||
glViewport(0, 0, 1280, 720);
|
||||
|
||||
// Enable transparency
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
}
|
||||
|
||||
Application::~Application()
|
||||
{
|
||||
delete card;
|
||||
for (lol::Layer* layer : layerStack)
|
||||
delete layer;
|
||||
|
||||
delete window;
|
||||
|
||||
glfwTerminate();
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <lol/lol.hpp>
|
||||
|
||||
|
||||
class Window;
|
||||
class Card;
|
||||
|
||||
class Application
|
||||
{
|
||||
|
@ -22,7 +23,7 @@ private:
|
|||
Window* window;
|
||||
|
||||
lol::ObjectManager manager;
|
||||
Card* card;
|
||||
std::vector<lol::Layer*> layerStack;
|
||||
|
||||
private:
|
||||
Application();
|
||||
|
|
42
src/Board.cpp
Normal file
42
src/Board.cpp
Normal file
|
@ -0,0 +1,42 @@
|
|||
#include "Board.hpp"
|
||||
|
||||
#include "CardStack.hpp"
|
||||
#include "ObjectIDs.hpp"
|
||||
|
||||
Board::Board(lol::ObjectManager& manager) :
|
||||
Layer("Board")
|
||||
{
|
||||
// Draw 8 cards from stack
|
||||
std::shared_ptr<CardStack> stack = manager.Get<CardStack>(CARD_STACK);
|
||||
for (int y = 0; y < 2; y++)
|
||||
{
|
||||
for (int x = 0; x < 4; x++)
|
||||
{
|
||||
std::shared_ptr<Card> card = stack->Draw();
|
||||
card->SetScale(glm::vec3(0.2f));
|
||||
|
||||
glm::vec3 cardSize = card->GetSize();
|
||||
card->SetPosition(glm::vec3(
|
||||
0.25f + (cardSize.x + 0.05f) * x,
|
||||
0.5f - cardSize.y - 0.025f + (cardSize.y + 0.05f) * y,
|
||||
0.0f
|
||||
));
|
||||
|
||||
openCards.push_back(card);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Board::~Board()
|
||||
{
|
||||
}
|
||||
|
||||
void Board::OnUpdate()
|
||||
{
|
||||
}
|
||||
|
||||
void Board::OnRender(lol::CameraBase& camera)
|
||||
{
|
||||
for (std::shared_ptr<Card> card : openCards)
|
||||
card->Draw(camera);
|
||||
}
|
17
src/Board.hpp
Normal file
17
src/Board.hpp
Normal file
|
@ -0,0 +1,17 @@
|
|||
#pragma once
|
||||
|
||||
#include <lol/lol.hpp>
|
||||
#include "Card.hpp"
|
||||
|
||||
class Board : public lol::Layer
|
||||
{
|
||||
public:
|
||||
Board(lol::ObjectManager& manager);
|
||||
~Board();
|
||||
|
||||
void OnUpdate() override;
|
||||
void OnRender(lol::CameraBase& camera) override;
|
||||
|
||||
private:
|
||||
std::vector<std::shared_ptr<Card>> openCards;
|
||||
};
|
|
@ -2,7 +2,10 @@ add_executable(koikoi
|
|||
"main.cpp"
|
||||
"Application.cpp"
|
||||
"Window.cpp"
|
||||
"Card.cpp")
|
||||
"Card.cpp"
|
||||
"CardStack.cpp"
|
||||
"Board.cpp"
|
||||
)
|
||||
|
||||
set( RC_DEPENDS "" )
|
||||
|
||||
|
|
17
src/Card.cpp
17
src/Card.cpp
|
@ -1,10 +1,13 @@
|
|||
#include "Card.hpp"
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
#include "ObjectIDs.hpp"
|
||||
|
||||
Card::Card(lol::ObjectManager& manager, Month month, int type)
|
||||
{
|
||||
try
|
||||
{
|
||||
vao = manager.Get<lol::VertexArray>(2);
|
||||
vao = manager.Get<lol::VertexArray>(VAO_CARD);
|
||||
}
|
||||
catch (const lol::ObjectNotFoundException& err)
|
||||
{
|
||||
|
@ -23,11 +26,16 @@ Card::Card(lol::ObjectManager& manager, Month month, int type)
|
|||
|
||||
std::shared_ptr<lol::ElementBuffer> ebo = std::make_shared<lol::ElementBuffer>(std::vector<unsigned int>{ 0, 1, 2, 0, 2, 3 });
|
||||
|
||||
vao = manager.Create<lol::VertexArray>(2, vbo, ebo);
|
||||
vao = manager.Create<lol::VertexArray>(VAO_CARD, vbo, ebo);
|
||||
}
|
||||
catch (const std::exception& err)
|
||||
{
|
||||
spdlog::critical("Unknown error in constructor of Card");
|
||||
throw err;
|
||||
}
|
||||
|
||||
shader = manager.Get<lol::Shader>(1);
|
||||
cards = manager.Get<lol::Texture2D>(0);
|
||||
shader = manager.Get<lol::Shader>(SHADER_CARD);
|
||||
cards = manager.Get<lol::Texture2D>(TEXTURE_CARD_ATLAS);
|
||||
|
||||
UpdateSuitAndType(month, type);
|
||||
}
|
||||
|
@ -48,6 +56,7 @@ void Card::PreRender(const lol::CameraBase& camera)
|
|||
cards->Bind();
|
||||
shader->SetUniform("offset", textureOffset);
|
||||
|
||||
shader->SetUniform("model", transformation);
|
||||
shader->SetUniform("view", camera.GetView());
|
||||
shader->SetUniform("projection", camera.GetProjection());
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ public:
|
|||
Card(lol::ObjectManager& manager, Month month, int type);
|
||||
|
||||
void UpdateSuitAndType(Month month, int type);
|
||||
glm::vec3 GetSize() { return glm::vec3(0.61035f, 1.0f, 0.0f) * GetScale(); }
|
||||
|
||||
private:
|
||||
void PreRender(const lol::CameraBase& camera) override;
|
||||
|
|
32
src/CardStack.cpp
Normal file
32
src/CardStack.cpp
Normal file
|
@ -0,0 +1,32 @@
|
|||
#include "CardStack.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <random>
|
||||
|
||||
CardStack::CardStack(lol::ObjectManager& manager)
|
||||
{
|
||||
// Create a full stack of cards
|
||||
for (int month = 0; month < 11; month++)
|
||||
{
|
||||
for (int type = 0; type < 4; type++)
|
||||
{
|
||||
stack.push_back(std::make_shared<Card>(manager, static_cast<Month>(month), type));
|
||||
}
|
||||
}
|
||||
|
||||
// Shuffle stack
|
||||
std::default_random_engine engine(time(0));
|
||||
std::shuffle(stack.begin(), stack.end(), engine);
|
||||
}
|
||||
|
||||
CardStack::~CardStack()
|
||||
{
|
||||
}
|
||||
|
||||
std::shared_ptr<Card> CardStack::Draw()
|
||||
{
|
||||
std::shared_ptr<Card> drawnCard = stack.back();
|
||||
stack.pop_back();
|
||||
return drawnCard;
|
||||
}
|
16
src/CardStack.hpp
Normal file
16
src/CardStack.hpp
Normal file
|
@ -0,0 +1,16 @@
|
|||
#pragma once
|
||||
|
||||
#include "Card.hpp"
|
||||
|
||||
class CardStack
|
||||
{
|
||||
public:
|
||||
CardStack(lol::ObjectManager& manager);
|
||||
~CardStack();
|
||||
|
||||
std::shared_ptr<Card> Draw();
|
||||
inline bool Empty() { return stack.empty(); }
|
||||
|
||||
private:
|
||||
std::vector<std::shared_ptr<Card>> stack;
|
||||
};
|
6
src/ObjectIDs.hpp
Normal file
6
src/ObjectIDs.hpp
Normal file
|
@ -0,0 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#define TEXTURE_CARD_ATLAS 0
|
||||
#define SHADER_CARD 1
|
||||
#define VAO_CARD 2
|
||||
#define CARD_STACK 3
|
|
@ -49,9 +49,9 @@ void Window::Clear()
|
|||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
}
|
||||
|
||||
void Window::Draw(lol::Drawable& drawable)
|
||||
void Window::Draw(lol::Layer& layer)
|
||||
{
|
||||
camera.Draw(drawable);
|
||||
layer.OnRender(camera);
|
||||
}
|
||||
|
||||
void Window::Display()
|
||||
|
|
|
@ -20,7 +20,7 @@ public:
|
|||
inline bool ShouldClose() { return glfwWindowShouldClose(window); }
|
||||
|
||||
void Clear();
|
||||
void Draw(lol::Drawable& drawable);
|
||||
void Draw(lol::Layer& layer);
|
||||
void Display();
|
||||
|
||||
private:
|
||||
|
|
2
vendor/lol
vendored
2
vendor/lol
vendored
|
@ -1 +1 @@
|
|||
Subproject commit 7b268efa6a4a893e64c2cad18a05aa633b5aebe1
|
||||
Subproject commit bb055a48d214b6697b57db03a9f7e4300178c585
|
Loading…
Reference in a new issue