Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Pokeprofs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
william.ho
Pokeprofs
Commits
57a0acf9
Commit
57a0acf9
authored
1 year ago
by
william.ho
Browse files
Options
Downloads
Patches
Plain Diff
splash.rs fonctionne sa mère
parent
03453a0e
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
game/src/main.rs
+2
-74
2 additions, 74 deletions
game/src/main.rs
game/src/splash.rs
+69
-0
69 additions, 0 deletions
game/src/splash.rs
with
71 additions
and
74 deletions
game/src/main.rs
+
2
−
74
View file @
57a0acf9
...
@@ -8,6 +8,8 @@ use bevy::{
...
@@ -8,6 +8,8 @@ use bevy::{
const
TEXT_COLOR
:
Color
=
Color
::
rgb
(
0.9
,
0.9
,
0.9
);
const
TEXT_COLOR
:
Color
=
Color
::
rgb
(
0.9
,
0.9
,
0.9
);
mod
splash
;
// Enum that will be used as a global state for the game
// Enum that will be used as a global state for the game
#[derive(Clone,
Copy,
Default,
Eq,
PartialEq,
Debug,
Hash,
States)]
#[derive(Clone,
Copy,
Default,
Eq,
PartialEq,
Debug,
Hash,
States)]
enum
GameState
{
enum
GameState
{
...
@@ -53,80 +55,6 @@ fn setup(mut commands: Commands) {
...
@@ -53,80 +55,6 @@ fn setup(mut commands: Commands) {
commands
.spawn
(
Camera2dBundle
::
default
());
commands
.spawn
(
Camera2dBundle
::
default
());
}
}
mod
splash
{
use
bevy
::
prelude
::
*
;
use
super
::{
despawn_screen
,
GameState
};
// This plugin will display a splash screen with Bevy logo for 1 second before switching to the menu
pub
struct
SplashPlugin
;
impl
Plugin
for
SplashPlugin
{
fn
build
(
&
self
,
app
:
&
mut
App
)
{
// As this plugin is managing the splash screen, it will focus on the state `GameState::Splash`
app
// When entering the state, spawn everything needed for this screen
.add_systems
(
OnEnter
(
GameState
::
Splash
),
splash_setup
)
// While in this state, run the `countdown` system
.add_systems
(
Update
,
countdown
.run_if
(
in_state
(
GameState
::
Splash
)))
// When exiting the state, despawn everything that was spawned for this screen
.add_systems
(
OnExit
(
GameState
::
Splash
),
despawn_screen
::
<
OnSplashScreen
>
);
}
}
// Tag component used to tag entities added on the splash screen
#[derive(Component)]
struct
OnSplashScreen
;
// Newtype to use a `Timer` for this screen as a resource
#[derive(Resource,
Deref,
DerefMut)]
struct
SplashTimer
(
Timer
);
fn
splash_setup
(
mut
commands
:
Commands
,
asset_server
:
Res
<
AssetServer
>
)
{
let
icon
=
asset_server
.load
(
"pokeball.png"
);
// Display the logo
commands
.spawn
((
NodeBundle
{
style
:
Style
{
align_items
:
AlignItems
::
Center
,
justify_content
:
JustifyContent
::
Center
,
width
:
Val
::
Percent
(
100.0
),
..
default
()
},
..
default
()
},
OnSplashScreen
,
))
.with_children
(|
parent
|
{
parent
.spawn
(
ImageBundle
{
style
:
Style
{
// This will set the logo to be 200px wide, and auto adjust its height
width
:
Val
::
Px
(
200.0
),
..
default
()
},
image
:
UiImage
::
new
(
icon
),
..
default
()
});
});
// Insert the timer as a resource
commands
.insert_resource
(
SplashTimer
(
Timer
::
from_seconds
(
1.0
,
TimerMode
::
Once
)));
}
// Tick the timer, and change state when finished
fn
countdown
(
mut
game_state
:
ResMut
<
NextState
<
GameState
>>
,
time
:
Res
<
Time
>
,
mut
timer
:
ResMut
<
SplashTimer
>
,
)
{
if
timer
.tick
(
time
.delta
())
.finished
()
{
game_state
.set
(
GameState
::
Menu
);
}
}
}
mod
game
{
mod
game
{
use
bevy
::
prelude
::
*
;
use
bevy
::
prelude
::
*
;
...
...
This diff is collapsed.
Click to expand it.
game/src/splash.rs
0 → 100644
+
69
−
0
View file @
57a0acf9
use
bevy
::
prelude
::
*
;
use
super
::{
despawn_screen
,
GameState
};
// This plugin will display a splash screen with Bevy logo for 1 second before switching to the menu
pub
struct
SplashPlugin
;
impl
Plugin
for
SplashPlugin
{
fn
build
(
&
self
,
app
:
&
mut
App
)
{
// As this plugin is managing the splash screen, it will focus on the state `GameState::Splash`
app
// When entering the state, spawn everything needed for this screen
.add_systems
(
OnEnter
(
GameState
::
Splash
),
splash_setup
)
// While in this state, run the `countdown` system
.add_systems
(
Update
,
countdown
.run_if
(
in_state
(
GameState
::
Splash
)))
// When exiting the state, despawn everything that was spawned for this screen
.add_systems
(
OnExit
(
GameState
::
Splash
),
despawn_screen
::
<
OnSplashScreen
>
);
}
}
// Tag component used to tag entities added on the splash screen
#[derive(Component)]
struct
OnSplashScreen
;
// Newtype to use a `Timer` for this screen as a resource
#[derive(Resource,
Deref,
DerefMut)]
struct
SplashTimer
(
Timer
);
fn
splash_setup
(
mut
commands
:
Commands
,
asset_server
:
Res
<
AssetServer
>
)
{
let
icon
=
asset_server
.load
(
"pokeball.png"
);
// Display the logo
commands
.spawn
((
NodeBundle
{
style
:
Style
{
align_items
:
AlignItems
::
Center
,
justify_content
:
JustifyContent
::
Center
,
width
:
Val
::
Percent
(
100.0
),
..
default
()
},
..
default
()
},
OnSplashScreen
,
))
.with_children
(|
parent
|
{
parent
.spawn
(
ImageBundle
{
style
:
Style
{
// This will set the logo to be 200px wide, and auto adjust its height
width
:
Val
::
Px
(
200.0
),
..
default
()
},
image
:
UiImage
::
new
(
icon
),
..
default
()
});
});
// Insert the timer as a resource
commands
.insert_resource
(
SplashTimer
(
Timer
::
from_seconds
(
1.0
,
TimerMode
::
Once
)));
}
// Tick the timer, and change state when finished
fn
countdown
(
mut
game_state
:
ResMut
<
NextState
<
GameState
>>
,
time
:
Res
<
Time
>
,
mut
timer
:
ResMut
<
SplashTimer
>
,
)
{
if
timer
.tick
(
time
.delta
())
.finished
()
{
game_state
.set
(
GameState
::
Menu
);
}
}
\ No newline at end of file
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