-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move planet and star setup to own modules
- Loading branch information
Showing
7 changed files
with
175 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,48 @@ | ||
use bevy::prelude::*; | ||
|
||
use crate::{ | ||
effects::animate::{AnimationBundle, AnimationIndices, AnimationTimer}, | ||
hud::indicator::Indicated, | ||
}; | ||
|
||
use super::orbit::{Orbit, Orbitable}; | ||
|
||
const PLANET_ANIMATION_INDICES: AnimationIndices = AnimationIndices { | ||
first: 0, | ||
last: 124, | ||
}; | ||
|
||
#[derive(Component, Clone, Debug)] | ||
pub struct Planet {} | ||
pub struct Planet; | ||
|
||
#[derive(Bundle)] | ||
pub struct PlanetBundle { | ||
pub name: Name, | ||
pub marker: Planet, | ||
pub indicated: Indicated, | ||
pub orbitable: Orbitable, | ||
pub orbit: Orbit, | ||
pub animation_bundle: AnimationBundle, | ||
pub sprite_sheet_bundle: SpriteSheetBundle, | ||
} | ||
impl Default for PlanetBundle { | ||
fn default() -> Self { | ||
Self { | ||
name: Name::new("Planet"), | ||
marker: Planet, | ||
indicated: Indicated { | ||
color: Color::ORANGE_RED, | ||
}, | ||
orbitable: Orbitable::default(), | ||
orbit: Orbit { | ||
parent: None, | ||
semi_major_axis: 0., | ||
}, | ||
animation_bundle: AnimationBundle { | ||
indices: PLANET_ANIMATION_INDICES, | ||
timer: AnimationTimer(Timer::from_seconds(0.1, TimerMode::Repeating)), | ||
}, | ||
sprite_sheet_bundle: SpriteSheetBundle::default(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,57 @@ | ||
use bevy::prelude::*; | ||
|
||
use crate::{ | ||
effects::animate::{AnimationBundle, AnimationIndices, AnimationTimer}, | ||
hud::indicator::Indicated, | ||
resources::assets::SpriteAssets, | ||
}; | ||
|
||
use super::orbit::Orbitable; | ||
|
||
const STAR_ANIMATION_INDICES: AnimationIndices = AnimationIndices { | ||
first: 0, | ||
last: 124, | ||
}; | ||
|
||
#[derive(Component, Clone, Debug)] | ||
pub struct Star {} | ||
pub struct Star; | ||
|
||
#[derive(Bundle)] | ||
pub struct StarBundle { | ||
pub name: Name, | ||
pub marker: Star, | ||
pub indicated: Indicated, | ||
pub orbitable: Orbitable, | ||
pub animation_bundle: AnimationBundle, | ||
pub sprite_sheet_bundle: SpriteSheetBundle, | ||
} | ||
impl Default for StarBundle { | ||
fn default() -> Self { | ||
Self { | ||
name: Name::new("Star"), | ||
marker: Star, | ||
indicated: Indicated { | ||
color: Color::ANTIQUE_WHITE, | ||
}, | ||
orbitable: Orbitable::ZERO, | ||
animation_bundle: AnimationBundle { | ||
indices: STAR_ANIMATION_INDICES, | ||
timer: AnimationTimer(Timer::from_seconds(0.1, TimerMode::Repeating)), | ||
}, | ||
sprite_sheet_bundle: SpriteSheetBundle::default(), | ||
} | ||
} | ||
} | ||
impl StarBundle { | ||
pub fn from_sprites(sprites: Res<SpriteAssets>) -> Self { | ||
Self { | ||
sprite_sheet_bundle: SpriteSheetBundle { | ||
texture_atlas: sprites.star.clone(), | ||
sprite: TextureAtlasSprite::new(0), | ||
transform: Transform::from_scale(Vec3::splat(2.0)), | ||
..default() | ||
}, | ||
..default() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use bevy::prelude::*; | ||
|
||
use crate::resources::state::GameState; | ||
|
||
pub struct AnimatePlugin; | ||
impl Plugin for AnimatePlugin { | ||
fn build(&self, app: &mut App) { | ||
app.add_systems(Update, animate_sprite.run_if(in_state(GameState::Active))); | ||
} | ||
} | ||
|
||
#[derive(Component, Clone, Copy)] | ||
pub struct AnimationIndices { | ||
pub first: usize, | ||
pub last: usize, | ||
} | ||
|
||
#[derive(Component, Deref, DerefMut)] | ||
pub struct AnimationTimer(pub Timer); | ||
|
||
#[derive(Bundle)] | ||
pub struct AnimationBundle { | ||
pub indices: AnimationIndices, | ||
pub timer: AnimationTimer, | ||
} | ||
|
||
fn animate_sprite( | ||
time: Res<Time>, | ||
mut query: Query<( | ||
&AnimationIndices, | ||
&mut AnimationTimer, | ||
&mut TextureAtlasSprite, | ||
)>, | ||
) { | ||
for (indices, mut timer, mut sprite) in &mut query { | ||
timer.tick(time.delta()); | ||
if timer.just_finished() { | ||
sprite.index = if sprite.index == indices.last { | ||
indices.first | ||
} else { | ||
sprite.index + 1 | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod animate; | ||
pub mod blink; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters