Skip to content

Commit

Permalink
get tile
Browse files Browse the repository at this point in the history
  • Loading branch information
jonylu7 committed Mar 10, 2024
1 parent 9f49d6d commit d676733
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 37 deletions.
96 changes: 96 additions & 0 deletions include/DrawOverlays.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
//
// Created by 盧威任 on 3/8/24.
//

#ifndef PRACTICALTOOLSFORSIMPLEDESIGN_DRAWOVERLAYS_HPP
#define PRACTICALTOOLSFORSIMPLEDESIGN_DRAWOVERLAYS_HPP
#include "Core/Drawable.hpp"
#include "pch.hpp"
class DrawOverlays : public Core::Drawable {

/* boxes:draw box on cell
*cross:draw cross on cell
* selected: defines bottom left & top right, show selected "corner" on
*given cell range circle: defines only the center(cell coord) & the
*radius(cell) circle-dash: defines only the center(cell coord) & the
*radius(cell)
*/
enum class OverlayShapes { BOXES, CROSS, SELECTED, CIRCLE };

public:
DrawOverlays(){};
~DrawOverlays(){};
void Start(std::vector<int> cellcoords, OverlayShapes shapes) {}

void InitVertexAndColor() {
/*
std::vector<float> vertex = {};
std::vector<float> color = {};
std::vector<unsigned int> index = {};
for (auto line : m_lineVector) {
vertex.push_back(line.getlineFrom().x);
vertex.push_back(line.getlineFrom().y);
color.push_back(line.getColor().x);
color.push_back(line.getColor().y);
color.push_back(line.getColor().z);
vertex.push_back(line.getlineTo().x);
vertex.push_back(line.getlineTo().y);
color.push_back(line.getColor().x);
color.push_back(line.getColor().y);
color.push_back(line.getColor().z);
}
m_VertexArray->AddVertexBuffer(
std::make_unique<Core::VertexBuffer>(vertex, 2));
m_VertexArray->AddVertexBuffer(
std::make_unique<Core::VertexBuffer>(color, 3));
*/
}

void Draw(const Util::Transform &trans, const float zindex) override {}

void DrawUsingCamera(const Util::Transform &trans,
const float zindex) override {
/*
if (m_Activate == false) {
return;
}
glLineWidth(m_shapelineWidth);
m_Program.Bind();
m_Program.Validate();
m_VertexArray->Bind();
auto cp = CameraClass::getProjectionMatrix();
auto cv = CameraClass::getViewMatrix();
constexpr glm::mat4 eye(1.F);
glm::vec2 size = {1.F, 1.F};
auto data = Util::ConvertToUniformBufferDataUsingCameraMatrix(
transform, size, zIndex);
m_Matrices->SetData(0, data);
m_VertexArray->Bind();
m_VertexArray->DrawLines(m_lineVector.size() * 5 * 2);
*/
}

private:
Core::Program m_Program = Core::Program("../assets/shaders/DrawLines.vert",
"../assets/shaders/DrawLines.frag");

std::unique_ptr<Core::UniformBuffer<Core::Matrices>> m_Matrices =
std::make_unique<Core::UniformBuffer<Core::Matrices>>(m_Program, "Grid",
0);

float m_shapelineWidth = 1.0F;
glm::vec2 shapelinecolor;

std::unique_ptr<Core::VertexArray> m_VertexArray =
std::make_unique<Core::VertexArray>();
};

#endif // PRACTICALTOOLSFORSIMPLEDESIGN_DRAWOVERLAYS_HPP
13 changes: 11 additions & 2 deletions include/Map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class MapClass : public Core::Drawable {
public:
MapClass() {}

void Init(std::vector<std::shared_ptr<TileClass>> map,
void Init(std::vector<std::vector<std::shared_ptr<TileClass>>> map,
std::shared_ptr<SpriteSheet> spritesheet, CELL width,
CELL height) {
m_Map = map;
Expand Down Expand Up @@ -71,6 +71,15 @@ class MapClass : public Core::Drawable {
int(cellCoord[1] * CELL_SIZE.y) + 0.5 * CELL_SIZE.y);
}

std::shared_ptr<TileClass> getTileByCellPosition(glm::vec2 position) {
if (position.x > m_MapWdith - 1 || position.y > m_MapHeight - 1 ||
position.x < 0 || position.y < 0) {
LOG_DEBUG("False Position Getting");
return nullptr;
}
return m_Map[position.x][position.y];
}

// weird
static std::vector<std::shared_ptr<TileClass>>
readMapAndTileSet(std::vector<int> map, std::map<int, TileClass> tileset) {
Expand Down Expand Up @@ -105,7 +114,7 @@ class MapClass : public Core::Drawable {
CELL m_MapWdith;
CELL m_MapHeight;
glm::vec2 m_MapPosition = {0, 0};
std::vector<std::shared_ptr<TileClass>> m_Map;
std::vector<std::vector<std::shared_ptr<TileClass>>> m_Map;
std::shared_ptr<SpriteSheet> m_SpriteSheet;
int m_ZIndex = 0;
Grid m_Grid;
Expand Down
33 changes: 0 additions & 33 deletions include/Rectangle.hpp

This file was deleted.

3 changes: 1 addition & 2 deletions src/Grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ void Grid::Draw(const Util::Transform &transform, const float zindex) {
void Grid::DrawUsingCamera(const Util::Transform &transform,
const float zIndex) {

// TODO:awaiting to be debugged
if (m_Activate == false) {
// return;
return;
}
glLineWidth(m_lineWidth);

Expand Down

0 comments on commit d676733

Please sign in to comment.