Commit f87ab806 authored by Srb František's avatar Srb František
Browse files

Added Dot as Player/Enemy character -> fix #1

parent 99fca5df
......@@ -20,6 +20,16 @@ void Display::DrawObject(float* line,unsigned int num_of_vertices) const
}
void Display::DrawPoint(float* point) const
{
glBufferData(GL_ARRAY_BUFFER, sizeof(point[0]) * 5, point, GL_DYNAMIC_DRAW);
glUseProgram(shaderProgram);
//point size
glPointSize(20);
glBindVertexArray(VAO);
glDrawArrays(GL_POINTS, 0, 1);
}
void Display::CleanWindow()
{
//clean whole screen and set every pixel to black
......
......@@ -9,6 +9,7 @@ public:
Display(unsigned int VAO, unsigned int shaderProgram);
~Display();
void DrawObject(float* line, unsigned int num_of_vertices) const;
void DrawPoint(float* line) const;
void CleanWindow();
private:
unsigned int VAO;
......
......@@ -135,6 +135,7 @@ void Scene::render_scene(const Display& display) const
continue;
auto enemy_lines_ptr = get_player_lines(walls, enemy);
display.DrawObject((float*)&((*enemy_lines_ptr)[0]), (unsigned int)enemy_lines_ptr->size() * 2);
this->render_point(enemy.position, enemy.color, display);
}
//draw goal
if (DEBUG_MODE || pos_is_visible(player, goal)) {
......@@ -147,6 +148,7 @@ void Scene::render_scene(const Display& display) const
}
auto player_lines_ptr = get_player_lines(walls,player);
display.DrawObject((float*)&((*player_lines_ptr)[0]), (unsigned int)player_lines_ptr->size() * 2);
this->render_point(player.position, player.color, display);
}
void Scene::restart_scene()
......@@ -344,4 +346,16 @@ std::unique_ptr<vec_lines> Scene::get_player_lines(const vec_lines& walls, const
return outline;
}
void Scene::render_point(pos position, tuple_color color, const Display& display) const
{
std::vector<float> point_data;
point_data.push_back(position.first); //x
point_data.push_back(position.second); //y
auto&& [r, g, b] = color;
point_data.push_back(r);
point_data.push_back(g);
point_data.push_back(b);
display.DrawPoint((float*)&(point_data[0]));
}
......@@ -33,6 +33,7 @@ private:
vec_lines walls;
Player player;
std::unique_ptr<vec_lines> get_player_lines(const vec_lines& walls,const Player& player) const;
void render_point(pos position, tuple_color color,const Display& display) const;
pos delta_pos;
pos goal;
float delta_rot;
......
......@@ -107,6 +107,8 @@ int main()
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)(2 * sizeof(float)));
glEnableVertexAttribArray(1);
//set glfw input mode to stick keys (stay pressed until polling)
glfwSetInputMode(window, GLFW_STICKY_KEYS, GLFW_TRUE);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment