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
17705460
Commit
17705460
authored
Sep 26, 2015
by
Michael Ochmann
Browse files
added ship audio with stereo flanging
parent
f3e1379a
Changes
9
Hide whitespace changes
Inline
Side-by-side
assets/sound/ship_engine.ogg
0 → 100644
View file @
17705460
File added
include/audio/AudioEventHandler.hpp
View file @
17705460
...
...
@@ -18,14 +18,17 @@ namespace gdw {
TRAKTORBEAM_REVERSE_ACTIVATED
,
TRAKTORBEAM_REVERSE_DEACTIVATED
,
PLAY_STATE_ENTER
,
PLAY_STATE_LEAVE
PLAY_STATE_LEAVE
,
};
AudioEventHandler
(
gdw
::
engine
&
engine
);
~
AudioEventHandler
();
void
trigger
(
gdw
::
AudioEventHandler
::
Event
event
);
void
playStateUpdate
(
float
deltaTime
);
private:
gdw
::
engine
&
engine
;
std
::
unordered_map
<
std
::
string
,
int
>
channels
;
bool
playerMoving
;
static
constexpr
float
MinPanPercentage
=
30.0
f
;
};
}
...
...
include/audio/audio.hpp
View file @
17705460
...
...
@@ -63,6 +63,8 @@ namespace gdw {
Mix_Volume
(
channel
,
(
int
)(
1.28
f
*
volume
));
}
void
stereo
(
int
channel
,
int
left
,
int
right
);
int
sound_volume
()
{
return
sound_volume_
;
}
...
...
include/gameplay/game_input_manager.h
View file @
17705460
...
...
@@ -9,6 +9,7 @@ class game_input_manager {
public:
game_input_manager
(
engine
&
engine
);
~
game_input_manager
();
static
const
float
maximum_movement_distance
;
void
update
(
float
dt
);
private:
...
...
src/audio/AudioEventHandler.cpp
View file @
17705460
#include <audio/AudioEventHandler.hpp>
#include <audio/audio.hpp>
#include <core/engine.hpp>
#include <ecs/entity.hpp>
#include <glm/glm.hpp>
#include <physics/movement/movement_component.h>
#include <gameplay/game_play_system.h>
#include <gameplay/level_manager.h>
#include <gameplay/game_input_manager.h>
namespace
gdw
{
AudioEventHandler
::
AudioEventHandler
(
gdw
::
engine
&
engine
)
:
engine
(
engine
){
engine
(
engine
),
playerMoving
(
false
){
}
...
...
@@ -15,7 +22,7 @@ namespace gdw {
switch
(
event
)
{
case
Event
::
PLAY_STATE_ENTER
:
this
->
channels
[
"background"
]
=
this
->
engine
.
audio
().
queue_sound
(
"backgroundNoise"
,
-
1
);
this
->
engine
.
audio
().
sound_volume
(
5
,
this
->
channels
[
"background"
]);
this
->
engine
.
audio
().
sound_volume
(
1
5
,
this
->
channels
[
"background"
]);
break
;
case
Event
::
PLAY_STATE_LEAVE
:
this
->
engine
.
audio
().
stop_sound
(
this
->
channels
[
"background"
]);
...
...
@@ -31,4 +38,39 @@ namespace gdw {
return
;
}
}
void
AudioEventHandler
::
playStateUpdate
(
float
deltaTime
)
{
float
movement
=
glm
::
length
(
this
->
engine
.
game_play_system
().
level_manager
().
player
()
->
component
<
movement_component
>
()
->
current_velocity
());
if
(
movement
>
0.4
f
&&
!
this
->
playerMoving
)
{
this
->
playerMoving
=
true
;
this
->
channels
[
"ship"
]
=
this
->
engine
.
audio
().
queue_sound
(
"engine"
,
-
1
);
this
->
engine
.
audio
().
sound_volume
(
40
,
this
->
channels
[
"ship"
]);
}
if
(
movement
<
0.4
f
&&
this
->
playerMoving
)
{
this
->
playerMoving
=
false
;
this
->
engine
.
audio
().
stop_sound
(
this
->
channels
[
"ship"
],
400
);
}
if
(
this
->
playerMoving
)
{
float
shipMax
=
gdw
::
game_input_manager
::
maximum_movement_distance
;
float
shipX
=
this
->
engine
.
game_play_system
().
level_manager
().
player
()
->
position
().
x
;
int
left
=
50
;
int
right
=
50
;
if
(
shipX
<
0.5
f
)
{
left
=
(
int
)
((
shipX
*
-
1
)
*
100
/
shipMax
);
right
=
(
int
)
((
100
-
left
)
/
50.0
f
*
AudioEventHandler
::
MinPanPercentage
+
AudioEventHandler
::
MinPanPercentage
);
left
=
(
int
)
(
left
/
100.0
f
*
50.0
f
+
50
);
left
=
left
>=
100
?
100
:
left
;
}
if
(
shipX
>
0.5
f
)
{
right
=
(
int
)
(
shipX
*
100
/
shipMax
);
left
=
(
int
)
((
100
-
right
)
/
50.0
f
*
AudioEventHandler
::
MinPanPercentage
+
AudioEventHandler
::
MinPanPercentage
);
right
=
(
int
)
(
right
/
100.0
f
*
50.0
f
+
50
);
right
=
right
>=
100
?
100
:
right
;
}
log
<<
"left :: "
<<
left
<<
", right :: "
<<
right
<<
std
::
endl
;
this
->
engine
.
audio
().
stereo
(
this
->
channels
[
"ship"
],
left
,
right
);
}
}
}
\ No newline at end of file
src/audio/audio.cpp
View file @
17705460
...
...
@@ -106,4 +106,10 @@ namespace gdw {
}
Mix_FadeOutChannel
(
channel
,
fade_out
);
}
void
audio
::
stereo
(
int
channel
,
int
left
,
int
right
)
{
left
=
(
Uint8
)
(
left
*
255
/
100
);
right
=
(
Uint8
)
(
right
*
255
/
100
);
Mix_SetPanning
(
channel
,
left
,
right
);
}
}
src/audio/audio_collection.cpp
View file @
17705460
...
...
@@ -23,6 +23,10 @@ namespace gdw {
std
::
pair
<
const
std
::
string
,
sound_ptr
>
(
"tractorBeam"
,
sound_manager_
.
load
(
"sound/tractor_beam.ogg"
))
);
sound_collection_
.
insert
(
std
::
pair
<
const
std
::
string
,
sound_ptr
>
(
"engine"
,
sound_manager_
.
load
(
"sound/ship_engine.ogg"
))
);
}
music_ptr
audio_collection
::
music
(
const
std
::
string
&
name
)
const
{
...
...
src/game_state_machine/play_state.cpp
View file @
17705460
...
...
@@ -47,6 +47,7 @@ void play_state::on_enter() {
void
play_state
::
update
(
float
dt
)
{
engine_
.
game_play_system
().
update
(
dt
);
this
->
engine_
.
audioEventHandler
().
playStateUpdate
(
dt
);
if
(
this
->
engine_
.
input
().
isKeyPressed
(
SDLK_ESCAPE
))
...
...
src/gameplay/game_input_manager.cpp
View file @
17705460
...
...
@@ -19,6 +19,8 @@
namespace
gdw
{
const
float
game_input_manager
::
maximum_movement_distance
=
13.0
f
;
game_input_manager
::
game_input_manager
(
engine
&
engine
)
:
engine_
(
engine
)
{
}
...
...
@@ -40,7 +42,6 @@ namespace gdw {
if
(
!
move
)
return
;
auto
&
input
=
engine_
.
input
();
constexpr
float
maximum_movement_distance
=
13.
f
;
constexpr
float
rotation_speed
=
7.
f
;
constexpr
float
turn_rate_modifier
=
4.5
f
;
...
...
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