Skip to content
Snippets Groups Projects
Verified Commit ba10525e authored by Louis's avatar Louis :fire:
Browse files

Spawn static alien creature

parent 98132d8f
No related branches found
No related tags found
No related merge requests found
use crate::entities::EntitySpawner;
use crate::system::window_bounds;
use bevy::math::Vec2;
pub fn spawn_static_aliens(mut spawner: EntitySpawner) {
let bounds = window_bounds();
spawner.spawn_alien_at(Vec2::new(bounds.max.x - 150.0, bounds.half_size().y));
}
mod aliens;
mod collision; mod collision;
mod motion; mod motion;
mod player; mod player;
...@@ -10,11 +11,14 @@ mod _plugin { ...@@ -10,11 +11,14 @@ mod _plugin {
pub struct EntityPlugin; pub struct EntityPlugin;
impl Plugin for EntityPlugin { impl Plugin for EntityPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.add_startup_system(super::player::spawn_player) app.add_startup_systems((
.add_systems(( super::player::spawn_player,
super::player::process_player_input, super::aliens::spawn_static_aliens,
super::motion::apply_velocity, ))
)); .add_systems((
super::player::process_player_input,
super::motion::apply_velocity,
));
} }
} }
} }
......
use crate::entities::motion::Velocity; use crate::entities::motion::Velocity;
use crate::entities::{BoxSize, Player}; use crate::entities::{BoxSize, CollisionGroup, Player};
use crate::system::{Background, BACKGROUND_HEIGHT, BACKGROUND_WIDTH}; use crate::system::{Background, BACKGROUND_HEIGHT, BACKGROUND_WIDTH};
use bevy::ecs::system::SystemParam; use bevy::ecs::system::SystemParam;
use bevy::prelude::{AssetServer, Commands, Entity, Res, SpriteBundle, Transform, Vec2}; use bevy::prelude::{AssetServer, Commands, Entity, Res, Sprite, SpriteBundle, Transform, Vec2};
static Z_PLAYER: f32 = 300.0; static Z_PLAYER: f32 = 300.0;
static Z_ITEMS: f32 = 200.0; static Z_ITEMS: f32 = 200.0;
...@@ -44,4 +44,22 @@ impl<'w, 's> EntitySpawner<'w, 's> { ...@@ -44,4 +44,22 @@ impl<'w, 's> EntitySpawner<'w, 's> {
)) ))
.id() .id()
} }
pub fn spawn_alien_at(&mut self, position: Vec2) -> Entity {
self.commands
.spawn((
SpriteBundle {
texture: self.assets.load("sprites/alien_ship.png"),
transform: Transform::from_translation(position.extend(Z_ENEMY)),
sprite: Sprite {
flip_x: true,
..Default::default()
},
..Default::default()
},
BoxSize::from(Vec2::new(50.0, 25.0)),
CollisionGroup::Enemy,
))
.id()
}
} }
use bevy::prelude::Color;
pub struct DawnBringerPalette;
impl DawnBringerPalette {
/// <div style="background-color:rgb(20, 12, 28); width: 10px; padding: 10px; border: 1px solid;"></div>
pub const MURKY_BLACK: Color = Color::rgb(0.078, 0.047, 0.110);
/// <div style="background-color:rgb(68, 36, 52); width: 10px; padding: 10px; border: 1px solid;"></div>
pub const DARK_PURPLE: Color = Color::rgb(0.267, 0.141, 0.204);
/// <div style="background-color:rgb(48, 52, 109); width: 10px; padding: 10px; border: 1px solid;"></div>
pub const MIDNIGHT_BLUE: Color = Color::rgb(0.188, 0.204, 0.427);
/// <div style="background-color:rgb(78, 74, 78); width: 10px; padding: 10px; border: 1px solid;"></div>
pub const DARK_GREY: Color = Color::rgb(0.306, 0.290, 0.306);
/// <div style="background-color: rgb(133, 76, 48); width: 10px; padding: 10px; border :1px solid;"></div>
pub const BROWN: Color = Color::rgb(0.522, 0.298, 0.188);
/// <div style="background-color: rgb(52, 101, 36); width: 10px; padding: 10px; border :1px solid;"></div>
pub const FOREST_GREEN: Color = Color::rgb(0.204, 0.396, 0.141);
/// <div style="background-color: rgb(208, 70, 72); width: 10px; padding: 10px; border :1px solid;"></div>
pub const RED: Color = Color::rgb(0.816, 0.275, 0.282);
/// <div style="background-color: rgb(117, 113, 97); width: 10px; padding: 10px; border :1px solid;"></div>
pub const OLIVE_GREY: Color = Color::rgb(0.459, 0.443, 0.380);
/// <div style="background-color: rgb(89, 125, 206); width: 10px; padding: 10px; border :1px solid;"></div>
pub const MID_BLUE: Color = Color::rgb(0.349, 0.490, 0.808);
/// <div style="background-color: rgb(210, 125, 44); width: 10px; padding: 10px; border :1px solid;"></div>
pub const ORANGE: Color = Color::rgb(0.824, 0.490, 0.173);
/// <div style="background-color: rgb(133, 149, 161); width: 10px; padding: 10px; border :1px solid;"></div>
pub const STEEL_GREY: Color = Color::rgb(0.522, 0.584, 0.631);
/// <div style="background-color: rgb(109, 170, 44); width: 10px; padding: 10px; border :1px solid;"></div>
pub const GRASS_GREEN: Color = Color::rgb(0.427, 0.667, 0.173);
/// <div style="background-color: rgb(210, 170, 153); width: 10px; padding: 10px; border :1px solid;"></div>
pub const CHICKEN_SKIN: Color = Color::rgb(0.824, 0.667, 0.600);
/// <div style="background-color: rgb(109, 194, 202); width: 10px; padding: 10px; border :1px solid;"></div>
pub const ICE_BLUE: Color = Color::rgb(0.427, 0.761, 0.792);
/// <div style="background-color: rgb(218, 212, 94); width: 10px; padding: 10px; border :1px solid;"></div>
pub const YELLOW: Color = Color::rgb(0.855, 0.831, 0.369);
/// <div style="background-color: rgb(222, 238, 214); width: 10px; padding: 10px; border :1px solid;"></div>
pub const OFF_WHITE: Color = Color::rgb(0.871, 0.933, 0.839);
}
mod camera; mod camera;
mod colours;
mod parallax; mod parallax;
mod window; mod window;
...@@ -22,6 +23,7 @@ mod _plugin { ...@@ -22,6 +23,7 @@ mod _plugin {
} }
pub use camera::default_projection; pub use camera::default_projection;
pub use colours::DawnBringerPalette;
pub use parallax::{Background, BACKGROUND_HEIGHT, BACKGROUND_WIDTH}; pub use parallax::{Background, BACKGROUND_HEIGHT, BACKGROUND_WIDTH};
pub use window::{window_bounds, VIEWPORT_HEIGHT, VIEWPORT_WIDTH}; pub use window::{window_bounds, VIEWPORT_HEIGHT, VIEWPORT_WIDTH};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment