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
9f7a5e89
Commit
9f7a5e89
authored
Oct 20, 2015
by
Benjamin 'Albsi' Albsmeier
Browse files
input methodes now renamed to snake case
parent
1af81e5d
Changes
9
Hide whitespace changes
Inline
Side-by-side
assets/config/settings.main
View file @
9f7a5e89
...
...
@@ -29,7 +29,7 @@ beam_inverse_mouse_button : right
beam_inverse_controller_axis : righttrigger
place_item_key1 : Space
place_item_mouse_button : Middle
place_item_controller_button :
A
place_item_controller_button :
a
test_key1 : t
test_key2 : p
test_mouse_button : middle
...
...
include/input/input.hpp
View file @
9f7a5e89
...
...
@@ -34,8 +34,8 @@ namespace gdw{
engine
&
engine_
;
glm
::
vec2
pos_
;
int
window
W
idth_
=
800
;
int
window
H
eight_
=
600
;
int
window
_w
idth_
=
800
;
int
window
_h
eight_
=
600
;
public:
input
(
engine
&
engine
);
~
input
();
...
...
@@ -76,37 +76,37 @@ namespace gdw{
* controller axis: <name>_controller_axis : <axis> + '_positiv' or '_negativ' (ignored if trigger)
* example: test_controller_axis : leftx_positiv
*/
void
add
M
apping
(
std
::
string
name
);
void
add
_m
apping
(
std
::
string
name
);
/**prints the mapping*/
void
print
M
apping
();
void
print
_m
apping
();
/**Returns true every frame, as long as it is down
* controller_id only for multi controller
*/
bool
isP
ressed
(
std
::
string
mapping
,
int
controller_id
=
-
1
);
bool
p
ressed
(
std
::
string
mapping
,
int
controller_id
=
-
1
);
/**Returns true once it is pressed
* controller_id only for multi controller
*/
bool
isD
own
(
std
::
string
mapping
,
int
controller_id
=
-
1
);
bool
d
own
(
std
::
string
mapping
,
int
controller_id
=
-
1
);
/**Returns true once it is released
* controller_id only for multi controller
*/
bool
isR
eleased
(
std
::
string
mapping
,
int
controller_id
=
-
1
);
bool
r
eleased
(
std
::
string
mapping
,
int
controller_id
=
-
1
);
/**returns x position of the mouse cursor or of the controller cross-hair*/
int
position
X
();
int
position
_x
();
/**returns y position of the mouse cursor or of the controller cross-hair*/
int
position
Y
();
int
position
_y
();
/**x motion of the mouse wheel*/
int
mouse
W
heel
X
();
int
mouse
_w
heel
_x
();
/**y motion of the mouse wheel*/
int
mouse
W
heel
Y
();
int
mouse
_w
heel
_y
();
std
::
shared_ptr
<
gdw
::
keyboard
>
keyboard
()
noexcept
{
return
keyboard_
;};
std
::
shared_ptr
<
gdw
::
controller
>
controller
(
int
id
=
-
1
);
...
...
src/audio/AudioEventHandler.cpp
View file @
9f7a5e89
...
...
@@ -43,13 +43,13 @@ namespace gdw {
}
void
AudioEventHandler
::
playStateUpdate
(
float
)
{
if
((
this
->
engine
.
input
().
isP
ressed
(
"move_left"
)
||
this
->
engine
.
input
().
isP
ressed
(
"move_right"
))
&&
!
this
->
playerMoving
)
{
if
((
this
->
engine
.
input
().
p
ressed
(
"move_left"
)
||
this
->
engine
.
input
().
p
ressed
(
"move_right"
))
&&
!
this
->
playerMoving
)
{
this
->
channels
[
"ship"
]
=
this
->
engine
.
audio
().
queue_sound
(
"engine"
,
-
1
);
this
->
engine
.
audio
().
sound_volume
(
40
,
this
->
channels
[
"ship"
]);
this
->
playerMoving
=
true
;
}
if
(
!
this
->
engine
.
input
().
isD
own
(
"move_left"
)
&&
!
this
->
engine
.
input
().
isD
own
(
"move_right"
)
&&
this
->
playerMoving
)
{
if
(
!
this
->
engine
.
input
().
d
own
(
"move_left"
)
&&
!
this
->
engine
.
input
().
d
own
(
"move_right"
)
&&
this
->
playerMoving
)
{
this
->
engine
.
audio
().
stop_sound
(
this
->
channels
[
"ship"
],
800
);
this
->
playerMoving
=
false
;
...
...
src/core/engine.cpp
View file @
9f7a5e89
...
...
@@ -48,7 +48,7 @@ namespace gdw {
ui_system_
=
make_unique
<
gdw
::
ui_system
>
(
*
this
);
game_state_machine_
=
make_unique
<
gdw
::
game_state_machine
>
(
*
this
);
input_
->
add
M
apping
(
"state_switch"
);
input_
->
add
_m
apping
(
"state_switch"
);
}
engine
::~
engine
()
noexcept
{
...
...
src/game_state_machine/credits_state.cpp
View file @
9f7a5e89
...
...
@@ -48,14 +48,14 @@ namespace gdw {
}
void
credits_state
::
update
(
float
dt
)
{
if
(
this
->
engine_
.
input
().
isP
ressed
(
"state_switch"
))
if
(
this
->
engine_
.
input
().
p
ressed
(
"state_switch"
))
this
->
engine_
.
game_state_machine
().
change_state
<
menu_state
>
();
if
(
this
->
rootElement
->
y_px
()
<=
(
this
->
rootElement
->
height_px
()
+
this
->
engine_
.
graphics_system
().
height
())
*
-
1
)
{
this
->
rootElement
->
y
(
this
->
uiManager
->
getElementById
(
"credits"
)
->
height
());
this
->
topMargin
=
0.5
f
/
100
*
5
;
}
double
scrollAmount
=
this
->
engine_
.
input
().
isD
own
(
"beam_normal"
)
?
0.005
:
0.001
;
scrollAmount
=
this
->
engine_
.
input
().
isD
own
(
"beam_inverse"
)
?
0.010
:
scrollAmount
;
double
scrollAmount
=
this
->
engine_
.
input
().
d
own
(
"beam_normal"
)
?
0.005
:
0.001
;
scrollAmount
=
this
->
engine_
.
input
().
d
own
(
"beam_inverse"
)
?
0.010
:
scrollAmount
;
this
->
rootElement
->
y
(
this
->
rootElement
->
y
()
-
scrollAmount
);
}
...
...
src/game_state_machine/play_state.cpp
View file @
9f7a5e89
...
...
@@ -71,7 +71,7 @@ void play_state::update(float dt) {
engine_
.
game_play_system
().
update
(
dt
);
this
->
engine_
.
audioEventHandler
().
playStateUpdate
(
dt
);
if
(
this
->
engine_
.
input
().
isP
ressed
(
"state_switch"
))
if
(
this
->
engine_
.
input
().
p
ressed
(
"state_switch"
))
this
->
engine_
.
game_state_machine
().
change_state
<
menu_state
>
();
}
...
...
src/gameplay/game_input_manager.cpp
View file @
9f7a5e89
...
...
@@ -28,12 +28,12 @@ namespace gdw {
game_input_manager
::
game_input_manager
(
engine
&
engine
)
:
engine_
(
engine
)
{
auto
&
input
=
engine_
.
input
();
input
.
add
M
apping
(
"test"
);
input
.
add
M
apping
(
"move_left"
);
input
.
add
M
apping
(
"move_right"
);
input
.
add
M
apping
(
"place_item"
);
input
.
add
M
apping
(
"beam_normal"
);
input
.
add
M
apping
(
"beam_inverse"
);
input
.
add
_m
apping
(
"test"
);
input
.
add
_m
apping
(
"move_left"
);
input
.
add
_m
apping
(
"move_right"
);
input
.
add
_m
apping
(
"place_item"
);
input
.
add
_m
apping
(
"beam_normal"
);
input
.
add
_m
apping
(
"beam_inverse"
);
}
game_input_manager
::~
game_input_manager
()
{
...
...
@@ -49,8 +49,8 @@ namespace gdw {
auto
&
input
=
engine_
.
input
();
auto
&
level_manager
=
engine_
.
game_play_system
().
level_manager
();
float
x
=
(
float
(
input
.
position
X
())
/
engine_
.
graphics_system
().
width
())
*
2.0
f
-
1
;
float
y
=
(
float
(
input
.
position
Y
())
/
engine_
.
graphics_system
().
height
())
*
2.0
f
-
1
;
float
x
=
(
float
(
input
.
position
_x
())
/
engine_
.
graphics_system
().
width
())
*
2.0
f
-
1
;
float
y
=
(
float
(
input
.
position
_y
())
/
engine_
.
graphics_system
().
height
())
*
2.0
f
-
1
;
auto
cam
=
level_manager
.
camera
()
->
component
<
camera_component
>
();
auto
camera
=
level_manager
.
camera
();
...
...
@@ -82,21 +82,21 @@ namespace gdw {
constexpr
float
rotation_speed
=
7.
f
;
constexpr
float
turn_rate_modifier
=
4.5
f
;
if
(
input
.
isP
ressed
(
"test"
)){
if
(
input
.
p
ressed
(
"test"
)){
//log << "input test pressed" << std::endl;
input
.
print
M
apping
();
input
.
print
_m
apping
();
}
/*if (input.
isD
own("test")){
log << "pos: x:" << input.position
X
() << " y:" << input.position
Y
() << std::endl;
/*if (input.
d
own("test")){
log << "pos: x:" << input.position
_x
() << " y:" << input.position
_y
() << std::endl;
//log << "input test down" << std::endl;
}*/
/*if (input.
isR
eleased("test")){
/*if (input.
r
eleased("test")){
log << "input test released" << std::endl;
}*/
if
(
input
.
isD
own
(
"move_left"
)
&&
player
->
position
().
x
>
-
maximum_movement_distance
)
{
if
(
input
.
d
own
(
"move_left"
)
&&
player
->
position
().
x
>
-
maximum_movement_distance
)
{
auto
orientation
=
player
->
rotation
()
*
glm
::
vec3
(
0
,
0
,
1
);
auto
diff
=
std
::
abs
(
orientation
.
x
-
(
-
1.
f
))
+
std
::
abs
(
orientation
.
z
-
(
0.
f
));
auto
clamped
=
glm
::
clamp
(
diff
/
turn_rate_modifier
,
0.
f
,
1.
f
);
...
...
@@ -109,7 +109,7 @@ namespace gdw {
move
->
add_angular_force
(
glm
::
vec3
(
0.
f
,
-
rotation_speed
*
(
std
::
pow
(
diff
,
1.4
f
))
,
0.
f
));
}
if
(
engine_
.
input
().
isD
own
(
"move_right"
)
&&
player
->
position
().
x
<
maximum_movement_distance
)
{
if
(
engine_
.
input
().
d
own
(
"move_right"
)
&&
player
->
position
().
x
<
maximum_movement_distance
)
{
auto
orientation
=
player
->
rotation
()
*
glm
::
vec3
(
0
,
0
,
1
);
auto
diff
=
std
::
abs
(
orientation
.
x
-
(
1.
f
))
+
std
::
abs
(
orientation
.
z
-
(
0.
f
));
auto
clamped
=
glm
::
clamp
(
diff
/
turn_rate_modifier
,
0.
f
,
1.
f
);
...
...
@@ -123,7 +123,7 @@ namespace gdw {
}
// SET ITEM WITH SPACE KEY
if
(
input
.
isD
own
(
"place_item"
))
{
if
(
input
.
d
own
(
"place_item"
))
{
engine_
.
game_play_system
().
player_item_manager
().
place_item
(
get_world_mouse_pos
());
}
}
...
...
@@ -133,35 +133,35 @@ namespace gdw {
auto
&
level_manager
=
engine_
.
game_play_system
().
level_manager
();
//MOUSEWHEEL
if
(
input
.
mouse
W
heel
Y
()
<
0.
f
)
{
if
(
input
.
mouse
_w
heel
_y
()
<
0.
f
)
{
auto
cam
=
engine_
.
game_play_system
().
level_manager
().
camera
();
cam
->
position
(
cam
->
position
()
+
glm
::
vec3
(
0
,
1.
f
,
1.
f
));
level_manager
.
set_weapon
(
weapon_type
::
tractor_beam
);
}
if
(
input
.
mouse
W
heel
Y
()
>
0.
f
)
{
if
(
input
.
mouse
_w
heel
_y
()
>
0.
f
)
{
auto
cam
=
engine_
.
game_play_system
().
level_manager
().
camera
();
cam
->
position
(
cam
->
position
()
+
glm
::
vec3
(
0
,
-
1.
f
,
-
1.
f
));
level_manager
.
set_weapon
(
weapon_type
::
portal_gun
);
}
if
(
input
.
isP
ressed
(
"beam_normal"
))
{
if
(
input
.
p
ressed
(
"beam_normal"
))
{
engine_
.
audioEventHandler
().
trigger
(
AudioEventHandler
::
TRAKTORBEAM_REVERSE_ACTIVATED
);
}
if
(
input
.
isR
eleased
(
"beam_normal"
))
{
if
(
input
.
r
eleased
(
"beam_normal"
))
{
engine_
.
audioEventHandler
().
trigger
(
AudioEventHandler
::
TRAKTORBEAM_REVERSE_DEACTIVATED
);
}
if
(
input
.
isP
ressed
(
"beam_inverse"
))
{
if
(
input
.
p
ressed
(
"beam_inverse"
))
{
engine_
.
audioEventHandler
().
trigger
(
AudioEventHandler
::
TRAKTORBEAM_ACTIVATED
);
}
if
(
input
.
isR
eleased
(
"beam_inverse"
))
{
if
(
input
.
r
eleased
(
"beam_inverse"
))
{
engine_
.
audioEventHandler
().
trigger
(
AudioEventHandler
::
TRAKTORBEAM_DEACTIVATED
);
}
//LEFT && RIGHT CLICK
switch
(
level_manager
.
weapon
())
{
case
weapon_type
::
tractor_beam
:
{
if
(
input
.
isD
own
(
"beam_normal"
)
||
input
.
isD
own
(
"beam_inverse"
))
{
if
(
input
.
d
own
(
"beam_normal"
)
||
input
.
d
own
(
"beam_inverse"
))
{
auto
intersection_point
=
get_world_mouse_pos
();
auto
cannon
=
level_manager
.
cannon
();
...
...
@@ -174,7 +174,7 @@ namespace gdw {
ray
r
(
cannon_pos
+
offset
,
intersection_point
);
auto
ray_unnormalized
=
glm
::
vec3
(
1.
f
);
if
(
input
.
isD
own
(
"beam_normal"
))
{
if
(
input
.
d
own
(
"beam_normal"
))
{
ray_unnormalized
=
r
.
source
-
r
.
destination
;
}
else
{
ray_unnormalized
=
r
.
destination
-
r
.
source
;
...
...
@@ -190,7 +190,7 @@ namespace gdw {
process_beam_collision
(
r
,
ray_unnormalized
,
beam_velocity
,
ray_length_
,
asteroid_hit
,
portal_type
,
remaining_length
);
if
(
input
.
isD
own
(
"beam_normal"
))
{
if
(
input
.
d
own
(
"beam_normal"
))
{
auto
ray_length
=
(
std
::
abs
(
ray_length_
-
0.
f
)
<
0.001
f
)
?
glm
::
length
(
ray_unnormalized
)
:
ray_length_
;
render_ray
(
&
r
,
offset
,
ray_length
,
0.18
f
,
false
,
glm
::
vec3
(
0.5
f
,
0.6
f
,
0.9
f
));
}
else
{
...
...
@@ -206,7 +206,7 @@ namespace gdw {
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
.
isD
own
(
"beam_normal"
))
{
if
(
input
.
d
own
(
"beam_normal"
))
{
render_ray
(
&
r2
,
offset
,
remaining_length
,
0.18
f
,
false
,
glm
::
vec3
(
0
,
0
,
1
));
}
else
{
render_ray
(
&
r2
,
offset
,
remaining_length
,
0.18
f
,
true
,
glm
::
vec3
(
1
,
0
,
0
));
...
...
@@ -221,7 +221,7 @@ namespace gdw {
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
.
isD
own
(
"beam_normal"
))
{
if
(
input
.
d
own
(
"beam_normal"
))
{
render_ray
(
&
r2
,
offset
,
remaining_length
,
0.18
f
,
false
,
glm
::
vec3
(
0
,
0
,
1
));
}
else
{
render_ray
(
&
r2
,
offset
,
remaining_length
,
0.18
f
,
true
,
glm
::
vec3
(
1
,
0
,
0
));
...
...
@@ -236,13 +236,13 @@ namespace gdw {
break
;
}
case
weapon_type
::
portal_gun
:
{
if
(
input
.
isD
own
(
"beam_normal"
)
||
input
.
isD
own
(
"beam_inverse"
))
{
if
(
input
.
d
own
(
"beam_normal"
)
||
input
.
d
own
(
"beam_inverse"
))
{
auto
intersection_point
=
get_world_mouse_pos
();
if
(
input
.
isD
own
(
"beam_normal"
))
if
(
input
.
d
own
(
"beam_normal"
))
level_manager
.
create_blue_portal
(
intersection_point
);
if
(
input
.
isD
own
(
"beam_inverse"
))
if
(
input
.
d
own
(
"beam_inverse"
))
level_manager
.
create_yellow_portal
(
intersection_point
);
}
break
;
...
...
src/input/input.cpp
View file @
9f7a5e89
...
...
@@ -22,8 +22,8 @@ namespace gdw{
mapping_
=
std
::
make_shared
<
gdw
::
input_mapping
>
(
this
,
engine_
);
controller_manager_
=
std
::
make_shared
<
gdw
::
controller_manager
>
(
this
,
engine_
);
window
W
idth_
=
engine_
.
getConfig
().
get
<
int
>
(
"width"
,
800
);
window
H
eight_
=
engine_
.
getConfig
().
get
<
int
>
(
"height"
,
600
);
window
_w
idth_
=
engine_
.
getConfig
().
get
<
int
>
(
"width"
,
800
);
window
_h
eight_
=
engine_
.
getConfig
().
get
<
int
>
(
"height"
,
600
);
}
input
::~
input
(){}
...
...
@@ -45,16 +45,16 @@ namespace gdw{
}
//MAPPING
void
input
::
add
M
apping
(
std
::
string
name
){
void
input
::
add
_m
apping
(
std
::
string
name
){
mapping_
->
add
(
name
);
}
void
input
::
print
M
apping
(){
void
input
::
print
_m
apping
(){
mapping_
->
print
();
}
//RETURN
bool
input
::
isP
ressed
(
std
::
string
id
,
int
controller_id
){
bool
input
::
p
ressed
(
std
::
string
id
,
int
controller_id
){
if
(
!
mapping_
->
is_mapping
(
id
))
return
false
;
if
(
keyboard_
->
pressed
(
mapping_
->
key_1
(
id
))){
return
true
;
...
...
@@ -74,7 +74,7 @@ namespace gdw{
return
false
;
}
bool
input
::
isD
own
(
std
::
string
id
,
int
controller_id
){
bool
input
::
d
own
(
std
::
string
id
,
int
controller_id
){
if
(
!
mapping_
->
is_mapping
(
id
))
return
false
;
if
(
keyboard_
->
down
(
mapping_
->
key_1
(
id
))){
return
true
;
...
...
@@ -94,7 +94,7 @@ namespace gdw{
return
false
;
}
bool
input
::
isR
eleased
(
std
::
string
id
,
int
controller_id
){
bool
input
::
r
eleased
(
std
::
string
id
,
int
controller_id
){
if
(
!
mapping_
->
is_mapping
(
id
))
return
false
;
if
(
keyboard_
->
released
(
mapping_
->
key_1
(
id
))){
return
true
;
...
...
@@ -114,19 +114,19 @@ namespace gdw{
return
false
;
}
int
input
::
position
X
(){
int
input
::
position
_x
(){
return
pos_
.
x
;
}
int
input
::
position
Y
(){
int
input
::
position
_y
(){
return
pos_
.
y
;
}
int
input
::
mouse
W
heel
X
(){
int
input
::
mouse
_w
heel
_x
(){
return
mouse_
->
wheel_x
();
}
int
input
::
mouse
W
heel
Y
(){
int
input
::
mouse
_w
heel
_y
(){
return
mouse_
->
wheel_y
();
}
...
...
src/ui/ui_system.cpp
View file @
9f7a5e89
...
...
@@ -44,7 +44,7 @@ namespace gdw {
width
(
engine_
.
graphics_system
().
width
());
height
(
engine_
.
graphics_system
().
height
());
engine_
.
input
().
add
M
apping
(
"button_click"
);
engine_
.
input
().
add
_m
apping
(
"button_click"
);
}
ui_system
::~
ui_system
(){
...
...
@@ -56,8 +56,8 @@ namespace gdw {
//engine_.graphics_system().height()
//glClearStencil( 0 );
//nvgluBindFramebuffer( NVGFrameBuffer_ );
float
mousex
=
engine_
.
input
().
position
X
();
float
mousey
=
engine_
.
input
().
position
Y
();
float
mousex
=
engine_
.
input
().
position
_x
();
float
mousey
=
engine_
.
input
().
position
_y
();
for
(
auto
&
widget
:
child_widgets_
)
{
handleInput
(
mousex
,
mousey
,
widget
.
get
());
...
...
@@ -113,10 +113,10 @@ namespace gdw {
if
(
x
>
0
&&
y
>
0
&&
x
<
widget
->
width_px
()
&&
y
<
widget
->
height_px
()){
widget
->
on_hover
(
x
,
y
);
if
(
engine_
.
input
().
isP
ressed
(
"button_click"
)){
if
(
engine_
.
input
().
p
ressed
(
"button_click"
)){
widget
->
on_pressed
(
x
,
y
);
}
if
(
engine_
.
input
().
isR
eleased
(
"button_click"
)){
if
(
engine_
.
input
().
r
eleased
(
"button_click"
)){
widget
->
on_released
(
x
,
y
);
}
}
...
...
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