From ba10525e82a5b3c237c195c4de8fa21a506d554e Mon Sep 17 00:00:00 2001
From: Louis Capitanchik <contact@louiscap.co>
Date: Mon, 3 Jul 2023 23:53:46 +0100
Subject: [PATCH] Spawn static alien creature

---
 src/entities/aliens.rs   |  8 ++++++++
 src/entities/mod.rs      | 14 +++++++++-----
 src/entities/spawning.rs | 22 ++++++++++++++++++++--
 src/system/colours.rs    | 37 +++++++++++++++++++++++++++++++++++++
 src/system/mod.rs        |  2 ++
 5 files changed, 76 insertions(+), 7 deletions(-)
 create mode 100644 src/entities/aliens.rs
 create mode 100644 src/system/colours.rs

diff --git a/src/entities/aliens.rs b/src/entities/aliens.rs
new file mode 100644
index 0000000..bfa6478
--- /dev/null
+++ b/src/entities/aliens.rs
@@ -0,0 +1,8 @@
+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));
+}
diff --git a/src/entities/mod.rs b/src/entities/mod.rs
index e6d1739..f604191 100644
--- a/src/entities/mod.rs
+++ b/src/entities/mod.rs
@@ -1,3 +1,4 @@
+mod aliens;
 mod collision;
 mod motion;
 mod player;
@@ -10,11 +11,14 @@ mod _plugin {
 	pub struct EntityPlugin;
 	impl Plugin for EntityPlugin {
 		fn build(&self, app: &mut App) {
-			app.add_startup_system(super::player::spawn_player)
-				.add_systems((
-					super::player::process_player_input,
-					super::motion::apply_velocity,
-				));
+			app.add_startup_systems((
+				super::player::spawn_player,
+				super::aliens::spawn_static_aliens,
+			))
+			.add_systems((
+				super::player::process_player_input,
+				super::motion::apply_velocity,
+			));
 		}
 	}
 }
diff --git a/src/entities/spawning.rs b/src/entities/spawning.rs
index 92174c6..7dc9980 100644
--- a/src/entities/spawning.rs
+++ b/src/entities/spawning.rs
@@ -1,8 +1,8 @@
 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 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_ITEMS: f32 = 200.0;
@@ -44,4 +44,22 @@ impl<'w, 's> EntitySpawner<'w, 's> {
 			))
 			.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()
+	}
 }
diff --git a/src/system/colours.rs b/src/system/colours.rs
new file mode 100644
index 0000000..36551b7
--- /dev/null
+++ b/src/system/colours.rs
@@ -0,0 +1,37 @@
+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);
+}
diff --git a/src/system/mod.rs b/src/system/mod.rs
index d70e631..77616b8 100644
--- a/src/system/mod.rs
+++ b/src/system/mod.rs
@@ -1,4 +1,5 @@
 mod camera;
+mod colours;
 mod parallax;
 mod window;
 
@@ -22,6 +23,7 @@ mod _plugin {
 }
 
 pub use camera::default_projection;
+pub use colours::DawnBringerPalette;
 pub use parallax::{Background, BACKGROUND_HEIGHT, BACKGROUND_WIDTH};
 pub use window::{window_bounds, VIEWPORT_HEIGHT, VIEWPORT_WIDTH};
 
-- 
GitLab