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
6a1abb5d
Commit
6a1abb5d
authored
Jul 13, 2021
by
Srb František
Browse files
fix
#5
Nyní žádně warningy/errory na mám stroji i pro /Wall
parent
2db75ed9
Changes
5
Show whitespace changes
Inline
Side-by-side
CppGame/Characters.cpp
View file @
6a1abb5d
...
...
@@ -8,7 +8,7 @@ Enemy::Enemy(float fov, float vision_range, std::pair<float, float> position,
{
// recalculate point stops to lines (to show them on DEBUG_MODE)
std
::
vector
<
Line
>
line_path
;
auto
[
last_x
,
last_y
,
_
]
=
path
[
0
];
auto
&&
[
last_x
,
last_y
,
_
]
=
path
[
0
];
for
(
auto
&&
[
x
,
y
,
_
]
:
path
)
{
if
(
x
!=
last_x
||
y
!=
last_y
)
{
line_path
.
push_back
(
Line
(
last_x
,
last_y
,
x
,
y
,
color
,
color
));
...
...
@@ -19,12 +19,10 @@ Enemy::Enemy(float fov, float vision_range, std::pair<float, float> position,
this
->
line_path
=
line_path
;
}
void
Enemy
::
update
(
double
delta_time
)
void
Enemy
::
update
(
float
delta_time
)
{
//TODO
//probably will redo this piece of code
static
constexpr
float
epsilon
=
0.01
f
;
auto
[
stop_x
,
stop_y
,
wait_time
]
=
path
[
path_index
];
auto
&&
[
stop_x
,
stop_y
,
wait_time
]
=
path
[
path_index
];
auto
[
x
,
y
]
=
position
;
if
(
path
.
size
()
==
1
)
{
rotation
+=
delta_time
;
...
...
@@ -54,7 +52,7 @@ void Enemy::update(double delta_time)
++
path_index
;
}
}
auto
[
next_stop_x
,
next_stop_y
,
_
]
=
path
[
path_index
];
auto
&&
[
next_stop_x
,
next_stop_y
,
_
]
=
path
[
path_index
];
rotation
=
atan2
(
next_stop_y
-
y
,
next_stop_x
-
x
);
}
}
...
...
CppGame/Characters.h
View file @
6a1abb5d
...
...
@@ -24,11 +24,11 @@ public:
size_t
path_index
;
float
progress
;
bool
waiting
;
std
::
optional
<
std
::
vector
<
Line
>>
line_path
;
Enemy
(
float
fov
,
float
vision_range
,
std
::
pair
<
float
,
float
>
position
,
float
mov_speed
,
float
rot_speed
,
int
rays
,
tuple_color
color
,
std
::
vector
<
std
::
tuple
<
float
,
float
,
int
>>
path
);
void
update
(
double
delta_time
);
void
update
(
float
delta_time
);
};
\ No newline at end of file
CppGame/CppGame.vcxproj
View file @
6a1abb5d
...
...
@@ -132,13 +132,14 @@
</ItemDefinitionGroup>
<ItemDefinitionGroup
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
<ClCompile>
<WarningLevel>
Level3
</WarningLevel>
<WarningLevel>
EnableAllWarnings
</WarningLevel>
<FunctionLevelLinking>
true
</FunctionLevelLinking>
<IntrinsicFunctions>
true
</IntrinsicFunctions>
<SDLCheck>
true
</SDLCheck>
<PreprocessorDefinitions>
NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
</PreprocessorDefinitions>
<ConformanceMode>
true
</ConformanceMode>
<AdditionalIncludeDirectories>
$(SolutionDir)\include;%(AdditionalIncludeDirectories)
</AdditionalIncludeDirectories>
<LanguageStandard>
stdcpp17
</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>
Console
</SubSystem>
...
...
CppGame/Scene.cpp
View file @
6a1abb5d
...
...
@@ -117,25 +117,24 @@ void Scene::load_scene_from_file(std::string file)
void
Scene
::
render_scene
(
const
Display
&
display
)
const
{
if
(
DEBUG_MODE
||
draw_walls
)
display
.
DrawObject
((
float
*
)
&
(
walls
[
0
]),
walls
.
size
()
*
2
);
display
.
DrawObject
((
float
*
)
&
(
walls
[
0
]),
(
unsigned
int
)
walls
.
size
()
*
2
);
//draw sonar
if
(
sonar
.
has_value
()){
auto
sonar_lines_ptr
=
get_player_lines
(
walls
,
sonar
.
value
());
float
sin_green
=
(
sin
(
time
)
+
1
)
/
2
;
display
.
DrawObject
((
float
*
)
&
((
*
sonar_lines_ptr
)[
0
]),
sonar_lines_ptr
->
size
()
*
2
);
display
.
DrawObject
((
float
*
)
&
((
*
sonar_lines_ptr
)[
0
]),
(
unsigned
int
)
sonar_lines_ptr
->
size
()
*
2
);
}
if
(
DEBUG_MODE
)
//draw paths
for
(
auto
&&
enemy
:
enemies
)
{
auto
&&
line_path
=
enemy
.
line_path
.
value
();
display
.
DrawObject
((
float
*
)
&
(
line_path
[
0
]),
line_path
.
size
()
*
2
);
display
.
DrawObject
((
float
*
)
&
(
line_path
[
0
]),
(
unsigned
int
)
line_path
.
size
()
*
2
);
}
//draw enemies
for
(
auto
&&
enemy
:
enemies
)
{
if
(
!
pos_is_visible
(
player
,
enemy
.
position
)
&&
!
DEBUG_MODE
&&
(
!
sonar
.
has_value
()
||
!
pos_is_visible
((
*
sonar
),
enemy
.
position
)))
continue
;
auto
enemy_lines_ptr
=
get_player_lines
(
walls
,
enemy
);
display
.
DrawObject
((
float
*
)
&
((
*
enemy_lines_ptr
)[
0
]),
enemy_lines_ptr
->
size
()
*
2
);
display
.
DrawObject
((
float
*
)
&
((
*
enemy_lines_ptr
)[
0
]),
(
unsigned
int
)
enemy_lines_ptr
->
size
()
*
2
);
}
//draw goal
if
(
DEBUG_MODE
||
pos_is_visible
(
player
,
goal
))
{
...
...
@@ -147,7 +146,7 @@ void Scene::render_scene(const Display& display) const
display
.
DrawObject
((
float
*
)
&
(
goal_lines
[
0
]),
4
);
}
auto
player_lines_ptr
=
get_player_lines
(
walls
,
player
);
display
.
DrawObject
((
float
*
)
&
((
*
player_lines_ptr
)[
0
]),
player_lines_ptr
->
size
()
*
2
);
display
.
DrawObject
((
float
*
)
&
((
*
player_lines_ptr
)[
0
]),
(
unsigned
int
)
player_lines_ptr
->
size
()
*
2
);
}
void
Scene
::
restart_scene
()
...
...
@@ -207,7 +206,7 @@ void Scene::handle_input(GLFWwindow* window)
delta_pos
=
new_pos
;
}
bool
Scene
::
update
(
double
delta_time
)
bool
Scene
::
update
(
float
delta_time
)
{
//----player----
if
(
!
check_collision
(
delta_time
))
...
...
@@ -247,8 +246,8 @@ bool Scene::end_screen(const Display& display)
}
bar
.
push_back
(
Line
(
-
1.0
f
,
y
,
1.0
f
,
y
,
red
,
red
));
}
display
.
DrawObject
((
float
*
)
&
(
bar
[
0
]),
bar
.
size
());
end_screen_height
+=
bar
.
size
()
/
4
;
display
.
DrawObject
((
float
*
)
&
(
bar
[
0
]),
(
unsigned
int
)
bar
.
size
());
end_screen_height
+=
(
int
)(
bar
.
size
()
/
4
)
;
return
false
;
}
...
...
@@ -309,7 +308,7 @@ std::unique_ptr<vec_lines> Scene::get_player_lines(const vec_lines& walls, const
{
vec_lines
lines
;
auto
[
x
,
y
]
=
player
.
position
;
//unstructre pair to 2 floats
double
line_size
=
player
.
vision_range
;
float
line_size
=
player
.
vision_range
;
//beginning angle of rays
float
angle
=
player
.
rotation
-
player
.
fov
/
2
;
for
(
size_t
i
=
0
;
i
<
player
.
rays
;
i
++
)
...
...
CppGame/Scene.h
View file @
6a1abb5d
...
...
@@ -8,7 +8,7 @@
#include <optional>
#include <memory>
#define PI 3.14159265
#define PI 3.14159265
f
#define DEBUG_MODE false
using
vec_lines
=
std
::
vector
<
Line
>
;
...
...
@@ -21,7 +21,7 @@ public:
void
render_scene
(
const
Display
&
display
)
const
;
void
restart_scene
();
void
handle_input
(
GLFWwindow
*
window
);
bool
update
(
double
delta_time
);
bool
update
(
float
delta_time
);
bool
end_screen
(
const
Display
&
display
);
bool
check_collision
(
float
delta_time
)
const
;
bool
pos_is_visible
(
const
Player
&
character
,
pos
position
)
const
;
...
...
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