Menu text & raw character colors
This commit is contained in:
parent
a52a3b84c8
commit
55278858cb
2 changed files with 49 additions and 36 deletions
65
src/game.rs
65
src/game.rs
|
@ -17,7 +17,6 @@ pub struct GamePlugin;
|
||||||
impl Plugin for GamePlugin {
|
impl Plugin for GamePlugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
app.add_event::<LevelStartupEvent>()
|
app.add_event::<LevelStartupEvent>()
|
||||||
.init_resource::<CharacterMaterials>()
|
|
||||||
.init_resource::<CharacterMeshes>()
|
.init_resource::<CharacterMeshes>()
|
||||||
.insert_resource(CurrentLevel(None))
|
.insert_resource(CurrentLevel(None))
|
||||||
.add_system_set(SystemSet::on_enter(AppState::Game).with_system(setup))
|
.add_system_set(SystemSet::on_enter(AppState::Game).with_system(setup))
|
||||||
|
@ -38,29 +37,6 @@ struct LevelStartupEvent(Entity);
|
||||||
|
|
||||||
struct CurrentLevel(Option<Entity>);
|
struct CurrentLevel(Option<Entity>);
|
||||||
|
|
||||||
struct CharacterMaterials {
|
|
||||||
red: Handle<ColorMaterial>,
|
|
||||||
green: Handle<ColorMaterial>,
|
|
||||||
blue: Handle<ColorMaterial>,
|
|
||||||
yellow: Handle<ColorMaterial>,
|
|
||||||
magenta: Handle<ColorMaterial>,
|
|
||||||
cyan: Handle<ColorMaterial>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FromWorld for CharacterMaterials {
|
|
||||||
fn from_world(world: &mut World) -> Self {
|
|
||||||
let mut materials = world.get_resource_mut::<Assets<ColorMaterial>>().unwrap();
|
|
||||||
Self {
|
|
||||||
red: materials.add(ColorMaterial::from(Color::rgba(1.0, 0., 0., 1.))),
|
|
||||||
green: materials.add(ColorMaterial::from(Color::rgba(0., 1.0, 0., 1.))),
|
|
||||||
blue: materials.add(ColorMaterial::from(Color::rgba(0., 0., 1.0, 1.))),
|
|
||||||
yellow: materials.add(ColorMaterial::from(Color::rgba(1.0, 1.0, 0., 1.))),
|
|
||||||
magenta: materials.add(ColorMaterial::from(Color::rgba(1.0, 0., 1.0, 1.))),
|
|
||||||
cyan: materials.add(ColorMaterial::from(Color::rgba(0., 1.0, 1.0, 1.))),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct CharacterMeshes {
|
struct CharacterMeshes {
|
||||||
square: Mesh2dHandle,
|
square: Mesh2dHandle,
|
||||||
}
|
}
|
||||||
|
@ -118,9 +94,9 @@ fn setup(
|
||||||
// This is a bad design, but it's the only way I found
|
// This is a bad design, but it's the only way I found
|
||||||
fn post_setup_level(
|
fn post_setup_level(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
character_materials: Res<CharacterMaterials>,
|
|
||||||
character_meshes: Res<CharacterMeshes>,
|
character_meshes: Res<CharacterMeshes>,
|
||||||
mut effects: ResMut<Assets<EffectAsset>>,
|
mut effects: ResMut<Assets<EffectAsset>>,
|
||||||
|
mut materials: ResMut<Assets<ColorMaterial>>,
|
||||||
mut level_query: Query<(&mut SelectedCharacterId, &mut CharacterIdList)>,
|
mut level_query: Query<(&mut SelectedCharacterId, &mut CharacterIdList)>,
|
||||||
mut level_startup_event: EventReader<LevelStartupEvent>,
|
mut level_startup_event: EventReader<LevelStartupEvent>,
|
||||||
) {
|
) {
|
||||||
|
@ -132,28 +108,31 @@ fn post_setup_level(
|
||||||
&mut commands,
|
&mut commands,
|
||||||
&character_meshes,
|
&character_meshes,
|
||||||
&mut effects,
|
&mut effects,
|
||||||
|
&mut materials,
|
||||||
&mut selected_character_id,
|
&mut selected_character_id,
|
||||||
&mut character_id_list,
|
&mut character_id_list,
|
||||||
character_materials.red.clone(),
|
|
||||||
Transform::from_xyz(-128., -64., 0.),
|
Transform::from_xyz(-128., -64., 0.),
|
||||||
|
Color::RED,
|
||||||
);
|
);
|
||||||
spawn_character(
|
spawn_character(
|
||||||
&mut commands,
|
&mut commands,
|
||||||
&character_meshes,
|
&character_meshes,
|
||||||
&mut effects,
|
&mut effects,
|
||||||
|
&mut materials,
|
||||||
&mut selected_character_id,
|
&mut selected_character_id,
|
||||||
&mut character_id_list,
|
&mut character_id_list,
|
||||||
character_materials.green.clone(),
|
|
||||||
Transform::from_xyz(0., -64., 0.),
|
Transform::from_xyz(0., -64., 0.),
|
||||||
|
Color::GREEN,
|
||||||
);
|
);
|
||||||
spawn_character(
|
spawn_character(
|
||||||
&mut commands,
|
&mut commands,
|
||||||
&character_meshes,
|
&character_meshes,
|
||||||
&mut effects,
|
&mut effects,
|
||||||
|
&mut materials,
|
||||||
&mut selected_character_id,
|
&mut selected_character_id,
|
||||||
&mut character_id_list,
|
&mut character_id_list,
|
||||||
character_materials.blue.clone(),
|
|
||||||
Transform::from_xyz(128., -64., 0.),
|
Transform::from_xyz(128., -64., 0.),
|
||||||
|
Color::BLUE,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -163,10 +142,11 @@ fn spawn_character(
|
||||||
commands: &mut Commands,
|
commands: &mut Commands,
|
||||||
character_meshes: &Res<CharacterMeshes>,
|
character_meshes: &Res<CharacterMeshes>,
|
||||||
effects: &mut ResMut<Assets<EffectAsset>>,
|
effects: &mut ResMut<Assets<EffectAsset>>,
|
||||||
|
materials: &mut ResMut<Assets<ColorMaterial>>,
|
||||||
selected_character_id: &mut Mut<SelectedCharacterId>,
|
selected_character_id: &mut Mut<SelectedCharacterId>,
|
||||||
character_id_list: &mut Mut<CharacterIdList>,
|
character_id_list: &mut Mut<CharacterIdList>,
|
||||||
material: Handle<ColorMaterial>,
|
|
||||||
transform: Transform,
|
transform: Transform,
|
||||||
|
color: Color,
|
||||||
) {
|
) {
|
||||||
let character_id = CharacterId(
|
let character_id = CharacterId(
|
||||||
character_id_list
|
character_id_list
|
||||||
|
@ -178,13 +158,25 @@ fn spawn_character(
|
||||||
character_id_list.0.insert(character_id);
|
character_id_list.0.insert(character_id);
|
||||||
|
|
||||||
let mut gradient = Gradient::new();
|
let mut gradient = Gradient::new();
|
||||||
gradient.add_key(0.0, Vec4::new(1.0, 0.1, 0.1, 0.0));
|
gradient.add_key(
|
||||||
gradient.add_key(0.2, Vec4::new(1.0, 0.1, 0.1, 1.0));
|
0.0,
|
||||||
gradient.add_key(1.0, Vec4::new(1.0, 0.1, 0.1, 0.0));
|
(Vec4::from(color) + Vec4::new(0.1, 0.1, 0.1, 0.0))
|
||||||
|
.clamp(Vec4::new(0., 0., 0., 0.), Vec4::new(1., 1., 1., 0.)),
|
||||||
|
);
|
||||||
|
gradient.add_key(
|
||||||
|
0.2,
|
||||||
|
(Vec4::from(color) + Vec4::new(0.1, 0.1, 0.1, 0.0))
|
||||||
|
.clamp(Vec4::new(0., 0., 0., 0.), Vec4::new(1., 1., 1., 1.)),
|
||||||
|
);
|
||||||
|
gradient.add_key(
|
||||||
|
1.0,
|
||||||
|
(Vec4::from(color) + Vec4::new(0.1, 0.1, 0.1, 0.0))
|
||||||
|
.clamp(Vec4::new(0., 0., 0., 0.), Vec4::new(1., 1., 1., 0.)),
|
||||||
|
);
|
||||||
commands
|
commands
|
||||||
.spawn_bundle(MaterialMesh2dBundle {
|
.spawn_bundle(MaterialMesh2dBundle {
|
||||||
mesh: character_meshes.square.clone(),
|
mesh: character_meshes.square.clone(),
|
||||||
material,
|
material: materials.add(ColorMaterial::from(color)),
|
||||||
transform,
|
transform,
|
||||||
..default()
|
..default()
|
||||||
})
|
})
|
||||||
|
@ -204,7 +196,7 @@ fn spawn_character(
|
||||||
effect: ParticleEffect::new(
|
effect: ParticleEffect::new(
|
||||||
effects.add(
|
effects.add(
|
||||||
EffectAsset {
|
EffectAsset {
|
||||||
name: "Red particles".into(),
|
name: "Particles".into(),
|
||||||
capacity: 4096,
|
capacity: 4096,
|
||||||
spawner: Spawner::rate(30.0.into())
|
spawner: Spawner::rate(30.0.into())
|
||||||
.with_active(selected_character_id.0.is_none()),
|
.with_active(selected_character_id.0.is_none()),
|
||||||
|
@ -236,8 +228,10 @@ fn spawn_character(
|
||||||
|
|
||||||
fn collision_event_system(
|
fn collision_event_system(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
|
//materials: ResMut<Assets<ColorMaterial>>,
|
||||||
current_level: Res<CurrentLevel>,
|
current_level: Res<CurrentLevel>,
|
||||||
mut collision_events: EventReader<CollisionEvent>,
|
mut collision_events: EventReader<CollisionEvent>,
|
||||||
|
//character_query: Query<(&CharacterId, &Handle<ColorMaterial>)>,
|
||||||
character_query: Query<&CharacterId>,
|
character_query: Query<&CharacterId>,
|
||||||
mut level_query: Query<(&mut SelectedCharacterId, &mut CharacterIdList)>,
|
mut level_query: Query<(&mut SelectedCharacterId, &mut CharacterIdList)>,
|
||||||
) {
|
) {
|
||||||
|
@ -245,9 +239,12 @@ fn collision_event_system(
|
||||||
for collision_event in collision_events.iter() {
|
for collision_event in collision_events.iter() {
|
||||||
if let CollisionEvent::Started(e1, e2, flags) = collision_event {
|
if let CollisionEvent::Started(e1, e2, flags) = collision_event {
|
||||||
if flags.is_empty() {
|
if flags.is_empty() {
|
||||||
|
//if let (Ok((c1_id, c1_material)), Ok((c2_id, c2_material))) =
|
||||||
if let (Ok(c1_id), Ok(c2_id)) =
|
if let (Ok(c1_id), Ok(c2_id)) =
|
||||||
(character_query.get(*e1), character_query.get(*e2))
|
(character_query.get(*e1), character_query.get(*e2))
|
||||||
{
|
{
|
||||||
|
//c1_material.color = (Vec4::from(c1_material.color) + Vec4::from(c2_material.color)).into();
|
||||||
|
|
||||||
let (mut selected_character_id, mut character_id_list) =
|
let (mut selected_character_id, mut character_id_list) =
|
||||||
level_query.get_mut(level_entity).unwrap();
|
level_query.get_mut(level_entity).unwrap();
|
||||||
character_id_list.0.remove(c2_id);
|
character_id_list.0.remove(c2_id);
|
||||||
|
|
20
src/menu.rs
20
src/menu.rs
|
@ -19,13 +19,29 @@ impl Plugin for MenuPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||||
|
let font = asset_server.get_handle("Cantarell-VF.otf");
|
||||||
|
commands
|
||||||
|
.spawn_bundle(Text2dBundle {
|
||||||
|
text: Text::from_section(
|
||||||
|
"BEVYJAM",
|
||||||
|
TextStyle {
|
||||||
|
font: font.clone(),
|
||||||
|
font_size: 48.0,
|
||||||
|
color: Color::WHITE,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.with_alignment(TextAlignment::CENTER),
|
||||||
|
transform: Transform::from_xyz(0., -128.0, 0.),
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
|
.insert(Menu());
|
||||||
commands
|
commands
|
||||||
.spawn_bundle(Text2dBundle {
|
.spawn_bundle(Text2dBundle {
|
||||||
text: Text::from_section(
|
text: Text::from_section(
|
||||||
"Press ENTER",
|
"Press ENTER",
|
||||||
TextStyle {
|
TextStyle {
|
||||||
font: asset_server.get_handle("Cantarell-VF.otf"),
|
font,
|
||||||
font_size: 64.0,
|
font_size: 32.0,
|
||||||
color: Color::WHITE,
|
color: Color::WHITE,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue