Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Srb František
Cpp-Game
Commits
f87ab806
Commit
f87ab806
authored
Jul 13, 2021
by
Srb František
Browse files
Added Dot as Player/Enemy character -> fix
#1
parent
99fca5df
Changes
5
Hide whitespace changes
Inline
Side-by-side
CppGame/Display.cpp
View file @
f87ab806
...
@@ -20,6 +20,16 @@ void Display::DrawObject(float* line,unsigned int num_of_vertices) const
...
@@ -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
()
void
Display
::
CleanWindow
()
{
{
//clean whole screen and set every pixel to black
//clean whole screen and set every pixel to black
...
...
CppGame/Display.h
View file @
f87ab806
...
@@ -9,6 +9,7 @@ public:
...
@@ -9,6 +9,7 @@ public:
Display
(
unsigned
int
VAO
,
unsigned
int
shaderProgram
);
Display
(
unsigned
int
VAO
,
unsigned
int
shaderProgram
);
~
Display
();
~
Display
();
void
DrawObject
(
float
*
line
,
unsigned
int
num_of_vertices
)
const
;
void
DrawObject
(
float
*
line
,
unsigned
int
num_of_vertices
)
const
;
void
DrawPoint
(
float
*
line
)
const
;
void
CleanWindow
();
void
CleanWindow
();
private:
private:
unsigned
int
VAO
;
unsigned
int
VAO
;
...
...
CppGame/Scene.cpp
View file @
f87ab806
...
@@ -135,6 +135,7 @@ void Scene::render_scene(const Display& display) const
...
@@ -135,6 +135,7 @@ void Scene::render_scene(const Display& display) const
continue
;
continue
;
auto
enemy_lines_ptr
=
get_player_lines
(
walls
,
enemy
);
auto
enemy_lines_ptr
=
get_player_lines
(
walls
,
enemy
);
display
.
DrawObject
((
float
*
)
&
((
*
enemy_lines_ptr
)[
0
]),
(
unsigned
int
)
enemy_lines_ptr
->
size
()
*
2
);
display
.
DrawObject
((
float
*
)
&
((
*
enemy_lines_ptr
)[
0
]),
(
unsigned
int
)
enemy_lines_ptr
->
size
()
*
2
);
this
->
render_point
(
enemy
.
position
,
enemy
.
color
,
display
);
}
}
//draw goal
//draw goal
if
(
DEBUG_MODE
||
pos_is_visible
(
player
,
goal
))
{
if
(
DEBUG_MODE
||
pos_is_visible
(
player
,
goal
))
{
...
@@ -147,6 +148,7 @@ void Scene::render_scene(const Display& display) const
...
@@ -147,6 +148,7 @@ void Scene::render_scene(const Display& display) const
}
}
auto
player_lines_ptr
=
get_player_lines
(
walls
,
player
);
auto
player_lines_ptr
=
get_player_lines
(
walls
,
player
);
display
.
DrawObject
((
float
*
)
&
((
*
player_lines_ptr
)[
0
]),
(
unsigned
int
)
player_lines_ptr
->
size
()
*
2
);
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
()
void
Scene
::
restart_scene
()
...
@@ -344,4 +346,16 @@ std::unique_ptr<vec_lines> Scene::get_player_lines(const vec_lines& walls, const
...
@@ -344,4 +346,16 @@ std::unique_ptr<vec_lines> Scene::get_player_lines(const vec_lines& walls, const
return
outline
;
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
]));
}
CppGame/Scene.h
View file @
f87ab806
...
@@ -33,6 +33,7 @@ private:
...
@@ -33,6 +33,7 @@ private:
vec_lines
walls
;
vec_lines
walls
;
Player
player
;
Player
player
;
std
::
unique_ptr
<
vec_lines
>
get_player_lines
(
const
vec_lines
&
walls
,
const
Player
&
player
)
const
;
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
delta_pos
;
pos
goal
;
pos
goal
;
float
delta_rot
;
float
delta_rot
;
...
...
CppGame/main.cpp
View file @
f87ab806
...
@@ -107,6 +107,8 @@ int main()
...
@@ -107,6 +107,8 @@ int main()
glVertexAttribPointer
(
1
,
3
,
GL_FLOAT
,
GL_FALSE
,
5
*
sizeof
(
float
),
(
void
*
)(
2
*
sizeof
(
float
)));
glVertexAttribPointer
(
1
,
3
,
GL_FLOAT
,
GL_FALSE
,
5
*
sizeof
(
float
),
(
void
*
)(
2
*
sizeof
(
float
)));
glEnableVertexAttribArray
(
1
);
glEnableVertexAttribArray
(
1
);
//set glfw input mode to stick keys (stay pressed until polling)
//set glfw input mode to stick keys (stay pressed until polling)
glfwSetInputMode
(
window
,
GLFW_STICKY_KEYS
,
GLFW_TRUE
);
glfwSetInputMode
(
window
,
GLFW_STICKY_KEYS
,
GLFW_TRUE
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment