Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Trader Tales
Manage
Activity
Members
Labels
Plan
Issues
1
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Microhacks
Trader Tales
Commits
419ff09b
Verified
Commit
419ff09b
authored
2 years ago
by
Louis
Browse files
Options
Downloads
Patches
Plain Diff
Show Death Message
parent
faae6cc8
No related branches found
No related tags found
No related merge requests found
Pipeline
#263
passed with stages
in 2 minutes and 38 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
game_core/src/world/hunger.rs
+95
-6
95 additions, 6 deletions
game_core/src/world/hunger.rs
game_core/src/world/mod.rs
+3
-0
3 additions, 0 deletions
game_core/src/world/mod.rs
with
98 additions
and
6 deletions
game_core/src/world/hunger.rs
+
95
−
6
View file @
419ff09b
use
std
::
collections
::
HashMap
;
use
bevy
::
prelude
::{
Commands
,
Component
,
Entity
,
EventReader
,
Mut
,
Query
,
Res
,
With
,
Without
};
use
bevy
::
prelude
::{
BuildChildren
,
Color
,
Commands
,
Component
,
DespawnRecursiveExt
,
Entity
,
EventReader
,
EventWriter
,
Mut
,
NodeBundle
,
Query
,
Res
,
TextBundle
,
Transform
,
TransformBundle
,
Val
,
VisibilityBundle
,
With
,
Without
,
};
use
bevy
::
text
::{
Text
,
TextStyle
};
use
bevy
::
ui
::{
AlignItems
,
FlexDirection
,
JustifyContent
,
Style
,
UiRect
};
use
serde
::{
Deserialize
,
Serialize
};
use
crate
::
assets
::
AssetHandles
;
use
crate
::
const_data
::
get_goods_from_name_checked
;
use
crate
::
states
::
Player
;
use
crate
::
system
::
camera
::
ChaseCam
;
use
crate
::
system
::
utilities
::
format_ui_distance
;
use
crate
::
world
::
spawning
::
apply_skull_marker
;
use
crate
::
world
::
travel
::
WorldTickEvent
;
use
crate
::
world
::{
TownName
,
TradeGood
,
TradingState
};
use
crate
::
world
::{
DistanceTravelled
,
TownName
,
TradeGood
,
TradingState
,
WorldLinked
};
#[derive(Clone,
Debug,
Default,
Serialize,
Deserialize,
Component)]
pub
struct
HungerState
{
...
...
@@ -148,19 +156,100 @@ fn process_hunger_state<'a>(
}
#[derive(Default)]
pub
struct
PlayerStarvedEvent
;
pub
struct
PlayerStarvedEvent
{
distance_travelled
:
f32
,
}
pub
fn
handle_entity_starvation
(
mut
commands
:
Commands
,
assets
:
Res
<
AssetHandles
>
,
food_query
:
Query
<
(
Entity
,
&
HungerState
),
Without
<
StarvationMarker
>>
,
player_query
:
Query
<
(),
With
<
Player
>>
,
player_query
:
Query
<
(
&
Transform
,
&
DistanceTravelled
),
With
<
Player
>>
,
town_query
:
Query
<&
TownName
>
,
mut
player_events
:
EventWriter
<
PlayerStarvedEvent
>
,
)
{
for
(
entity
,
hunger
)
in
&
food_query
{
if
hunger
.sustenance
==
0
{
apply_skull_marker
(
&
mut
commands
,
&
assets
,
entity
);
commands
.entity
(
entity
)
.insert
(
StarvationMarker
);
if
town_query
.contains
(
entity
)
{
apply_skull_marker
(
&
mut
commands
,
&
assets
,
entity
);
commands
.entity
(
entity
)
.insert
(
StarvationMarker
);
}
else
if
let
Ok
((
transform
,
distance_travelled
))
=
player_query
.get
(
entity
)
{
commands
.entity
(
entity
)
.despawn_recursive
();
let
new_entity
=
commands
.spawn
((
TransformBundle
::
from
(
*
transform
),
VisibilityBundle
::
default
(),
ChaseCam
,
WorldLinked
,
))
.id
();
apply_skull_marker
(
&
mut
commands
,
&
assets
,
new_entity
);
player_events
.send
(
PlayerStarvedEvent
{
distance_travelled
:
distance_travelled
.0
,
})
}
}
}
}
pub
fn
handle_player_starved
(
mut
commands
:
Commands
,
assets
:
Res
<
AssetHandles
>
,
mut
events
:
EventReader
<
PlayerStarvedEvent
>
,
)
{
for
event
in
events
.iter
()
{
commands
.spawn
((
NodeBundle
{
style
:
Style
{
margin
:
UiRect
::
all
(
Val
::
Auto
),
flex_direction
:
FlexDirection
::
Column
,
align_items
:
AlignItems
::
Center
,
justify_content
:
JustifyContent
::
Center
,
..
Default
::
default
()
},
..
Default
::
default
()
},
WorldLinked
,
))
.with_children
(|
builder
|
{
builder
.spawn
(
TextBundle
{
text
:
Text
::
from_section
(
"You Have Perished"
,
TextStyle
{
font_size
:
64.0
,
color
:
Color
::
ANTIQUE_WHITE
,
font
:
assets
.font
(
"compass_pro"
),
},
),
..
Default
::
default
()
});
builder
.spawn
(
TextBundle
{
text
:
Text
::
from_section
(
format!
(
"You made it: {}"
,
format_ui_distance
(
event
.distance_travelled
)
),
TextStyle
{
font_size
:
48.0
,
color
:
Color
::
ANTIQUE_WHITE
,
font
:
assets
.font
(
"equipment_pro"
),
},
),
..
Default
::
default
()
});
builder
.spawn
(
TextBundle
{
text
:
Text
::
from_section
(
"Press Escape To Return To Menu"
,
TextStyle
{
font_size
:
32.0
,
color
:
Color
::
ANTIQUE_WHITE
,
font
:
assets
.font
(
"equipment_pro"
),
},
),
..
Default
::
default
()
});
});
}
}
This diff is collapsed.
Click to expand it.
game_core/src/world/mod.rs
+
3
−
0
View file @
419ff09b
...
...
@@ -33,6 +33,7 @@ pub use utils::{grid_to_px, px_to_grid, ActiveLevel, WorldLinked};
pub
use
world_query
::{
CameraBounds
,
MapQuery
};
use
crate
::
system
::
flow
::
AppState
;
use
crate
::
world
::
hunger
::
PlayerStarvedEvent
;
use
crate
::
world
::
spawning
::
PopulateWorldEvent
;
use
crate
::
world
::
travel
::
WorldTickEvent
;
...
...
@@ -49,6 +50,7 @@ impl Plugin for WorldPlugin {
.init_resource
::
<
EncounterState
>
()
.add_event
::
<
PopulateWorldEvent
>
()
.add_event
::
<
WorldTickEvent
>
()
.add_event
::
<
PlayerStarvedEvent
>
()
.add_event
::
<
SelectEncounterOptionEvent
>
()
.add_enter_system
(
AppState
::
InGame
,
|
mut
commands
:
Commands
|
{
commands
.insert_resource
(
ActiveLevel
{
...
...
@@ -96,6 +98,7 @@ impl Plugin for WorldPlugin {
.with_system
(
encounters
::
notify_new_zone
)
.with_system
(
hunger
::
handle_entity_starvation
)
.with_system
(
encounters
::
handle_encounter_option_event
)
.with_system
(
hunger
::
handle_player_starved
)
.with_system
(|
mut
events
:
ResMut
<
Events
<
WorldTickEvent
>>
|
{
events
.clear
();
})
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment