Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Engel Simulator 2020
Engel Simulator 2020
Commits
c52f3ff6
Commit
c52f3ff6
authored
Dec 29, 2020
by
Rahix
🦀
Browse files
Merge 'Proper Game Over State'
See merge request
!45
parents
aa57da0c
66ecefe3
Changes
11
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/angel_shifts/bottle_angel.rs
View file @
c52f3ff6
...
...
@@ -142,6 +142,6 @@ pub fn update_bottle_shift(
.unwrap
();
player
.collected_hours
+=
*
hours_to_award
as
u32
;
*
hours_to_award
=
0
;
game_manager
.request_return_to_heaven
(
false
);
game_manager
.request_return_to_heaven
();
}
}
src/angel_shifts/network_switch.rs
View file @
c52f3ff6
...
...
@@ -139,6 +139,6 @@ pub fn update_network_switch_shift(
.unwrap
();
player
.collected_hours
+=
*
hours_to_award
as
u32
;
*
hours_to_award
=
0
;
game_manager
.request_return_to_heaven
(
false
);
game_manager
.request_return_to_heaven
();
}
}
src/components/player.rs
View file @
c52f3ff6
...
...
@@ -11,9 +11,4 @@ impl Player {
collected_hours
:
0
,
}
}
pub
fn
reset
(
&
mut
self
)
{
self
.sanity
=
1.0
;
self
.collected_hours
=
0
;
}
}
src/resources/game_manager.rs
View file @
c52f3ff6
...
...
@@ -13,12 +13,19 @@ impl GameManager {
}
}
pub
fn
request_return_to_heaven
(
&
mut
self
,
game_over
:
bool
)
{
self
.game_over
=
game_over
;
pub
fn
request_return_to_heaven
(
&
mut
self
)
{
self
.return_timeout
.get_or_insert
(
0.0
);
}
pub
fn
request_game_over
(
&
mut
self
)
{
self
.game_over
=
true
;
}
pub
fn
wants_return_to_heaven
(
&
self
)
->
bool
{
self
.return_timeout
.map_or
(
false
,
|
t
|
t
>=
3.0
)
}
pub
fn
wants_game_over
(
&
self
)
->
bool
{
self
.game_over
}
}
src/states/game_over.rs
0 → 100644
View file @
c52f3ff6
use
crate
::
gamestate
;
use
crate
::
states
;
use
crate
::
utils
;
pub
struct
GameOverState
{
gui_svg
:
web_sys
::
SvgElement
,
}
impl
GameOverState
{
pub
fn
new
()
->
GameOverState
{
GameOverState
{
gui_svg
:
utils
::
get_element_by_id
(
"game-over-ui"
)
.unwrap
(),
}
}
}
impl
gamestate
::
State
for
GameOverState
{
fn
init
(
&
mut
self
,
mut
init
:
gamestate
::
StateInitializer
)
->
gamestate
::
Transition
{
init
.register_onclick
(
"game-over-replay"
);
init
.register_onclick
(
"game-over-quit"
);
self
.gui_svg
.style
()
.set_property
(
"display"
,
"block"
)
.unwrap
();
gamestate
::
Transition
::
Sleep
}
fn
deinit
(
&
mut
self
)
{
self
.gui_svg
.style
()
.set_property
(
"display"
,
"none"
)
.unwrap
();
}
fn
event
(
&
mut
self
,
event
:
gamestate
::
Event
)
->
gamestate
::
Transition
{
match
event
{
gamestate
::
Event
::
MouseClick
{
target
:
"game-over-replay"
,
..
}
=>
gamestate
::
Transition
::
push
(
states
::
HeavenState
::
new
(
None
)),
gamestate
::
Event
::
MouseClick
{
target
:
"game-over-quit"
,
..
}
=>
gamestate
::
Transition
::
Pop
,
event
=>
{
crate
::
console_warn!
(
"unknown event {:?}"
,
event
);
gamestate
::
Transition
::
Keep
}
}
}
}
src/states/heaven.rs
View file @
c52f3ff6
...
...
@@ -27,6 +27,9 @@ impl HeavenState {
});
// Update the angel stats GUI elements
utils
::
get_element_by_id
::
<
web_sys
::
Element
>
(
"heaven-sanity"
)
.unwrap
()
.set_inner_html
(
&
format!
(
"{}%"
,
(
player
.sanity
*
100.0
)
.round
()
as
usize
));
utils
::
get_element_by_id
::
<
web_sys
::
Element
>
(
"heaven-collected-hours"
)
.unwrap
()
.set_inner_html
(
&
format!
(
"{}"
,
player
.collected_hours
));
...
...
src/states/ingame.rs
View file @
c52f3ff6
...
...
@@ -166,13 +166,12 @@ impl gamestate::State for InGameState {
let
game_manager
=
self
.resources.get
::
<
resources
::
GameManager
>
()
.unwrap
();
if
game_manager
.wants_return_to_heaven
()
{
let
player_ent
=
self
.resources.get
::
<
resources
::
Player
>
()
.unwrap
()
.0
.clone
();
let
player
=
<&
mut
components
::
Player
>
::
query
()
.get
_mut
(
&
mut
self
.world
,
player_ent
)
let
player
=
<&
components
::
Player
>
::
query
()
.get
(
&
self
.world
,
player_ent
)
.unwrap
();
if
game_manager
.game_over
{
player
.reset
();
}
gamestate
::
Transition
::
replace
(
states
::
HeavenState
::
new
(
Some
(
player
.clone
())))
}
else
if
game_manager
.wants_game_over
()
{
gamestate
::
Transition
::
replace
(
states
::
GameOverState
::
new
())
}
else
{
gamestate
::
Transition
::
Loop
}
...
...
src/states/mod.rs
View file @
c52f3ff6
mod
game_over
;
mod
heaven
;
mod
ingame
;
mod
level_loading
;
mod
main_menu
;
pub
use
game_over
::
GameOverState
;
pub
use
heaven
::
HeavenState
;
pub
use
ingame
::
InGameState
;
pub
use
level_loading
::
LevelLoadingState
;
...
...
src/systems/player.rs
View file @
c52f3ff6
...
...
@@ -38,7 +38,6 @@ pub fn player_sanity_check(
let
player
=
players
.get_mut
(
world
,
player
.0
)
.unwrap
();
if
player
.sanity
<=
0.0
{
// TODO: Game Over Screen
game_manager
.request_return_to_heaven
(
true
);
game_manager
.request_game_over
();
}
}
www/src/index.html
View file @
c52f3ff6
...
...
@@ -60,10 +60,12 @@
<g
transform=
"translate(250, 800)"
>
<text
x=
"0"
y=
"-15"
class=
"group-box-label"
>
ANGEL STATS:
</text>
<text
x=
"30"
y=
"30"
class=
"stats-label"
>
Collected hours:
</text>
<text
x=
"450"
y=
"30"
class=
"stats-number positive"
id=
"heaven-collected-hours"
>
?
</text>
<text
x=
"30"
y=
"80"
class=
"stats-label"
>
Hours still needed:
</text>
<text
x=
"450"
y=
"80"
class=
"stats-number negative"
id=
"heaven-needed-hours"
>
?
</text>
<text
x=
"30"
y=
"30"
class=
"stats-label"
>
Sanity remaining:
</text>
<text
x=
"450"
y=
"30"
class=
"stats-number health"
id=
"heaven-sanity"
>
?
</text>
<text
x=
"30"
y=
"80"
class=
"stats-label"
>
Collected hours:
</text>
<text
x=
"450"
y=
"80"
class=
"stats-number positive"
id=
"heaven-collected-hours"
>
?
</text>
<text
x=
"30"
y=
"130"
class=
"stats-label"
>
Hours still needed:
</text>
<text
x=
"450"
y=
"130"
class=
"stats-number negative"
id=
"heaven-needed-hours"
>
?
</text>
</g>
<g
transform=
"translate(1100, 300)"
>
...
...
@@ -89,6 +91,21 @@
<text
x=
"0"
y=
"0"
>
START SHIFT
</text>
</g>
</svg>
<svg
id=
"game-over-ui"
class=
"game-gui"
viewBox=
"0 0 1920 1080"
style=
"display: none"
>
<!-- GUI for the Game Over screen -->
<rect
x=
"0"
y=
"0"
width=
"1920"
height=
"1080"
class=
"background"
/>
<text
x=
"960"
y=
"300"
class=
"header"
>
Game Over
</text>
<g
id=
"game-over-replay"
transform=
"translate(960, 500)"
class=
"big-button button-1"
>
<rect
x=
"-350"
y=
"-60"
width=
"700"
height=
"120"
/>
<text
x=
"0"
y=
"0"
>
Start New Game
</text>
</g>
<g
id=
"game-over-quit"
transform=
"translate(960, 650)"
class=
"big-button button-3"
>
<rect
x=
"-120"
y=
"-60"
width=
"240"
height=
"120"
/>
<text
x=
"0"
y=
"0"
>
Quit
</text>
</g>
</svg>
<svg
id=
"menu-ui"
class=
"game-gui"
viewBox=
"0 0 1920 1080"
style=
"display: block"
>
<!-- GUI for the main menu -->
<rect
x=
"0"
y=
"0"
width=
"1920"
height=
"1080"
class=
"background"
/>
...
...
www/src/styles.scss
View file @
c52f3ff6
...
...
@@ -130,6 +130,10 @@ div.game {
fill
:
#ffffff
;
&
.health
{
fill
:
$typography-1
;
}
&
.positive
{
fill
:
$typography-2
;
}
...
...
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