Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
GameDevWeek
S
Sommersemester 2019
Cpp
PhaseShifter
Commits
a1a9b8d8
Commit
a1a9b8d8
authored
Sep 21, 2019
by
Kevin Balz
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop' into feature/36-level-design
parents
0502b5ca
ed512969
Pipeline
#3432
passed with stage
in 3 minutes and 47 seconds
Changes
13
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
86 additions
and
28 deletions
+86
-28
assets/game_assets/blueprints/camera.json
assets/game_assets/blueprints/camera.json
+2
-1
src/gameplay/beat_system.cpp
src/gameplay/beat_system.cpp
+1
-0
src/gameplay/camera_system.cpp
src/gameplay/camera_system.cpp
+22
-5
src/gameplay/camera_system.hpp
src/gameplay/camera_system.hpp
+6
-1
src/gameplay/dash_system.cpp
src/gameplay/dash_system.cpp
+1
-0
src/gameplay/enemy_system.cpp
src/gameplay/enemy_system.cpp
+1
-0
src/gameplay/enemy_system.hpp
src/gameplay/enemy_system.hpp
+2
-0
src/gameplay/shake_comp.hpp
src/gameplay/shake_comp.hpp
+16
-0
src/gameplay/spring_comp.hpp
src/gameplay/spring_comp.hpp
+1
-0
src/level/level_system.cpp
src/level/level_system.cpp
+5
-0
src/messages.hpp
src/messages.hpp
+5
-0
src/meta_system.cpp
src/meta_system.cpp
+1
-1
src/ui/hud_system.cpp
src/ui/hud_system.cpp
+23
-20
No files found.
assets/game_assets/blueprints/camera.json
View file @
a1a9b8d8
...
...
@@ -18,5 +18,6 @@
"Spring"
:
{
"spring_constant"
:
20.0
,
"mass"
:
1.0
}
},
"Shake"
:
{}
}
src/gameplay/beat_system.cpp
View file @
a1a9b8d8
...
...
@@ -42,6 +42,7 @@ namespace phase_shifter::gameplay {
if
(
beat
)
{
_beat_index
++
;
LOG
(
plog
::
debug
)
<<
"beat"
;
_bus
.
send
<
Screen_shake_msg
>
(
0.03
f
,
0.05
f
);
beats_left
=
size
-
1
-
_beat_index
+
_beat_offset
;
if
(
beats_left
<=
0
||
_beat_index
+
1
>=
size
)
{
...
...
src/gameplay/camera_system.cpp
View file @
a1a9b8d8
...
...
@@ -6,17 +6,28 @@ namespace phase_shifter::gameplay {
using
mirrage
::
ecs
::
components
::
Transform_comp
;
Camera_system
::
Camera_system
(
mirrage
::
ecs
::
Entity_manager
&
entity_manager
)
:
_entity_manager
(
entity_manager
)
Camera_system
::
Camera_system
(
mirrage
::
util
::
Message_bus
&
bus
,
mirrage
::
ecs
::
Entity_manager
&
entity_manager
)
:
_entity_manager
(
entity_manager
)
,
_mailbox
(
bus
)
{
_entity_manager
.
register_component_type
<
Viewtarget_comp
>
();
_entity_manager
.
register_component_type
<
Spring_comp
>
();
_entity_manager
.
register_component_type
<
Shake_comp
>
();
_mailbox
.
subscribe_to
([
&
](
Screen_shake_msg
&
e
)
{
for
(
auto
&
shake
:
_entity_manager
.
list
<
Shake_comp
>
())
{
shake
.
intesity
=
e
.
intensity
;
shake
.
duration
=
e
.
duration
;
shake
.
time_remaining
=
e
.
duration
;
}
});
}
void
Camera_system
::
update
(
mirrage
::
util
::
Time
dt
)
{
for
(
auto
&&
[
transform
,
viewtarget
,
spring
]
:
_entity_manager
.
list
<
Transform_comp
,
Viewtarget_comp
,
Spring_comp
>
())
{
_mailbox
.
update_subscriptions
();
for
(
auto
&&
[
transform
,
viewtarget
,
spring
,
shake
]
:
_entity_manager
.
list
<
Transform_comp
,
Viewtarget_comp
,
Spring_comp
,
Shake_comp
>
())
{
auto
target_facet
=
_entity_manager
.
get
(
viewtarget
.
target
);
if
(
target_facet
.
is_some
())
{
...
...
@@ -35,7 +46,13 @@ namespace phase_shifter::gameplay {
glm
::
vec3
spring_force
=
spring
.
spring_constant
*
(
dest_pos
-
transform
.
position
);
glm
::
vec3
acceleration
=
(
spring_force
+
damping_force
)
/
spring
.
mass
;
spring
.
velocity
+=
dt
.
value
()
*
acceleration
;
transform
.
position
+=
dt
.
value
()
*
spring
.
velocity
;
spring
.
position
+=
dt
.
value
()
*
spring
.
velocity
;
transform
.
position
=
spring
.
position
;
if
(
shake
.
time_remaining
>
0
)
{
glm
::
vec3
shake_direction
=
glm
::
normalize
(
glm
::
vec3
{
std
::
rand
(),
0
,
std
::
rand
()});
transform
.
position
+=
shake
.
intesity
*
(
shake
.
time_remaining
/
shake
.
duration
)
*
shake_direction
;
shake
.
time_remaining
-=
dt
.
value
();
}
transform
.
direction
(
-
offset
);
}
}
...
...
src/gameplay/camera_system.hpp
View file @
a1a9b8d8
...
...
@@ -2,18 +2,23 @@
#include <mirrage/utils/units.hpp>
#include <mirrage/ecs/entity_manager.hpp>
#include <mirrage/utils/messagebus.hpp>
#include "../messages.hpp"
#include "viewtarget_comp.hpp"
#include "spring_comp.hpp"
#include "shake_comp.hpp"
namespace
phase_shifter
::
gameplay
{
class
Camera_system
{
public:
Camera_system
(
mirrage
::
ecs
::
Entity_manager
&
entity_manager
);
Camera_system
(
mirrage
::
util
::
Message_bus
&
bus
,
mirrage
::
ecs
::
Entity_manager
&
entity_manager
);
void
update
(
mirrage
::
util
::
Time
dt
);
private:
mirrage
::
ecs
::
Entity_manager
&
_entity_manager
;
mirrage
::
util
::
Mailbox_collection
_mailbox
;
};
}
\ No newline at end of file
src/gameplay/dash_system.cpp
View file @
a1a9b8d8
...
...
@@ -115,6 +115,7 @@ namespace phase_shifter::gameplay {
_bus
.
send
<
Enemy_killed_msg
>
(
k_transform
.
position
,
glm
::
vec3
(
attack_direction
.
x
,
0.
f
,
attack_direction
.
y
));
_bus
.
send
<
Screen_shake_msg
>
(
0.5
f
,
0.3
f
);
_ecs
.
erase
(
entity
);
}
}
...
...
src/gameplay/enemy_system.cpp
View file @
a1a9b8d8
...
...
@@ -238,6 +238,7 @@ namespace phase_shifter::gameplay {
Stadium
{
last_player_pos
,
player_pos
,
player_body
.
radius
}))
{
_entity_manager
.
erase
(
bullet_handle
);
_bus
.
send
<
Damaged_msg
>
(
player_handle
);
_bus
.
send
<
Screen_shake_msg
>
(
0.3
f
,
0.3
f
);
}
}
}
...
...
src/gameplay/enemy_system.hpp
View file @
a1a9b8d8
...
...
@@ -12,6 +12,8 @@
#include "beat_system.hpp"
#include "../messages.hpp"
namespace
phase_shifter
::
gameplay
{
struct
Stadium
{
...
...
src/gameplay/shake_comp.hpp
0 → 100644
View file @
a1a9b8d8
#pragma once
#include <mirrage/ecs/ecs.hpp>
#include <mirrage/utils/sf2_glm.hpp>
namespace
phase_shifter
::
gameplay
{
struct
Shake_comp
:
public
mirrage
::
ecs
::
Component
<
Shake_comp
>
{
static
constexpr
const
char
*
name
()
{
return
"Shake"
;
}
using
Component
::
Component
;
float
intesity
=
0
;
float
duration
=
0
;
//duration in seconds
float
time_remaining
=
0
;
//remaining shake time in seconds
};
}
// namespace phase_shifter::gameplay
src/gameplay/spring_comp.hpp
View file @
a1a9b8d8
...
...
@@ -12,6 +12,7 @@ namespace phase_shifter::gameplay {
float
spring_constant
=
1.
f
;
float
mass
=
1.
f
;
glm
::
vec3
position
=
{
0.
f
,
0.
f
,
0.
f
};
glm
::
vec3
velocity
=
{
0.
f
,
0.
f
,
0.
f
};
};
...
...
src/level/level_system.cpp
View file @
a1a9b8d8
...
...
@@ -6,6 +6,7 @@
#include "../gameplay/player_comp.hpp"
#include "../gameplay/rigid_body_comp.hpp"
#include "../gameplay/viewtarget_comp.hpp"
#include "../gameplay/spring_comp.hpp"
#include "../helper/attachment_comp.hpp"
#include <mirrage/ecs/components/transform_comp.hpp>
...
...
@@ -84,6 +85,10 @@ namespace phase_shifter::level {
entity
.
process
([
=
](
gameplay
::
Viewtarget_comp
&
viewtarget
)
{
viewtarget
.
target
=
playerhandle
;
});
entity
.
process
(
[
=
](
gameplay
::
Spring_comp
&
spring
,
Transform_comp
&
transform
)
{
spring
.
position
=
transform
.
position
;
});
})
.
create
();
...
...
src/messages.hpp
View file @
a1a9b8d8
...
...
@@ -29,4 +29,9 @@ namespace phase_shifter {
mirrage
::
util
::
Str_id
id
;
};
struct
Screen_shake_msg
{
float
intensity
;
float
duration
;
//duration in seconds
};
}
// namespace phase_shifter
src/meta_system.cpp
View file @
a1a9b8d8
...
...
@@ -43,7 +43,7 @@ namespace phase_shifter {
,
_combat_system
(
std
::
make_unique
<
gameplay
::
Combat_system
>
(
engine
.
bus
(),
_entities
,
*
_beat_system
))
,
_attachment_system
(
std
::
make_unique
<
helper
::
Attachment_system
>
(
_entities
))
,
_hud_system
(
std
::
make_unique
<
ui
::
Hud_system
>
(
engine
.
gui
(),
_entities
,
*
_beat_system
))
,
_camera_system
(
std
::
make_unique
<
gameplay
::
Camera_system
>
(
_entities
))
,
_camera_system
(
std
::
make_unique
<
gameplay
::
Camera_system
>
(
engine
.
bus
(),
_entities
))
,
_enemy_system
(
std
::
make_unique
<
gameplay
::
Enemy_system
>
(
engine
.
bus
(),
_entities
,
*
_beat_system
))
,
_dash_system
(
std
::
make_unique
<
gameplay
::
Dash_system
>
(
engine
.
bus
(),
_entities
))
,
_stationary_attack_system
(
...
...
src/ui/hud_system.cpp
View file @
a1a9b8d8
...
...
@@ -13,7 +13,7 @@ namespace phase_shifter::ui {
using
namespace
mirrage
::
gui
::
literals
;
namespace
{
constexpr
auto
hud_height
=
1
0
0
;
constexpr
auto
hud_height
=
1
3
0
;
constexpr
auto
bar_height
=
80
;
constexpr
auto
beat_bar_height
=
79
;
constexpr
auto
bar_speed
=
100
;
...
...
@@ -38,35 +38,24 @@ namespace phase_shifter::ui {
if
(
font
.
is_some
())
ImGui
::
PushFont
(
font
.
get_or_throw
());
ImGui
::
PositionNextWindow
(
glm
::
vec2
(
viewport
.
z
,
hud_height
),
ImGui
::
WindowPosition_X
::
left
,
ImGui
::
WindowPosition_Y
::
top
);
if
(
ImGui
::
Begin
(
"hud"
,
nullptr
,
ImGuiWindowFlags_NoTitleBar
|
ImGuiWindowFlags_NoMove
|
ImGuiWindowFlags_NoResize
|
ImGuiWindowFlags_NoBackground
|
ImGuiWindowFlags_NoInputs
))
{
ImGui
::
Text
(
"%i"
,
_beat_system
.
beat_state
().
beats_left
);
ImGui
::
End
();
}
ImGui
::
PushStyleColor
(
ImGuiCol_WindowBg
,
ImColor
(
0
,
0
,
0
,
180
).
Value
);
ImGui
::
PushStyleColor
(
ImGuiCol_Border
,
ImColor
(
0
,
0
,
0
,
0
).
Value
);
ImGui
::
PositionNextWindow
(
glm
::
vec2
(
viewport
.
z
,
hud_height
),
ImGui
::
WindowPosition_X
::
center
,
ImGui
::
WindowPosition_Y
::
bottom
);
if
(
ImGui
::
Begin
(
"beat"
,
nullptr
,
ImGuiWindowFlags_NoTitleBar
|
ImGuiWindowFlags_NoMove
|
ImGuiWindowFlags_NoResize
|
ImGuiWindowFlags_No
Background
|
ImGuiWindowFlags_No
Inputs
))
{
|
ImGuiWindowFlags_No
Inputs
|
ImGuiWindowFlags_No
Scrollbar
))
{
ImGui
::
PushStyleColor
(
ImGuiCol_Border
,
"#00000000"
_imcolor
.
Value
);
// Hide Border
ImVec2
cursor
=
ImGui
::
GetCursorScreenPos
();
cursor
.
y
+=
hud_height
/
2.
f
-
10
;
cursor
.
y
+=
hud_height
/
2.
f
+
10
;
auto
beat_state
=
_beat_system
.
beat_state
();
auto
beats
=
_beat_system
.
time_stamps
();
auto
beat_index
=
_beat_system
.
beat_index
()
+
1
;
//auto line_offset = bar_speed * beat_state.avg_beat_time;
//auto beats = std::clamp(beat_state.beats_left, 0, 5);
ImGui
::
BeginChild
(
"Line"
,
{
viewport
.
z
,
bar
_height
},
true
);
ImGui
::
BeginChild
(
"Line"
,
{
viewport
.
z
,
hud
_height
},
true
);
ImDrawList
*
drawList
=
ImGui
::
GetWindowDrawList
();
while
(
beat_index
<
static_cast
<
int
>
(
beats
.
size
()))
{
...
...
@@ -81,16 +70,27 @@ namespace phase_shifter::ui {
auto
bar_color
=
ImGui
::
ColorConvertFloat4ToU32
(
bar_color_float
);
ImVec2
p
(
cursor
.
x
+
viewport
.
z
/
2
-
x_offset
,
cursor
.
y
-
height
/
2.
f
);
drawList
->
AddLine
(
p
,
{
p
.
x
,
p
.
y
+
height
},
bar_color
,
1
);
drawList
->
AddLine
(
p
,
{
p
.
x
,
p
.
y
+
height
},
bar_color
,
2
);
p
.
x
=
cursor
.
x
+
viewport
.
z
/
2
+
x_offset
;
drawList
->
AddLine
(
p
,
{
p
.
x
,
p
.
y
+
height
},
bar_color
,
1
);
drawList
->
AddLine
(
p
,
{
p
.
x
,
p
.
y
+
height
},
bar_color
,
2
);
beat_index
++
;
}
ImVec2
middle
(
cursor
.
x
+
viewport
.
z
/
2
,
cursor
.
y
-
bar_height
/
2.
f
);
drawList
->
AddLine
(
middle
,
{
middle
.
x
,
middle
.
y
+
bar_height
},
0xFFFF0000
,
4
);
drawList
->
AddLine
(
middle
,
{
middle
.
x
,
middle
.
y
+
bar_height
},
0xFFFF0000
,
6
);
auto
beat_color
=
(
_beat_system
.
beat_state
().
beats_left
<
50
&&
_beat_system
.
beat_state
().
beats_left
%
2
==
0
)
?
ImColor
(
255
,
0
,
0
)
:
ImColor
(
255
,
255
,
255
);
auto
beats_left
=
std
::
to_string
(
_beat_system
.
beat_state
().
beats_left
);
auto
text_size
=
ImGui
::
CalcTextSize
(
beats_left
.
c_str
());
drawList
->
AddText
(
ImVec2
(
middle
.
x
-
text_size
.
x
/
2.
f
,
middle
.
y
-
text_size
.
y
-
10
),
beat_color
,
beats_left
.
c_str
());
ImGui
::
EndChild
();
ImGui
::
PopStyleColor
();
...
...
@@ -105,6 +105,9 @@ namespace phase_shifter::ui {
}
}
ImGui
::
PopStyleColor
();
ImGui
::
PopStyleColor
();
if
(
font
.
is_some
())
ImGui
::
PopFont
();
}
...
...
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