Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
shoot-the-revival
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
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
shoot-the-revival
Commits
d7df3eba
Verified
Commit
d7df3eba
authored
1 year ago
by
Louis
Browse files
Options
Downloads
Patches
Plain Diff
Render moving background
parent
f66ac5d6
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/entities/spawning.rs
+20
-5
20 additions, 5 deletions
src/entities/spawning.rs
src/system/mod.rs
+4
-1
4 additions, 1 deletion
src/system/mod.rs
src/system/parallax.rs
+19
-0
19 additions, 0 deletions
src/system/parallax.rs
with
43 additions
and
6 deletions
src/entities/spawning.rs
+
20
−
5
View file @
d7df3eba
use
crate
::
entities
::
motion
::
Velocity
;
use
crate
::
entities
::
Player
;
use
crate
::
system
::
Background
;
use
bevy
::
ecs
::
system
::
SystemParam
;
use
bevy
::
prelude
::{
AssetServer
,
Commands
,
Entity
,
Res
,
SpriteBundle
,
Transform
,
Vec2
};
static
Z_PLAYER
:
f32
=
300.0
;
static
Z_ITEMS
:
f32
=
200.0
;
static
Z_ENEMY
:
f32
=
250.0
;
static
Z_BACKGROUND
:
f32
=
50.0
;
#[derive(SystemParam)]
pub
struct
EntitySpawner
<
'w
,
's
>
{
commands
:
Commands
<
'w
,
's
>
,
assets
:
Res
<
'w
,
AssetServer
>
,
}
static
Z_PLAYER
:
f32
=
300.0
;
static
Z_ITEMS
:
f32
=
200.0
;
static
Z_ENEMY
:
f32
=
250.0
;
static
Z_BACKGROUND
:
f32
=
50.0
;
impl
<
'w
,
's
>
EntitySpawner
<
'w
,
's
>
{
pub
fn
spawn_player_at
(
&
mut
self
,
position
:
Vec2
)
->
Entity
{
self
.commands
...
...
@@ -28,4 +29,18 @@ impl<'w, 's> EntitySpawner<'w, 's> {
))
.id
()
}
pub
fn
spawn_background_at
(
&
mut
self
,
position
:
Vec2
)
->
Entity
{
self
.commands
.spawn
((
SpriteBundle
{
texture
:
self
.assets
.load
(
"sprites/background.png"
),
transform
:
Transform
::
from_translation
(
position
.extend
(
Z_BACKGROUND
)),
..
Default
::
default
()
},
Velocity
::
from
(
Vec2
::
new
(
-
75.0
,
0.0
)),
Background
,
))
.id
()
}
}
This diff is collapsed.
Click to expand it.
src/system/mod.rs
+
4
−
1
View file @
d7df3eba
mod
camera
;
mod
parallax
;
mod
window
;
mod
_plugin
{
...
...
@@ -8,12 +9,14 @@ mod _plugin {
pub
struct
SystemPlugin
;
impl
Plugin
for
SystemPlugin
{
fn
build
(
&
self
,
app
:
&
mut
App
)
{
app
.add_startup_system
(
super
::
camera
::
spawn_2d_camera
);
app
.add_startup_system
(
super
::
camera
::
spawn_2d_camera
)
.add_startup_system
(
super
::
parallax
::
spawn_backgrounds
);
}
}
}
pub
use
camera
::
default_projection
;
pub
use
parallax
::
Background
;
pub
use
window
::{
window_bounds
,
VIEWPORT_HEIGHT
,
VIEWPORT_WIDTH
};
pub
use
_plugin
::
SystemPlugin
;
This diff is collapsed.
Click to expand it.
src/system/parallax.rs
0 → 100644
+
19
−
0
View file @
d7df3eba
use
crate
::
entities
::
EntitySpawner
;
use
crate
::
system
::
window_bounds
;
use
bevy
::
prelude
::{
Component
,
Vec2
};
#[derive(Component)]
pub
struct
Background
;
// TODO: No Magic Numbers!
const
BACKGROUND_WIDTH
:
f32
=
2110.0
;
pub
fn
spawn_backgrounds
(
mut
spawner
:
EntitySpawner
)
{
let
bounds
=
window_bounds
();
spawner
.spawn_background_at
(
Vec2
::
new
(
BACKGROUND_WIDTH
/
2.0
,
bounds
.height
()
/
2.0
));
spawner
.spawn_background_at
(
Vec2
::
new
(
(
BACKGROUND_WIDTH
/
2.0
)
+
BACKGROUND_WIDTH
,
bounds
.height
()
/
2.0
,
));
}
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