Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
GameDevWeek
Sommersemester 2015
Cpp
Deth Buff Arr
Commits
262b4ffb
Commit
262b4ffb
authored
Sep 27, 2015
by
Elias Broschin
Browse files
stuff
parent
dbffeff7
Changes
5
Hide whitespace changes
Inline
Side-by-side
include/gameplay/game_input_manager.h
View file @
262b4ffb
...
...
@@ -17,7 +17,7 @@ public:
void
update
(
float
dt
);
glm
::
vec3
get_world_mouse_pos
();
void
render_ray
(
ray
*
r
,
float
length
,
float
radius
,
glm
::
vec3
color
);
void
process_beam_collision
(
ray
&
r
,
glm
::
vec3
&
ray_unnormalized
,
float
&
beam_velocity
,
float
&
ray_length_
,
bool
&
asteroid_hit
);
void
process_beam_collision
(
ray
&
r
,
glm
::
vec3
&
ray_unnormalized
,
float
&
beam_velocity
,
float
&
ray_length_
,
bool
&
asteroid_hit
,
int
&
portal_type
,
float
&
remaining_ray_length
);
private:
void
handle_key_input
(
float
dt
);
void
handle_mouse_input
(
float
dt
);
...
...
include/gameplay/level_manager.h
View file @
262b4ffb
...
...
@@ -48,6 +48,8 @@ public:
void
create_blue_portal
(
glm
::
vec3
world_pos
);
void
create_yellow_portal
(
glm
::
vec3
world_pos
);
bool
level_build
()
{
return
is_level_build_
;}
private:
engine
&
engine_
;
std
::
vector
<
unsigned
long
long
>
victims_
;
...
...
@@ -70,6 +72,8 @@ private:
maploader
maploader_
;
float
map_load_timer_
;
bool
is_level_build_
;
};
}
//Namespace gdw
...
...
src/game_state_machine/play_state.cpp
View file @
262b4ffb
...
...
@@ -44,7 +44,8 @@ play_state::~play_state() {}
void
play_state
::
on_enter
()
{
this
->
engine_
.
audioEventHandler
().
trigger
(
AudioEventHandler
::
PLAY_STATE_ENTER
);
engine_
.
game_play_system
().
level_manager
().
build_stage
();
if
(
!
engine_
.
game_play_system
().
level_manager
().
level_build
())
engine_
.
game_play_system
().
level_manager
().
build_stage
();
if
(
this
->
engine_
.
getConfig
().
get
<
bool
>
(
"test_ui"
,
""
))
{
auto
w1
=
engine_
.
ui_system
().
add_widget
<
box_widget
>
(
100
,
100
,
500
,
500
,
glm
::
vec4
(
0.7
,
0.2
,
0.1
,
0.6
));
auto
w2
=
w1
->
add_widget
<
box_widget
>
(
100
,
100
,
500
,
500
,
glm
::
vec4
(
0.2
,
0.2
,
0.1
,
0.6
));
...
...
@@ -57,7 +58,6 @@ void play_state::update(float dt) {
engine_
.
game_play_system
().
update
(
dt
);
this
->
engine_
.
audioEventHandler
().
playStateUpdate
(
dt
);
if
(
this
->
engine_
.
input
().
isPressed
(
inputMaping
::
state_switch
))
this
->
engine_
.
game_state_machine
().
change_state
<
menu_state
>
();
}
...
...
src/gameplay/game_input_manager.cpp
View file @
262b4ffb
...
...
@@ -175,8 +175,11 @@ namespace gdw {
auto
ray_length_
=
max_ray_length
;
bool
asteroid_hit
=
false
;
float
beam_velocity
=
10.
f
;
auto
remaining_length
=
0.
f
;
int
portal_type
=
-
1
;
//-1 none, 0 blue, 1 yellow
process_beam_collision
(
r
,
ray_unnormalized
,
beam_velocity
,
ray_length_
,
asteroid_hit
);
process_beam_collision
(
r
,
ray_unnormalized
,
beam_velocity
,
ray_length_
,
asteroid_hit
,
portal_type
,
remaining_length
);
if
(
input
.
isDown
(
inputMaping
::
beam_normal
))
{
auto
ray_length
=
(
std
::
abs
(
ray_length_
-
0.
f
)
<
0.001
f
)
?
glm
::
length
(
ray_unnormalized
)
:
ray_length_
;
...
...
@@ -185,6 +188,41 @@ namespace gdw {
auto
ray_length
=
(
std
::
abs
(
ray_length_
-
0.
f
)
<
0.001
f
)
?
glm
::
length
(
ray_unnormalized
)
:
ray_length_
;
render_ray
(
&
r
,
ray_length
,
std
::
max
((
beam_velocity
/
10.
f
)
/
2.
f
,
1.
f
),
glm
::
vec3
(
1
,
0
,
0
));
}
// do {
switch
(
portal_type
)
{
case
0
:
{
auto
yellow_portal
=
level_manager
.
yellow_portal
();
if
(
yellow_portal
)
{
ray
r2
(
yellow_portal
->
position
(),
yellow_portal
->
position
()
+
(
r
.
source
-
r
.
destination
));
portal_type
=
-
1
;
ray_length_
=
remaining_length
;
process_beam_collision
(
r2
,
ray_unnormalized
,
beam_velocity
,
ray_length_
,
asteroid_hit
,
portal_type
,
remaining_length
);
if
(
input
.
isDown
(
inputMaping
::
beam_normal
))
{
render_ray
(
&
r2
,
remaining_length
,
std
::
max
((
beam_velocity
/
10.
f
)
/
2.
f
,
1.
f
),
glm
::
vec3
(
0
,
0
,
1
));
}
else
{
render_ray
(
&
r2
,
remaining_length
,
std
::
max
((
beam_velocity
/
10.
f
)
/
2.
f
,
1.
f
),
glm
::
vec3
(
1
,
0
,
0
));
}
}
break
;
}
case
1
:
{
auto
blue_portal
=
level_manager
.
blue_portal
();
if
(
blue_portal
)
{
ray
r2
(
blue_portal
->
position
(),
blue_portal
->
position
()
+
(
r
.
source
-
r
.
destination
));
portal_type
=
-
1
;
ray_length_
=
remaining_length
;
process_beam_collision
(
r2
,
ray_unnormalized
,
beam_velocity
,
ray_length_
,
asteroid_hit
,
portal_type
,
remaining_length
);
if
(
input
.
isDown
(
inputMaping
::
beam_normal
))
{
render_ray
(
&
r2
,
remaining_length
,
std
::
max
((
beam_velocity
/
10.
f
)
/
2.
f
,
1.
f
),
glm
::
vec3
(
0
,
0
,
1
));
}
else
{
render_ray
(
&
r2
,
remaining_length
,
std
::
max
((
beam_velocity
/
10.
f
)
/
2.
f
,
1.
f
),
glm
::
vec3
(
1
,
0
,
0
));
}
}
break
;
}
default:
{}
}
// } while(portal_type > 0 || glm::length(remaining_length)<0.3f);
}
break
;
}
...
...
@@ -203,9 +241,9 @@ namespace gdw {
}
}
void
game_input_manager
::
process_beam_collision
(
ray
&
r
,
glm
::
vec3
&
ray_unnormalized
,
float
&
beam_velocity
,
float
&
ray_length_
,
bool
&
asteroid_hit
)
{
void
game_input_manager
::
process_beam_collision
(
ray
&
r
,
glm
::
vec3
&
ray_unnormalized
,
float
&
beam_velocity
,
float
&
ray_length_
,
bool
&
asteroid_hit
,
int
&
portal_type
,
float
&
remaining_ray_length
)
{
auto
collider
=
engine_
.
physics_system
().
checkCollisions
<
gdw
::
shape_type
::
ray
>
(
&
r
);
//DONT DO THIS AT HOME
//BEAM X ACCELERATOR
for
(
auto
&
coll
:
collider
)
{
...
...
@@ -219,10 +257,11 @@ namespace gdw {
}
}
//BEAM X EVERYTHING ELSE
//BEAM X ASTEROIDS
for
(
auto
&
coll
:
collider
)
{
auto
c
=
engine_
.
entity_manager
().
resolve
(
coll
);
auto
move
=
c
->
component
<
movement_component
>
();
auto
type_comp
=
c
->
component
<
object_type_component
>
();
if
(
type_comp
)
{
...
...
@@ -230,15 +269,49 @@ namespace gdw {
ray_length_
=
std
::
min
(
ray_length_
,
glm
::
length
(
c
->
position
()
-
r
.
source
));
asteroid_hit
=
true
;
}
if
(
type_comp
->
get_object_type
()
==
"PLAYER"
)
{
continue
;
}
}
}
//BEAM X PORTAL
for
(
auto
&
coll
:
collider
)
{
auto
c
=
engine_
.
entity_manager
().
resolve
(
coll
);
auto
type_comp
=
c
->
component
<
object_type_component
>
();
if
(
!
type_comp
)
continue
;
if
(
type_comp
->
get_object_type
()
==
"BLUE_PORTAL"
)
{
if
(
glm
::
length
(
r
.
source
-
c
->
position
())
>
ray_length_
)
continue
;
auto
reduced_ray_length
=
std
::
min
(
ray_length_
,
glm
::
length
(
c
->
position
()
-
r
.
source
));
remaining_ray_length
=
ray_length_
-
reduced_ray_length
;
ray_length_
=
reduced_ray_length
;
portal_type
=
0
;
}
if
(
type_comp
->
get_object_type
()
==
"YELLOW_PORTAL"
)
{
if
(
glm
::
length
(
r
.
source
-
c
->
position
())
>
ray_length_
)
continue
;
auto
reduced_ray_length
=
std
::
min
(
ray_length_
,
glm
::
length
(
c
->
position
()
-
r
.
source
));
remaining_ray_length
=
ray_length_
-
reduced_ray_length
;
ray_length_
=
reduced_ray_length
;
portal_type
=
1
;
}
}
//BEAM X MOVINGS
for
(
auto
&
coll
:
collider
)
{
auto
c
=
engine_
.
entity_manager
().
resolve
(
coll
);
auto
move
=
c
->
component
<
movement_component
>
();
auto
type_comp
=
c
->
component
<
object_type_component
>
();
if
(
type_comp
->
get_object_type
()
==
"PLAYER"
)
{
continue
;
}
if
(
glm
::
length
(
ray_unnormalized
)
<
0.01
f
)
continue
;
auto
attract_dir
=
glm
::
normalize
(
ray_unnormalized
);
if
(
move
)
{
//TODO: replace hardcode value with victim_speed
auto
distance
=
glm
::
length
(
r
.
source
-
c
->
position
());
if
(
glm
::
length
(
r
.
source
-
c
->
position
())
<
ray_length_
)
{
move
->
add_force
((
attract_dir
*
beam_velocity
)
/
std
::
max
(
distance
/
20.
f
,
2.
f
));
...
...
src/gameplay/level_manager.cpp
View file @
262b4ffb
...
...
@@ -34,7 +34,7 @@
namespace
gdw
{
level_manager
::
level_manager
(
engine
&
engine
)
:
engine_
(
engine
),
player_speed_
(
80.
f
),
maploader_
(
engine_
),
weapon_type_
(
weapon_type
::
tractor_beam
),
blue_portal_
(
-
1
),
yellow_portal_
(
-
1
)
{
blue_portal_
(
-
1
),
yellow_portal_
(
-
1
)
,
is_level_build_
(
false
)
{
auto
ptr
=
engine_
.
config_manager
().
load
(
"config/settings"
);
map_load_timer_
=
ptr
->
get
<
float
>
(
"map_load_timer"
,
0.
f
);
}
...
...
@@ -116,6 +116,8 @@ namespace gdw {
float
tpos
[]{
20
+
15
,
3
,
15
};
maploader_
.
set_move_target
(
tpos
,
false
);
is_level_build_
=
true
;
}
void
level_manager
::
update
(
float
dt
)
{
...
...
@@ -326,6 +328,11 @@ namespace gdw {
auto
&
portal
=
engine_
.
entity_manager
().
emplace_back
(
glm
::
vec3
(
world_pos
.
x
,
3.
f
,
world_pos
.
z
),
glm
::
angleAxis
(
glm
::
radians
(
-
45.
f
),
glm
::
vec3
(
1.
f
,
0.
f
,
0.
f
)));
portal
.
emplace_back
<
staticmesh_component
>
(
"mesh/coin.msh"
);
portal
.
emplace_back
<
object_type_component
>
(
"BLUE_PORTAL"
);
auto
col_data
=
engine_
.
physics_system
().
collision_data_manager
().
load
(
"physic/coin.col"
);
auto
&
coll_comp
=
portal
.
emplace_back
<
collision_component
>
(
new
sphere
(
col_data
->
center
(),
glm
::
length
(
col_data
->
half_extend
())));
blue_portal_
=
portal
.
id
();
}
...
...
@@ -339,7 +346,12 @@ namespace gdw {
auto
&
portal
=
engine_
.
entity_manager
().
emplace_back
(
glm
::
vec3
(
world_pos
.
x
,
3.
f
,
world_pos
.
z
),
glm
::
angleAxis
(
glm
::
radians
(
-
45.
f
),
glm
::
vec3
(
1.
f
,
0.
f
,
0.
f
)));
portal
.
emplace_back
<
staticmesh_component
>
(
"mesh/coin.msh"
);
portal
.
emplace_back
<
object_type_component
>
(
"YELLOW_PORTAL"
);
portal
.
scale
(
glm
::
vec3
(
1.5
f
));
auto
col_data
=
engine_
.
physics_system
().
collision_data_manager
().
load
(
"physic/coin.col"
);
auto
&
coll_comp
=
portal
.
emplace_back
<
collision_component
>
(
new
sphere
(
col_data
->
center
(),
glm
::
length
(
col_data
->
half_extend
())));
yellow_portal_
=
portal
.
id
();
}
...
...
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